This commit is contained in:
Beverly Nguyen
2025-07-31 12:16:57 -07:00
parent 181ea66468
commit 1b04d1fd83
8 changed files with 37 additions and 49 deletions
+2 -2
View File
@@ -161,7 +161,7 @@
"filename": "app/config.py", "filename": "app/config.py",
"hashed_secret": "577a4c667e4af8682ca431857214b3a920883efc", "hashed_secret": "577a4c667e4af8682ca431857214b3a920883efc",
"is_verified": false, "is_verified": false,
"line_number": 121, "line_number": 119,
"is_secret": false "is_secret": false
} }
], ],
@@ -634,5 +634,5 @@
} }
] ]
}, },
"generated_at": "2025-07-31T19:13:35Z" "generated_at": "2025-07-31T19:16:39Z"
} }
+2 -2
View File
@@ -550,7 +550,7 @@ def register_errorhandlers(application): # noqa (C901 too complex)
application.logger.warning( application.logger.warning(
f"API {error_url} failed with status {error.status_code} message {error.message}", f"API {error_url} failed with status {error.status_code} message {error.message}",
exc_info=sys.exc_info(), exc_info=sys.exc_info(),
stack_info=True stack_info=True,
) )
error_code = error.status_code error_code = error.status_code
@@ -562,7 +562,7 @@ def register_errorhandlers(application): # noqa (C901 too complex)
application.logger.exception( application.logger.exception(
f"API {error_url} failed with status {error.status_code} message {error.message}", f"API {error_url} failed with status {error.status_code} message {error.message}",
exc_info=sys.exc_info(), exc_info=sys.exc_info(),
stack_info=True stack_info=True,
) )
error_code = 500 error_code = 500
+1 -3
View File
@@ -17,9 +17,7 @@ class Config(object):
ADMIN_BASE_URL = getenv("ADMIN_BASE_URL", "http://localhost:6012") ADMIN_BASE_URL = getenv("ADMIN_BASE_URL", "http://localhost:6012")
HEADER_COLOUR = "#81878b" # mix of dark-grey and mid-grey HEADER_COLOUR = "#81878b" # mix of dark-grey and mid-grey
LOGO_CDN_DOMAIN = (
"static-logos.notifications.service.gov.uk" # TODO use our own CDN
)
ASSETS_DEBUG = False ASSETS_DEBUG = False
# Credentials # Credentials
+1 -3
View File
@@ -22,9 +22,7 @@ class BaseAPIClient:
This class is not thread-safe. This class is not thread-safe.
""" """
def __init__( def __init__(self, api_key, base_url=API_PUBLIC_URL, timeout=30):
self, api_key, base_url=API_PUBLIC_URL, timeout=30
):
""" """
Initialise the client Initialise the client
Error if either of base_url or secret missing Error if either of base_url or secret missing
+19 -17
View File
@@ -295,10 +295,12 @@ def test_download_links_show_when_data_available(
mock_jobs_with_data = { mock_jobs_with_data = {
"data": [{"id": "job1", "created_at": "2020-01-01T00:00:00.000000+00:00"}], "data": [{"id": "job1", "created_at": "2020-01-01T00:00:00.000000+00:00"}],
"total": 1, "total": 1,
"page_size": 50 "page_size": 50,
} }
mocker.patch("app.job_api_client.get_page_of_jobs", return_value=mock_jobs_with_data) mocker.patch(
"app.job_api_client.get_page_of_jobs", return_value=mock_jobs_with_data
)
mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[{"id": "job1"}]) mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[{"id": "job1"}])
page = client_request.get( page = client_request.get(
@@ -323,7 +325,7 @@ def test_download_links_partial_data_available(
mock_jobs_with_data = { mock_jobs_with_data = {
"data": [{"id": "job1", "created_at": "2020-01-01T00:00:00.000000+00:00"}], "data": [{"id": "job1", "created_at": "2020-01-01T00:00:00.000000+00:00"}],
"total": 1, "total": 1,
"page_size": 50 "page_size": 50,
} }
mock_jobs_empty = {"data": [], "total": 0, "page_size": 50} mock_jobs_empty = {"data": [], "total": 0, "page_size": 50}
@@ -332,7 +334,9 @@ def test_download_links_partial_data_available(
return mock_jobs_with_data return mock_jobs_with_data
return mock_jobs_empty return mock_jobs_empty
mocker.patch("app.job_api_client.get_page_of_jobs", side_effect=mock_get_page_of_jobs) mocker.patch(
"app.job_api_client.get_page_of_jobs", side_effect=mock_get_page_of_jobs
)
mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[]) mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[])
page = client_request.get( page = client_request.get(
@@ -369,7 +373,10 @@ def test_download_links_no_data_available(
assert "Download all data last 3 days" not in page.text assert "Download all data last 3 days" not in page.text
assert "Download all data last 5 days" not in page.text assert "Download all data last 5 days" not in page.text
assert "Download all data last 7 days" not in page.text assert "Download all data last 7 days" not in page.text
assert "No recent activity to download. Download links will appear when jobs are available." in page.text assert (
"No recent activity to download. Download links will appear when jobs are available."
in page.text
)
def test_download_not_available_to_users_without_dashboard( def test_download_not_available_to_users_without_dashboard(
@@ -560,9 +567,8 @@ def test_should_show_notifications_for_a_service_with_next_previous(
): ):
mocker.patch( mocker.patch(
"app.notification_api_client.get_notifications_for_service", "app.notification_api_client.get_notifications_for_service",
return_value=notification_json( return_value=notification_json(service_one["id"], rows=50, with_links=True)
service_one["id"], rows=50, with_links=True | {"total": 150},
) | {"total": 150},
) )
page = client_request.get( page = client_request.get(
"main.view_notifications", "main.view_notifications",
@@ -608,9 +614,8 @@ def test_doesnt_show_next_button_on_last_page(
): ):
mocker.patch( mocker.patch(
"app.notification_api_client.get_notifications_for_service", "app.notification_api_client.get_notifications_for_service",
return_value=notification_json( return_value=notification_json(service_one["id"], rows=50, with_links=True)
service_one["id"], rows=50, with_links=True | {"total": 100},
) | {"total": 100},
) )
page = client_request.get( page = client_request.get(
"main.view_notifications", "main.view_notifications",
@@ -637,9 +642,7 @@ def test_doesnt_show_pagination_when_50_or_fewer_items(
): ):
mocker.patch( mocker.patch(
"app.notification_api_client.get_notifications_for_service", "app.notification_api_client.get_notifications_for_service",
return_value=notification_json( return_value=notification_json(service_one["id"], rows=50, with_links=False),
service_one["id"], rows=50, with_links=False
),
) )
page = client_request.get( page = client_request.get(
"main.view_notifications", "main.view_notifications",
@@ -663,9 +666,8 @@ def test_doesnt_show_pagination_with_search_term(
): ):
mocker.patch( mocker.patch(
"app.notification_api_client.get_notifications_for_service", "app.notification_api_client.get_notifications_for_service",
return_value=notification_json( return_value=notification_json(service_one["id"], rows=50, with_links=True)
service_one["id"], rows=50, with_links=True | {"total": 100},
) | {"total": 100},
) )
page = client_request.post( page = client_request.post(
"main.view_notifications", "main.view_notifications",
+3 -1
View File
@@ -185,7 +185,9 @@ def test_should_show_create_api_key_page(
label = item.select_one(".usa-radio__label") label = item.select_one(".usa-radio__label")
hint = label.select_one(".usa-hint") hint = label.select_one(".usa-hint")
# Get the label text without the hint text # Get the label text without the hint text
label_text = label.text.replace(hint.text, "").strip() if hint else label.text label_text = (
label.text.replace(hint.text, "").strip() if hint else label.text
)
assert normalize_spaces(label_text) == option[0] assert normalize_spaces(label_text) == option[0]
assert normalize_spaces(hint.text) == option[1] assert normalize_spaces(hint.text) == option[1]
else: else:
+6 -12
View File
@@ -50,9 +50,7 @@ def test_all_activity(
mock_get_page_of_jobs = mocker.patch( mock_get_page_of_jobs = mocker.patch(
"app.job_api_client.get_page_of_jobs", return_value=MOCK_JOBS "app.job_api_client.get_page_of_jobs", return_value=MOCK_JOBS
) )
mocker.patch( mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[])
"app.job_api_client.get_immediate_jobs", return_value=[]
)
response = client_request.get_response( response = client_request.get_response(
"main.all_jobs_activity", "main.all_jobs_activity",
@@ -65,7 +63,7 @@ def test_all_activity(
assert "All activity" in response.text assert "All activity" in response.text
assert any( assert any(
call[0][0] == SERVICE_ONE_ID and call[1].get('page') == current_page call[0][0] == SERVICE_ONE_ID and call[1].get("page") == current_page
for call in mock_get_page_of_jobs.call_args_list for call in mock_get_page_of_jobs.call_args_list
) )
page = BeautifulSoup(response.data, "html.parser") page = BeautifulSoup(response.data, "html.parser")
@@ -139,9 +137,7 @@ def test_all_activity_no_jobs(client_request, mocker):
"total": 0, "total": 0,
}, },
) )
mocker.patch( mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[])
"app.job_api_client.get_immediate_jobs", return_value=[]
)
response = client_request.get_response( response = client_request.get_response(
"main.all_jobs_activity", "main.all_jobs_activity",
service_id=SERVICE_ONE_ID, service_id=SERVICE_ONE_ID,
@@ -162,7 +158,7 @@ def test_all_activity_no_jobs(client_request, mocker):
expected_message == actual_message expected_message == actual_message
), f"Expected message '{expected_message}', but got '{actual_message}'" ), f"Expected message '{expected_message}', but got '{actual_message}'"
assert any( assert any(
call[0][0] == SERVICE_ONE_ID and call[1].get('page') == current_page call[0][0] == SERVICE_ONE_ID and call[1].get("page") == current_page
for call in mock_get_page_of_jobs.call_args_list for call in mock_get_page_of_jobs.call_args_list
) )
@@ -194,9 +190,7 @@ def test_all_activity_pagination(client_request, mocker):
"total": 100, "total": 100,
}, },
) )
mocker.patch( mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[])
"app.job_api_client.get_immediate_jobs", return_value=[]
)
response = client_request.get_response( response = client_request.get_response(
"main.all_jobs_activity", "main.all_jobs_activity",
@@ -204,7 +198,7 @@ def test_all_activity_pagination(client_request, mocker):
page=current_page, page=current_page,
) )
assert any( assert any(
call[0][0] == SERVICE_ONE_ID and call[1].get('page') == current_page call[0][0] == SERVICE_ONE_ID and call[1].get("page") == current_page
for call in mock_get_page_of_jobs.call_args_list for call in mock_get_page_of_jobs.call_args_list
) )
+3 -9
View File
@@ -145,9 +145,7 @@ def test_default_email_sender_is_checked_and_has_hint(
) )
assert page.select(".usa-radio input")[0].has_attr("checked") assert page.select(".usa-radio input")[0].has_attr("checked")
assert ( assert normalize_spaces(page.select_one(".usa-radio .usa-hint").text) == "(Default)"
normalize_spaces(page.select_one(".usa-radio .usa-hint").text) == "(Default)"
)
assert not page.select(".usa-radio input")[1].has_attr("checked") assert not page.select(".usa-radio input")[1].has_attr("checked")
@@ -162,9 +160,7 @@ def test_default_sms_sender_is_checked_and_has_hint(
) )
assert page.select(".usa-radio input")[0].has_attr("checked") assert page.select(".usa-radio input")[0].has_attr("checked")
assert ( assert normalize_spaces(page.select_one(".usa-radio .usa-hint").text) == "(Default)"
normalize_spaces(page.select_one(".usa-radio .usa-hint").text) == "(Default)"
)
assert not page.select(".usa-radio input")[1].has_attr("checked") assert not page.select(".usa-radio input")[1].has_attr("checked")
@@ -179,9 +175,7 @@ def test_default_sms_sender_is_checked_and_has_hint_when_there_are_no_inbound_nu
) )
assert page.select(".usa-radio input")[0].has_attr("checked") assert page.select(".usa-radio input")[0].has_attr("checked")
assert ( assert normalize_spaces(page.select_one(".usa-radio .usa-hint").text) == "(Default)"
normalize_spaces(page.select_one(".usa-radio .usa-hint").text) == "(Default)"
)
assert not page.select(".usa-radio input")[1].has_attr("checked") assert not page.select(".usa-radio input")[1].has_attr("checked")