tests: check convert to sql errors using str() (#36515)

This commit is contained in:
Frédéric Péters 2019-11-15 22:35:50 +01:00
parent a41d06892e
commit 87e3f925cb
1 changed files with 4 additions and 4 deletions

View File

@ -68,27 +68,27 @@ def test_command_exists():
def test_unknown_publisher_fails(pub):
with pytest.raises(CommandError) as excinfo:
call_command('convert_to_sql', '-d', 'unknown.net', '--database', 'foobar')
assert excinfo.value.message == 'unknown tenant'
assert str(excinfo.value) == 'unknown tenant'
def test_failing_connection(pub):
with pytest.raises(psycopg2.OperationalError) as excinfo:
call_command('convert_to_sql', '-d', 'example.net', '--database', 'foobar', '--port', '666')
assert 'could not connect' in excinfo.value.message
assert 'could not connect' in str(excinfo.value)
def test_database_does_not_exist(pub):
new_database = 'test_%s' % random.randint(1000, 9999)
with pytest.raises(psycopg2.OperationalError) as excinfo:
call_command('convert_to_sql', '-d', 'example.net', '--database', new_database)
assert 'exist' in excinfo.value.message # works for english + french postgresql
assert 'exist' in str(excinfo.value) # works for english + french postgresql
def test_already_migrated_fails():
pub = create_temporary_pub(sql_mode=True)
with pytest.raises(CommandError) as excinfo:
call_command('convert_to_sql', '-d', 'example.net', '--database', 'foobar')
assert excinfo.value.message == 'tenant already using postgresql'
assert str(excinfo.value) == 'tenant already using postgresql'
cleanup_connection()
force_connections_close()
clean_temporary_pub()