Add an event if a user is archived

This adds a new type of event, 'archive_user', which stores the id of
the archived user and the id of the user who is doing the archiving.
This commit is contained in:
Katie Smith
2019-05-22 14:05:19 +01:00
parent 73b4aa4d85
commit f57f8641ad
4 changed files with 50 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import pytest
from bs4 import BeautifulSoup
from flask import url_for
from lxml import html
@@ -166,6 +167,7 @@ def test_archive_user_posts_to_user_client(
logged_in_platform_admin_client,
api_user_active,
mocker,
mock_events,
):
mock_user_client = mocker.patch('app.user_api_client.post')
@@ -176,3 +178,24 @@ def test_archive_user_posts_to_user_client(
assert response.status_code == 302
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 mock_events.called
def test_archive_user_does_not_create_event_if_user_client_raises_exception(
logged_in_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 = logged_in_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