mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-03 21:21:14 -04:00
Updated reference files, refreshed ui/ux for report generation. Buttons toggle on and off based on if report exists
This commit is contained in:
@@ -302,6 +302,10 @@ def test_download_links_show_when_data_available(
|
||||
"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.s3_client.check_s3_file_exists", return_value=True)
|
||||
mock_obj = mocker.Mock()
|
||||
mock_obj.content_length = 1024
|
||||
mocker.patch("app.s3_client.s3_csv_client.get_csv_upload", return_value=mock_obj)
|
||||
|
||||
page = client_request.get(
|
||||
"main.all_jobs_activity",
|
||||
@@ -309,11 +313,10 @@ def test_download_links_show_when_data_available(
|
||||
)
|
||||
|
||||
assert "Download recent reports" in page.text
|
||||
assert "Download all data last 24 hours" in page.text
|
||||
assert "Download all data last 3 days" in page.text
|
||||
assert "Download all data last 5 days" in page.text
|
||||
assert "Download all data last 7 days" in page.text
|
||||
assert "No recent activity to download" not in page.text
|
||||
assert "Yesterday" in page.text
|
||||
assert "Last 3 days" in page.text
|
||||
assert "Last 5 days" in page.text
|
||||
assert "Last 7 days" in page.text
|
||||
|
||||
|
||||
def test_download_links_partial_data_available(
|
||||
@@ -338,6 +341,10 @@ def test_download_links_partial_data_available(
|
||||
"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.s3_client.check_s3_file_exists", return_value=True)
|
||||
mock_obj = mocker.Mock()
|
||||
mock_obj.content_length = 2048
|
||||
mocker.patch("app.s3_client.s3_csv_client.get_csv_upload", return_value=mock_obj)
|
||||
|
||||
page = client_request.get(
|
||||
"main.all_jobs_activity",
|
||||
@@ -345,10 +352,10 @@ def test_download_links_partial_data_available(
|
||||
)
|
||||
|
||||
assert "Download recent reports" in page.text
|
||||
assert "Download all data last 24 hours" in page.text
|
||||
assert "Download all data last 3 days" not in page.text
|
||||
assert "Download all data last 5 days" in page.text
|
||||
assert "Download all data last 7 days" not in page.text
|
||||
assert "Yesterday" in page.text
|
||||
assert "Last 3 days" in page.text
|
||||
assert "Last 5 days" in page.text
|
||||
assert "Last 7 days" in page.text
|
||||
assert "No recent activity to download" not in page.text
|
||||
|
||||
|
||||
@@ -362,6 +369,7 @@ def test_download_links_no_data_available(
|
||||
|
||||
mocker.patch("app.job_api_client.get_page_of_jobs", return_value=mock_jobs_empty)
|
||||
mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[])
|
||||
mocker.patch("app.s3_client.check_s3_file_exists", return_value=False)
|
||||
|
||||
page = client_request.get(
|
||||
"main.all_jobs_activity",
|
||||
@@ -369,14 +377,11 @@ def test_download_links_no_data_available(
|
||||
)
|
||||
|
||||
assert "Download recent reports" in page.text
|
||||
assert "Download all data last 24 hours" 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 7 days" not in page.text
|
||||
assert (
|
||||
"No recent activity to download. Download links will appear when jobs are available."
|
||||
in page.text
|
||||
)
|
||||
assert "Yesterday" in page.text
|
||||
assert "No messages sent" in page.text
|
||||
assert "Last 3 days - No messages sent" in page.text
|
||||
assert "Last 5 days - No messages sent" in page.text
|
||||
assert "Last 7 days - No messages sent" in page.text
|
||||
|
||||
|
||||
def test_download_not_available_to_users_without_dashboard(
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.main.views.notifications import (
|
||||
PERIOD_TO_S3_FILENAME,
|
||||
generate_empty_report_csv,
|
||||
)
|
||||
from notifications_utils.s3 import S3ObjectNotFound
|
||||
from app.main.views.notifications import PERIOD_TO_S3_FILENAME
|
||||
from tests.conftest import SERVICE_ONE_ID
|
||||
|
||||
|
||||
@@ -15,12 +11,6 @@ def test_period_to_s3_filename_mapping():
|
||||
assert PERIOD_TO_S3_FILENAME["seven_day"] == "7-day-report"
|
||||
|
||||
|
||||
def test_empty_csv_has_correct_headers():
|
||||
result = list(generate_empty_report_csv())
|
||||
assert len(result) == 1
|
||||
assert "Phone Number,Template,Sent by,Batch File" in result[0]
|
||||
|
||||
|
||||
@patch("app.main.views.notifications.s3download")
|
||||
@patch("app.main.views.notifications.generate_notifications_csv")
|
||||
def test_job_based_reports_dont_use_s3(
|
||||
@@ -71,27 +61,30 @@ def test_general_reports_use_s3(
|
||||
|
||||
|
||||
@patch("app.main.views.notifications.s3download")
|
||||
def test_missing_s3_file_returns_headers_only(
|
||||
def test_missing_s3_file_redirects_gracefully(
|
||||
mock_s3download,
|
||||
client_request,
|
||||
service_one,
|
||||
mock_get_service_data_retention,
|
||||
):
|
||||
from notifications_utils.s3 import S3ObjectNotFound
|
||||
|
||||
mock_s3download.side_effect = S3ObjectNotFound(
|
||||
{"Error": {"Code": "NoSuchKey"}}, "GetObject"
|
||||
)
|
||||
|
||||
response = client_request.get_response(
|
||||
# Verify that when an S3 file is missing, we redirect gracefully
|
||||
# instead of showing a 500 error
|
||||
client_request.get(
|
||||
"main.download_notifications_csv",
|
||||
service_id=SERVICE_ONE_ID,
|
||||
number_of_days="five_day",
|
||||
message_type="sms",
|
||||
_test_page_title=False,
|
||||
_expected_redirect=f"/services/{SERVICE_ONE_ID}/notifications/sms?status=sending,delivered,failed",
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert b"Phone Number,Template,Sent by" in response.data
|
||||
assert response.data.count(b"\n") == 1
|
||||
# The redirect happens, which means no 500 error occurred
|
||||
mock_s3download.assert_called_once_with(SERVICE_ONE_ID, "5-day-report")
|
||||
|
||||
|
||||
@patch("app.main.views.notifications.convert_s3_csv_timestamps")
|
||||
|
||||
@@ -34,7 +34,10 @@ def test_should_200_for_tour_start(
|
||||
"service one: ((one)) ((two)) ((three))"
|
||||
)
|
||||
|
||||
assert page.select("a.usa-button")[0]["href"] == url_for(
|
||||
# Find the tour step button specifically, not just any usa-button
|
||||
tour_buttons = [btn for btn in page.select("a.usa-button") if "tour" in btn.get("href", "")]
|
||||
assert len(tour_buttons) > 0, "No tour button found"
|
||||
assert tour_buttons[0]["href"] == url_for(
|
||||
".tour_step", service_id=SERVICE_ONE_ID, template_id=fake_uuid, step_index=1
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user