Fix assertion in test

When using `with pytest.raises...` any assertions inside the `with`
statement that occur below the line that raises the exception don't get
called. It's not possible to check the response status_code / location
in this test because an exception is raised before the response is
returned.
This commit is contained in:
Katie Smith
2020-04-22 16:31:59 +01:00
parent ffdcda02bf
commit 407c6d264c

View File

@@ -255,20 +255,15 @@ def test_archive_user_shows_error_message_if_user_cannot_be_archived(
) == 'User cant be removed from a service - check all services have another team member with manage_settings'
def test_archive_user_does_not_create_event_if_user_client_raises_exception(
def test_archive_user_does_not_create_event_if_user_client_raises_unexpected_exception(
platform_admin_client,
api_user_active,
mocker,
mock_events,
):
mock_user_client = mocker.patch('app.user_api_client.post', side_effect=Exception())
with pytest.raises(Exception):
response = platform_admin_client.post(
platform_admin_client.post(
url_for('main.archive_user', user_id=api_user_active.id)
)
assert response.status_code == 500
assert response.location == url_for('main.user_information', user_id=api_user_active['id'], _external=True)
mock_user_client.assert_called_once_with('/user/{}/archive'.format(api_user_active['id']), data=None)
assert not mock_events.called
assert not mock_events.called