mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-28 19:59:18 -04:00
Merge remote-tracking branch 'origin/main' into 855-make-individual-message-send-reports-less-ephemeral
This commit is contained in:
@@ -2,10 +2,12 @@ from datetime import datetime
|
||||
from functools import partial
|
||||
|
||||
import pytest
|
||||
from flask import url_for
|
||||
from flask import Flask, url_for
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.formatters import (
|
||||
apply_html_class,
|
||||
convert_markdown_template,
|
||||
email_safe,
|
||||
format_datetime_relative,
|
||||
format_delta,
|
||||
@@ -166,3 +168,29 @@ def test_email_safe_return_dot_separated_email_domain(service_name, safe_email):
|
||||
def test_format_delta():
|
||||
naive_now_utc = datetime.utcnow().isoformat()
|
||||
assert format_delta(naive_now_utc) == "just now"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("fake_jinja_template")
|
||||
def test_jinja_format(fake_jinja_template):
|
||||
app = Flask("app")
|
||||
with app.app_context():
|
||||
assert (
|
||||
convert_markdown_template(fake_jinja_template, test=True) == "<p>True</p>"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("fake_markdown_file")
|
||||
def test_markdown_format(fake_markdown_file):
|
||||
app = Flask("app")
|
||||
with app.app_context():
|
||||
assert (
|
||||
convert_markdown_template(fake_markdown_file, test=True) == "<h1>Test</h1>"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("fake_soup_template")
|
||||
def test_soup_format(fake_soup_template):
|
||||
assert (
|
||||
apply_html_class([["h1", "testClass"]], fake_soup_template)
|
||||
== '<h1 class="testClass">Test</h1>'
|
||||
)
|
||||
|
||||
@@ -125,7 +125,6 @@ def test_service_navigation_for_org_user(
|
||||
(
|
||||
"Send messages",
|
||||
"Sent messages",
|
||||
"Team members",
|
||||
),
|
||||
403,
|
||||
),
|
||||
@@ -134,7 +133,6 @@ def test_service_navigation_for_org_user(
|
||||
(
|
||||
"Send messages",
|
||||
"Sent messages",
|
||||
"Team members",
|
||||
"Usage",
|
||||
),
|
||||
200,
|
||||
|
||||
@@ -363,7 +363,7 @@ def test_should_show_back_to_service_if_user_belongs_to_service(
|
||||
):
|
||||
mock_get_service.return_value = service_one
|
||||
expected_page_text = (
|
||||
"Test Service Switch service " "Send messages " "Dashboard " "Team members"
|
||||
"Test Service Switch service " "Send messages " "Dashboard " "Usage"
|
||||
) # TODO: set sidebar variables in common test module
|
||||
|
||||
page = client_request.get(
|
||||
|
||||
@@ -1179,6 +1179,20 @@ def _test_dashboard_menu(client_request, mocker, usr, service, permissions):
|
||||
return client_request.get("main.service_dashboard", service_id=service["id"])
|
||||
|
||||
|
||||
def _test_settings_menu(client_request, mocker, usr, service, permissions):
|
||||
usr["permissions"][str(service["id"])] = permissions
|
||||
usr["services"] = [service["id"]]
|
||||
mocker.patch("app.user_api_client.check_verify_code", return_value=(True, ""))
|
||||
mocker.patch(
|
||||
"app.service_api_client.get_services", return_value={"data": [service]}
|
||||
)
|
||||
mocker.patch("app.user_api_client.get_user", return_value=usr)
|
||||
mocker.patch("app.user_api_client.get_user_by_email", return_value=usr)
|
||||
mocker.patch("app.service_api_client.get_service", return_value={"data": service})
|
||||
client_request.login(usr)
|
||||
return client_request.get("main.service_dashboard", service_id=service["id"])
|
||||
|
||||
|
||||
def test_menu_send_messages(
|
||||
client_request,
|
||||
mocker,
|
||||
@@ -1215,11 +1229,8 @@ def test_menu_send_messages(
|
||||
)
|
||||
in page
|
||||
)
|
||||
# assert url_for('main.uploads', service_id=service_one['id']) in page
|
||||
assert url_for("main.manage_users", service_id=service_one["id"]) in page
|
||||
|
||||
assert url_for("main.service_settings", service_id=service_one["id"]) not in page
|
||||
# assert url_for('main.api_keys', service_id=service_one['id']) not in page
|
||||
assert url_for("main.manage_users", service_id=service_one["id"]) not in page
|
||||
assert url_for("main.service_settings", service_id=service_one["id"]) in page
|
||||
|
||||
|
||||
def test_menu_manage_service(
|
||||
@@ -1255,10 +1266,39 @@ def test_menu_manage_service(
|
||||
)
|
||||
in page
|
||||
)
|
||||
assert url_for("main.manage_users", service_id=service_one["id"]) in page
|
||||
assert url_for("main.service_settings", service_id=service_one["id"]) in page
|
||||
assert url_for(".service_dashboard", service_id=service_one["id"]) in page
|
||||
assert url_for(".choose_template", service_id=service_one["id"]) in page
|
||||
|
||||
# assert url_for('main.api_keys', service_id=service_one['id']) not in page
|
||||
|
||||
def test_menu_main_settings(
|
||||
client_request,
|
||||
mocker,
|
||||
api_user_active,
|
||||
service_one,
|
||||
mock_get_service_templates,
|
||||
mock_has_no_jobs,
|
||||
mock_get_template_statistics,
|
||||
mock_get_service_statistics,
|
||||
mock_get_annual_usage_for_service,
|
||||
mock_get_inbound_sms_summary,
|
||||
mock_get_free_sms_fragment_limit,
|
||||
):
|
||||
page = _test_settings_menu(
|
||||
client_request,
|
||||
mocker,
|
||||
api_user_active,
|
||||
service_one,
|
||||
["view_activity", "user_profile", "manage_users", "manage_settings"],
|
||||
)
|
||||
page = str(page)
|
||||
assert (
|
||||
url_for(
|
||||
"main.service_settings",
|
||||
service_id=service_one["id"],
|
||||
)
|
||||
in page
|
||||
)
|
||||
assert url_for("main.service_settings", service_id=service_one["id"]) in page
|
||||
|
||||
|
||||
def test_menu_manage_api_keys(
|
||||
@@ -1296,8 +1336,8 @@ def test_menu_manage_api_keys(
|
||||
)
|
||||
in page
|
||||
)
|
||||
assert url_for("main.manage_users", service_id=service_one["id"]) in page
|
||||
assert url_for("main.service_settings", service_id=service_one["id"]) in page
|
||||
# assert url_for("main.manage_users", service_id=service_one["id"]) not in page
|
||||
# assert url_for("main.service_settings", service_id=service_one["id"]) not in page
|
||||
assert url_for("main.api_integration", service_id=service_one["id"]) in page
|
||||
|
||||
|
||||
@@ -1324,8 +1364,8 @@ def test_menu_all_services_for_platform_admin_user(
|
||||
)
|
||||
page = str(page)
|
||||
assert url_for("main.choose_template", service_id=service_one["id"]) in page
|
||||
assert url_for("main.manage_users", service_id=service_one["id"]) in page
|
||||
assert url_for("main.service_settings", service_id=service_one["id"]) in page
|
||||
# assert url_for("main.manage_users", service_id=service_one["id"]) in page
|
||||
# assert url_for("main.service_settings", service_id=service_one["id"]) in page
|
||||
# assert url_for('main.view_notifications', service_id=service_one['id'], message_type='email') in page
|
||||
assert (
|
||||
url_for(
|
||||
|
||||
@@ -27,7 +27,7 @@ from tests.conftest import (
|
||||
(
|
||||
create_active_user_with_permissions(),
|
||||
(
|
||||
"Test User (you) "
|
||||
"Test User(you) "
|
||||
"Permissions "
|
||||
"Can See dashboard "
|
||||
"Can Send messages "
|
||||
@@ -39,18 +39,18 @@ from tests.conftest import (
|
||||
),
|
||||
(
|
||||
create_active_user_empty_permissions(),
|
||||
("Test User With Empty Permissions (you) " "Permissions"),
|
||||
("Test User With Empty Permissions(you) " "Permissions"),
|
||||
False,
|
||||
),
|
||||
(
|
||||
create_active_user_view_permissions(),
|
||||
("Test User With Permissions (you) " "Permissions " "Can See dashboard"),
|
||||
("Test User With Permissions(you) " "Permissions " "Can See dashboard"),
|
||||
False,
|
||||
),
|
||||
(
|
||||
create_active_user_manage_template_permissions(),
|
||||
(
|
||||
"Test User With Permissions (you) "
|
||||
"Test User With Permissions(you) "
|
||||
"Permissions "
|
||||
"Can See dashboard "
|
||||
"Can Add and edit templates"
|
||||
@@ -232,7 +232,7 @@ def test_should_show_caseworker_on_overview_page(
|
||||
|
||||
assert normalize_spaces(page.select_one("h1").text) == "Team members"
|
||||
assert normalize_spaces(page.select(".user-list-item")[0].text) == (
|
||||
"Test User With Permissions (you) " "Permissions " "Can See dashboard"
|
||||
"Test User With Permissions(you) " "Permissions " "Can See dashboard"
|
||||
)
|
||||
# [1:5] are invited users
|
||||
assert normalize_spaces(page.select(".user-list-item")[6].text) == (
|
||||
@@ -1240,7 +1240,7 @@ def test_cancel_invited_user_doesnt_work_if_user_not_invited_to_this_service(
|
||||
(
|
||||
"pending",
|
||||
(
|
||||
"invited_user@test.gsa.gov (invited) "
|
||||
"invited_user@test.gsa.gov(invited) "
|
||||
"Permissions "
|
||||
"Can See dashboard "
|
||||
"Can Send messages "
|
||||
@@ -1252,7 +1252,7 @@ def test_cancel_invited_user_doesnt_work_if_user_not_invited_to_this_service(
|
||||
(
|
||||
"cancelled",
|
||||
(
|
||||
"invited_user@test.gsa.gov (cancelled invite) "
|
||||
"invited_user@test.gsa.gov(cancelled invite) "
|
||||
"Permissions"
|
||||
# all permissions are greyed out
|
||||
),
|
||||
@@ -1413,10 +1413,7 @@ def test_manage_user_page_shows_how_many_folders_user_can_view(
|
||||
user_div = page.select_one(
|
||||
"h2[title='notify@digital.cabinet-office.gov.uk']"
|
||||
).parent
|
||||
assert (
|
||||
user_div.select_one(".tick-cross-list-hint:last-child").text.strip()
|
||||
== expected_message
|
||||
)
|
||||
assert user_div.select_one(".tick-cross-list-hint").text.strip() == expected_message
|
||||
|
||||
|
||||
def test_manage_user_page_doesnt_show_folder_hint_if_service_has_no_folders(
|
||||
|
||||
@@ -400,9 +400,9 @@ def test_navigation_urls(
|
||||
assert [a["href"] for a in page.select(".nav a")] == [
|
||||
"/services/{}/templates".format(SERVICE_ONE_ID),
|
||||
"/services/{}".format(SERVICE_ONE_ID),
|
||||
"/services/{}/users".format(SERVICE_ONE_ID),
|
||||
"/services/{}/usage".format(SERVICE_ONE_ID),
|
||||
"/services/{}/service-settings".format(SERVICE_ONE_ID),
|
||||
# "/services/{}/users".format(SERVICE_ONE_ID),
|
||||
# "/services/{}/service-settings".format(SERVICE_ONE_ID),
|
||||
# '/services/{}/api'.format(SERVICE_ONE_ID),
|
||||
]
|
||||
|
||||
@@ -418,7 +418,7 @@ def test_caseworkers_get_caseworking_navigation(
|
||||
client_request.login(active_caseworking_user)
|
||||
page = client_request.get("main.choose_template", service_id=SERVICE_ONE_ID)
|
||||
assert normalize_spaces(page.select_one("header + .grid-container nav").text) == (
|
||||
"Send messages Sent messages Team members"
|
||||
"Send messages Sent messages"
|
||||
)
|
||||
|
||||
|
||||
@@ -433,5 +433,5 @@ def test_caseworkers_see_jobs_nav_if_jobs_exist(
|
||||
client_request.login(active_caseworking_user)
|
||||
page = client_request.get("main.choose_template", service_id=SERVICE_ONE_ID)
|
||||
assert normalize_spaces(page.select_one("header + .grid-container nav").text) == (
|
||||
"Send messages Sent messages Team members"
|
||||
"Send messages Sent messages"
|
||||
)
|
||||
|
||||
@@ -2323,6 +2323,10 @@ def client_request(logged_in_client, mocker, service_one): # noqa (C901 too com
|
||||
"app.service_api_client.get_global_notification_count", side_effect=_get
|
||||
)
|
||||
|
||||
mocker.patch(
|
||||
"app.billing_api_client.create_or_update_free_sms_fragment_limit", autospec=True
|
||||
)
|
||||
|
||||
class ClientRequest:
|
||||
@staticmethod
|
||||
@contextmanager
|
||||
@@ -3594,3 +3598,21 @@ def end_to_end_authenticated_context(browser):
|
||||
context = browser.new_context(storage_state=auth_state_path)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def fake_markdown_file():
|
||||
input = "#Test"
|
||||
return input
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def fake_jinja_template():
|
||||
input = "{% if True %}True{% endif %}"
|
||||
return input
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def fake_soup_template():
|
||||
input = "<h1>Test</h1>"
|
||||
return input
|
||||
|
||||
Reference in New Issue
Block a user