2019-11-04 11:07:55 +00:00
|
|
|
|
import uuid
|
|
|
|
|
|
|
2019-05-22 14:05:19 +01:00
|
|
|
|
import pytest
|
2018-07-06 11:10:14 +01:00
|
|
|
|
from flask import url_for
|
2020-04-21 17:40:47 +01:00
|
|
|
|
from notifications_python_client.errors import HTTPError
|
2018-07-06 11:10:14 +01:00
|
|
|
|
|
2018-07-06 16:16:21 +01:00
|
|
|
|
from tests import user_json
|
2019-06-05 11:25:27 +01:00
|
|
|
|
from tests.conftest import normalize_spaces
|
2018-07-06 11:10:14 +01:00
|
|
|
|
|
2018-07-10 17:24:20 +01:00
|
|
|
|
|
2018-07-16 15:04:03 +01:00
|
|
|
|
def test_find_users_by_email_page_loads_correctly(client_request, platform_admin_user):
|
|
|
|
|
|
client_request.login(platform_admin_user)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
document = client_request.get("main.find_users_by_email")
|
2018-07-06 11:10:14 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert document.h1.text.strip() == "Find users by email"
|
|
|
|
|
|
assert len(document.find_all("input", {"type": "search"})) > 0
|
2018-07-06 16:16:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_users_by_email_displays_users_found(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
client_request, platform_admin_user, mocker
|
2018-07-06 16:16:21 +01:00
|
|
|
|
):
|
2018-07-16 15:04:03 +01:00
|
|
|
|
client_request.login(platform_admin_user)
|
2018-07-10 17:24:20 +01:00
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.user_api_client.find_users_by_full_or_partial_email",
|
2018-07-10 17:24:20 +01:00
|
|
|
|
return_value={"data": [user_json()]},
|
|
|
|
|
|
)
|
2018-07-16 15:04:03 +01:00
|
|
|
|
document = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.find_users_by_email",
|
2018-07-16 15:04:03 +01:00
|
|
|
|
_data={"search": "twilight.sparkle"},
|
2023-08-25 09:12:23 -07:00
|
|
|
|
_expected_status=200,
|
2018-07-16 15:04:03 +01:00
|
|
|
|
)
|
2018-07-06 16:16:21 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert any(
|
|
|
|
|
|
element.text.strip() == "test@gsa.gov"
|
|
|
|
|
|
for element in document.find_all("a", {"class": "browse-list-link"}, href=True)
|
|
|
|
|
|
)
|
|
|
|
|
|
assert any(
|
|
|
|
|
|
element.text.strip() == "Test User"
|
|
|
|
|
|
for element in document.find_all("span", {"class": "browse-list-hint"})
|
2018-07-16 15:04:03 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
document.find("a", {"class": "browse-list-link"}).text.strip() == "test@gsa.gov"
|
|
|
|
|
|
)
|
|
|
|
|
|
assert (
|
|
|
|
|
|
document.find("span", {"class": "browse-list-hint"}).text.strip() == "Test User"
|
|
|
|
|
|
)
|
2018-07-10 17:24:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_users_by_email_displays_multiple_users(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
client_request, platform_admin_user, mocker
|
2018-07-10 17:24:20 +01:00
|
|
|
|
):
|
2018-07-16 15:04:03 +01:00
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.user_api_client.find_users_by_full_or_partial_email",
|
|
|
|
|
|
return_value={
|
|
|
|
|
|
"data": [user_json(name="Apple Jack"), user_json(name="Apple Bloom")]
|
|
|
|
|
|
},
|
2018-07-16 15:04:03 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
document = client_request.post(
|
|
|
|
|
|
"main.find_users_by_email", _data={"search": "apple"}, _expected_status=200
|
|
|
|
|
|
)
|
2018-07-10 17:24:20 +01:00
|
|
|
|
|
2018-07-16 15:04:03 +01:00
|
|
|
|
assert any(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
element.text.strip() == "Apple Jack"
|
|
|
|
|
|
for element in document.find_all("span", {"class": "browse-list-hint"})
|
2018-07-16 15:04:03 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert any(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
element.text.strip() == "Apple Bloom"
|
|
|
|
|
|
for element in document.find_all("span", {"class": "browse-list-hint"})
|
2018-07-16 15:04:03 +01:00
|
|
|
|
)
|
2018-07-10 17:24:20 +01:00
|
|
|
|
|
2018-07-06 16:16:21 +01:00
|
|
|
|
|
|
|
|
|
|
def test_find_users_by_email_displays_message_if_no_users_found(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
client_request, platform_admin_user, mocker
|
2018-07-06 16:16:21 +01:00
|
|
|
|
):
|
2018-07-16 15:04:03 +01:00
|
|
|
|
client_request.login(platform_admin_user)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.find_users_by_full_or_partial_email",
|
|
|
|
|
|
return_value={"data": []},
|
|
|
|
|
|
)
|
2018-07-16 15:04:03 +01:00
|
|
|
|
document = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.find_users_by_email",
|
|
|
|
|
|
_data={"search": "twilight.sparkle"},
|
|
|
|
|
|
_expected_status=200,
|
2018-07-16 15:04:03 +01:00
|
|
|
|
)
|
2018-07-06 16:16:21 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
document.find("p", {"class": "browse-list-hint"}).text.strip()
|
|
|
|
|
|
== "No users found."
|
|
|
|
|
|
)
|
2018-07-10 16:33:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_users_by_email_validates_against_empty_search_submission(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
client_request, platform_admin_user, mocker
|
2018-07-10 16:33:13 +01:00
|
|
|
|
):
|
2018-07-16 15:04:03 +01:00
|
|
|
|
client_request.login(platform_admin_user)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
document = client_request.post(
|
|
|
|
|
|
"main.find_users_by_email", _data={"search": ""}, _expected_status=200
|
|
|
|
|
|
)
|
2018-07-10 16:33:13 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
expected_message = (
|
|
|
|
|
|
"Error: You need to enter full or partial email address to search by."
|
|
|
|
|
|
)
|
|
|
|
|
|
assert (
|
|
|
|
|
|
document.find("span", {"class": "usa-error-message"}).text.strip()
|
|
|
|
|
|
== expected_message
|
|
|
|
|
|
)
|
2018-07-10 17:24:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_user_information_page_shows_information_about_user(
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request,
|
2018-07-10 17:24:20 +01:00
|
|
|
|
platform_admin_user,
|
2019-11-04 11:07:55 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
2018-07-10 17:24:20 +01:00
|
|
|
|
):
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
2019-11-04 11:07:55 +00:00
|
|
|
|
user_service_one = uuid.uuid4()
|
|
|
|
|
|
user_service_two = uuid.uuid4()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_user",
|
|
|
|
|
|
side_effect=[
|
|
|
|
|
|
user_json(name="Apple Bloom", services=[user_service_one, user_service_two])
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2018-07-16 16:34:10 +01:00
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.user_api_client.get_organizations_and_services_for_user",
|
|
|
|
|
|
return_value={
|
|
|
|
|
|
"organizations": [],
|
|
|
|
|
|
"services": [
|
|
|
|
|
|
{
|
|
|
|
|
|
"id": user_service_one,
|
|
|
|
|
|
"name": "Fresh Orchard Juice",
|
|
|
|
|
|
"restricted": True,
|
|
|
|
|
|
},
|
|
|
|
|
|
{"id": user_service_two, "name": "Nature Therapy", "restricted": False},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
)
|
|
|
|
|
|
page = client_request.get("main.user_information", user_id=fake_uuid)
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one("h1").text) == "Apple Bloom"
|
|
|
|
|
|
|
|
|
|
|
|
assert [normalize_spaces(p.text) for p in page.select("main p")] == [
|
|
|
|
|
|
"test@gsa.gov",
|
|
|
|
|
|
"+12028675109",
|
|
|
|
|
|
"Text message code",
|
|
|
|
|
|
"Last logged in just now",
|
2022-01-04 10:56:25 +00:00
|
|
|
|
]
|
2018-07-10 17:24:20 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert "0 failed login attempts" not in page.text
|
2018-07-10 17:24:20 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert [normalize_spaces(h2.text) for h2 in page.select("main h2")] == [
|
|
|
|
|
|
"Live services",
|
|
|
|
|
|
"Trial mode services",
|
|
|
|
|
|
"Authentication",
|
|
|
|
|
|
"Last login",
|
2022-01-04 10:56:25 +00:00
|
|
|
|
]
|
2019-06-12 09:50:11 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert [normalize_spaces(a.text) for a in page.select("main li a")] == [
|
|
|
|
|
|
"Nature Therapy",
|
|
|
|
|
|
"Fresh Orchard Juice",
|
2022-01-04 10:56:25 +00:00
|
|
|
|
]
|
2018-07-10 17:24:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
2022-02-23 19:57:27 +00:00
|
|
|
|
def test_user_information_page_shows_change_auth_type_link(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
|
|
|
|
|
api_user_active,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
mock_get_organizations_and_services_for_user,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker,
|
2022-02-23 19:57:27 +00:00
|
|
|
|
):
|
|
|
|
|
|
client_request.login(platform_admin_user)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_user",
|
|
|
|
|
|
side_effect=[
|
|
|
|
|
|
user_json(
|
|
|
|
|
|
id_=api_user_active["id"], name="Apple Bloom", auth_type="sms_auth"
|
|
|
|
|
|
)
|
|
|
|
|
|
],
|
2022-02-23 19:57:27 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page = client_request.get("main.user_information", user_id=api_user_active["id"])
|
|
|
|
|
|
change_auth_url = url_for("main.change_user_auth", user_id=api_user_active["id"])
|
|
|
|
|
|
|
|
|
|
|
|
link = page.find("a", {"href": change_auth_url})
|
|
|
|
|
|
assert normalize_spaces(link.text) == "Change authentication for this user"
|
2022-02-23 19:57:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
@pytest.mark.parametrize("current_auth_type", ["email_auth", "sms_auth"])
|
2022-02-23 19:57:27 +00:00
|
|
|
|
def test_change_user_auth_preselects_current_auth_type(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
client_request, platform_admin_user, api_user_active, mocker, current_auth_type
|
2022-02-23 19:57:27 +00:00
|
|
|
|
):
|
|
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_user",
|
|
|
|
|
|
side_effect=[
|
|
|
|
|
|
user_json(
|
|
|
|
|
|
id_=api_user_active["id"],
|
|
|
|
|
|
name="Apple Bloom",
|
|
|
|
|
|
auth_type=current_auth_type,
|
|
|
|
|
|
)
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2022-02-23 19:57:27 +00:00
|
|
|
|
|
|
|
|
|
|
checked_radios = client_request.get(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.change_user_auth",
|
|
|
|
|
|
user_id=api_user_active["id"],
|
2023-08-28 12:12:21 -04:00
|
|
|
|
).select(".usa-radio input[checked]")
|
2022-02-23 19:57:27 +00:00
|
|
|
|
|
|
|
|
|
|
assert len(checked_radios) == 1
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert checked_radios[0]["value"] == current_auth_type
|
2022-02-23 19:57:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
def test_change_user_auth(client_request, platform_admin_user, api_user_active, mocker):
|
2022-02-23 19:57:27 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_user",
|
|
|
|
|
|
side_effect=[
|
|
|
|
|
|
user_json(
|
|
|
|
|
|
id_=api_user_active["id"], name="Apple Bloom", auth_type="sms_auth"
|
|
|
|
|
|
)
|
|
|
|
|
|
],
|
|
|
|
|
|
)
|
2022-02-23 19:57:27 +00:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_update = mocker.patch("app.user_api_client.update_user_attribute")
|
2022-02-23 19:57:27 +00:00
|
|
|
|
|
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.change_user_auth",
|
|
|
|
|
|
user_id=api_user_active["id"],
|
|
|
|
|
|
_data={"auth_type": "email_auth"},
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
"main.user_information", user_id=api_user_active["id"]
|
|
|
|
|
|
),
|
2022-02-23 19:57:27 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
mock_update.assert_called_once_with(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
api_user_active["id"],
|
|
|
|
|
|
auth_type="email_auth",
|
2022-02-23 19:57:27 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-10 17:24:20 +01:00
|
|
|
|
def test_user_information_page_displays_if_there_are_failed_login_attempts(
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request,
|
2018-07-10 17:24:20 +01:00
|
|
|
|
platform_admin_user,
|
2019-11-04 11:07:55 +00:00
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
2018-07-10 17:24:20 +01:00
|
|
|
|
):
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_user",
|
|
|
|
|
|
side_effect=[user_json(name="Apple Bloom", failed_login_count=2)],
|
|
|
|
|
|
)
|
2018-07-16 16:34:10 +01:00
|
|
|
|
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.user_api_client.get_organizations_and_services_for_user",
|
|
|
|
|
|
return_value={"organizations": [], "services": []},
|
2018-07-16 16:34:10 +01:00
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page = client_request.get("main.user_information", user_id=fake_uuid)
|
2018-07-10 17:24:20 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.select("main p")[-1].text) == (
|
|
|
|
|
|
"2 failed login attempts"
|
2022-01-04 10:56:25 +00:00
|
|
|
|
)
|
2019-05-22 11:38:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-06-05 11:25:27 +01:00
|
|
|
|
def test_user_information_page_shows_archive_link_for_active_users(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
2019-06-05 11:25:27 +01:00
|
|
|
|
api_user_active,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
mock_get_organizations_and_services_for_user,
|
2019-06-05 11:25:27 +01:00
|
|
|
|
):
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page = client_request.get("main.user_information", user_id=api_user_active["id"])
|
|
|
|
|
|
archive_url = url_for("main.archive_user", user_id=api_user_active["id"])
|
2019-06-05 11:25:27 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
link = page.find("a", {"href": archive_url})
|
|
|
|
|
|
assert normalize_spaces(link.text) == "Archive user"
|
2019-06-05 11:25:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_user_information_page_does_not_show_archive_link_for_inactive_users(
|
|
|
|
|
|
mocker,
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request,
|
2019-06-05 11:25:27 +01:00
|
|
|
|
platform_admin_user,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
mock_get_organizations_and_services_for_user,
|
2019-06-05 11:25:27 +01:00
|
|
|
|
):
|
2022-01-04 10:56:25 +00:00
|
|
|
|
inactive_user_id = uuid.uuid4()
|
2023-08-25 09:12:23 -07:00
|
|
|
|
inactive_user = user_json(id_=inactive_user_id, state="inactive")
|
2022-01-04 10:56:25 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
"app.user_api_client.get_user",
|
|
|
|
|
|
side_effect=[platform_admin_user, inactive_user],
|
2019-06-05 11:25:27 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page = client_request.get("main.user_information", user_id=inactive_user_id)
|
|
|
|
|
|
|
|
|
|
|
|
archive_url = url_for("main.archive_user", user_id=inactive_user_id)
|
|
|
|
|
|
assert not page.find("a", {"href": archive_url})
|
2019-06-05 11:25:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-05-22 11:38:47 +01:00
|
|
|
|
def test_archive_user_prompts_for_confirmation(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
2019-05-22 11:38:47 +01:00
|
|
|
|
api_user_active,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
mock_get_organizations_and_services_for_user,
|
2019-05-22 11:38:47 +01:00
|
|
|
|
):
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
2023-08-25 09:12:23 -07:00
|
|
|
|
page = client_request.get("main.archive_user", user_id=api_user_active["id"])
|
2019-05-22 11:38:47 +01:00
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert (
|
|
|
|
|
|
"Are you sure you want to archive this user?"
|
|
|
|
|
|
in page.find("div", class_="banner-dangerous").text
|
|
|
|
|
|
)
|
2019-05-22 11:38:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_archive_user_posts_to_user_client(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
2019-05-22 11:38:47 +01:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
mocker,
|
2019-05-22 14:05:19 +01:00
|
|
|
|
mock_events,
|
2019-05-22 11:38:47 +01:00
|
|
|
|
):
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_user_client = mocker.patch("app.user_api_client.post")
|
2019-05-22 11:38:47 +01:00
|
|
|
|
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.archive_user",
|
|
|
|
|
|
user_id=api_user_active["id"],
|
2021-12-30 16:13:49 +00:00
|
|
|
|
_expected_redirect=url_for(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.user_information",
|
|
|
|
|
|
user_id=api_user_active["id"],
|
2021-12-30 16:13:49 +00:00
|
|
|
|
),
|
2019-05-22 11:38:47 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
mock_user_client.assert_called_once_with(
|
|
|
|
|
|
"/user/{}/archive".format(api_user_active["id"]), data=None
|
|
|
|
|
|
)
|
2019-05-22 14:05:19 +01:00
|
|
|
|
|
|
|
|
|
|
assert mock_events.called
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-21 17:40:47 +01:00
|
|
|
|
def test_archive_user_shows_error_message_if_user_cannot_be_archived(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
2020-04-21 17:40:47 +01:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
mocker,
|
2023-07-12 12:09:44 -04:00
|
|
|
|
mock_get_non_empty_organizations_and_services_for_user,
|
2020-04-21 17:40:47 +01:00
|
|
|
|
):
|
|
|
|
|
|
mocker.patch(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"app.user_api_client.post",
|
2020-04-21 17:40:47 +01:00
|
|
|
|
side_effect=HTTPError(
|
|
|
|
|
|
response=mocker.Mock(
|
|
|
|
|
|
status_code=400,
|
2023-08-25 09:12:23 -07:00
|
|
|
|
json={
|
|
|
|
|
|
"result": "error",
|
|
|
|
|
|
"message": "User can’t be removed from a service - check all services have another "
|
|
|
|
|
|
"team member with manage_settings",
|
|
|
|
|
|
},
|
2020-04-21 17:40:47 +01:00
|
|
|
|
),
|
2023-08-25 09:12:23 -07:00
|
|
|
|
message="User can’t be removed from a service - check all services have another team member "
|
|
|
|
|
|
"with manage_settings",
|
|
|
|
|
|
),
|
2020-04-21 17:40:47 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
page = client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.archive_user",
|
|
|
|
|
|
user_id=api_user_active["id"],
|
2021-12-30 16:13:49 +00:00
|
|
|
|
_follow_redirects=True,
|
2020-04-21 17:40:47 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
|
assert normalize_spaces(page.find("h1").text) == "Platform admin user"
|
|
|
|
|
|
assert (
|
|
|
|
|
|
normalize_spaces(page.select_one(".banner-dangerous").text)
|
|
|
|
|
|
== "User can’t be removed from a service - check all services have another team member with manage_settings"
|
|
|
|
|
|
)
|
2020-04-21 17:40:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
2020-04-22 16:31:59 +01:00
|
|
|
|
def test_archive_user_does_not_create_event_if_user_client_raises_unexpected_exception(
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request,
|
|
|
|
|
|
platform_admin_user,
|
2019-05-22 14:05:19 +01:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_events,
|
|
|
|
|
|
):
|
2023-07-26 09:09:06 -07:00
|
|
|
|
# flake8 doesn't like this
|
|
|
|
|
|
# with pytest.raises(Exception):
|
|
|
|
|
|
try:
|
2021-12-30 16:13:49 +00:00
|
|
|
|
client_request.login(platform_admin_user)
|
|
|
|
|
|
client_request.post(
|
2023-08-25 09:12:23 -07:00
|
|
|
|
"main.archive_user",
|
|
|
|
|
|
user_id=api_user_active.id,
|
2019-05-22 14:05:19 +01:00
|
|
|
|
)
|
2023-07-26 09:09:06 -07:00
|
|
|
|
assert 1 == 0
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
assert 1 == 1
|
2020-04-22 16:31:59 +01:00
|
|
|
|
assert not mock_events.called
|