mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-27 17:38:17 -04:00
Fix tests which call str() on exception messages
Since Pytest 5, `ExceptionInfo` objects (returned by `pytest.raises`) now have the same `str` representation as `repr`. This means that `str(e)` now needs to be changed to `str(e.value)`. https://github.com/pytest-dev/pytest/issues/5412
This commit is contained in:
@@ -46,7 +46,7 @@ def test_update_letter_notifications_statuses_raises_for_invalid_format(notify_a
|
||||
|
||||
with pytest.raises(DVLAException) as e:
|
||||
update_letter_notifications_statuses(filename='NOTIFY-20170823160812-RSP.TXT')
|
||||
assert 'DVLA response file: {} has an invalid format'.format('NOTIFY-20170823160812-RSP.TXT') in str(e)
|
||||
assert 'DVLA response file: {} has an invalid format'.format('NOTIFY-20170823160812-RSP.TXT') in str(e.value)
|
||||
|
||||
|
||||
def test_update_letter_notification_statuses_when_notification_does_not_exist_updates_notification_history(
|
||||
@@ -75,7 +75,7 @@ def test_update_letter_notifications_statuses_raises_dvla_exception(notify_api,
|
||||
failed = ["ref-foo"]
|
||||
assert "DVLA response file: {filename} has failed letters with notification.reference {failures}".format(
|
||||
filename="failed.txt", failures=failed
|
||||
) in str(e)
|
||||
) in str(e.value)
|
||||
|
||||
|
||||
def test_update_letter_notifications_statuses_calls_with_correct_bucket_location(notify_api, mocker):
|
||||
@@ -136,7 +136,7 @@ def test_update_letter_notifications_statuses_persisted(notify_api, mocker, samp
|
||||
assert failed_letter.billable_units == 2
|
||||
assert failed_letter.updated_at
|
||||
assert "DVLA response file: {filename} has failed letters with notification.reference {failures}".format(
|
||||
filename="NOTIFY-20170823160812-RSP.TXT", failures=[format(failed_letter.reference)]) in str(e)
|
||||
filename="NOTIFY-20170823160812-RSP.TXT", failures=[format(failed_letter.reference)]) in str(e.value)
|
||||
|
||||
|
||||
def test_update_letter_notifications_does_not_call_send_callback_if_no_db_entry(notify_api, mocker,
|
||||
|
||||
@@ -686,7 +686,7 @@ def test_process_letter_task_check_virus_scan_failed(sample_letter_notification,
|
||||
with pytest.raises(VirusScanError) as e:
|
||||
process_virus_scan_failed(filename)
|
||||
|
||||
assert "Virus scan failed:" in str(e)
|
||||
assert "Virus scan failed:" in str(e.value)
|
||||
mock_move_failed_pdf.assert_called_once_with(filename, ScanErrorType.FAILURE)
|
||||
assert sample_letter_notification.status == NOTIFICATION_VIRUS_SCAN_FAILED
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ def test_send_sms_raises_if_mmg_fails_to_return_json(notify_api, mocker):
|
||||
request_mock.post('https://example.com/mmg', text=response_dict, status_code=200)
|
||||
mmg_client.send_sms(to, content, reference)
|
||||
|
||||
assert 'app.clients.sms.mmg.MMGClientResponseException: Code 200 text NOT AT ALL VALID JSON {"key" : "value"}} exception Expecting value: line 1 column 1 (char 0)' in str(exc) # noqa
|
||||
assert 'Code 200 text NOT AT ALL VALID JSON {"key" : "value"}} exception Expecting value: line 1 column 1 (char 0)' in str(exc.value) # noqa
|
||||
assert exc.value.status_code == 200
|
||||
assert exc.value.text == 'NOT AT ALL VALID JSON {"key" : "value"}}'
|
||||
|
||||
|
||||
@@ -503,7 +503,7 @@ def test_dao_fetch_live_services_data(sample_user):
|
||||
def test_get_service_by_id_returns_none_if_no_service(notify_db):
|
||||
with pytest.raises(NoResultFound) as e:
|
||||
dao_fetch_service_by_id(str(uuid.uuid4()))
|
||||
assert 'No row was found for one()' in str(e)
|
||||
assert 'No row was found for one()' in str(e.value)
|
||||
|
||||
|
||||
def test_get_service_by_id_returns_service(notify_db_session):
|
||||
|
||||
Reference in New Issue
Block a user