diff --git a/.github/workflows/test_endpoints.yaml b/.github/workflows/test_endpoints.yaml index 8a0cab59b1..d76f420ffa 100644 --- a/.github/workflows/test_endpoints.yaml +++ b/.github/workflows/test_endpoints.yaml @@ -58,7 +58,7 @@ jobs: echo "PYTHONPATH=/github/workspace/env/site-packages:${{ env.PYTHONPATH}}" >> $GITHUB_ENV - name: Checks for new endpoints against AWS WAF rules - uses: cds-snc/notification-utils/.github/actions/waffles@a6ed8d1bc1b70780a204912e4266b1981b330bae # 52.0.4 + uses: cds-snc/notification-utils/.github/actions/waffles@08ba5512ae392390b6c991042858f3cbe4e8aa95 # 52.0.11 with: app-loc: '/github/workspace' app-libs: '/github/workspace/env/site-packages' diff --git a/app/main/views/send.py b/app/main/views/send.py index d11efe2b74..8b38b29326 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -35,6 +35,7 @@ from app import ( current_service, + get_current_locale, job_api_client, notification_api_client, redis_client, @@ -628,7 +629,7 @@ def send_test_preview(service_id, template_id, filetype): return TemplatePreview.from_utils_template(template, filetype, page=request.args.get("page")) -def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_pdf=False): +def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_pdf=False, user_language="en"): try: # The happy path is that the job doesn’t already exist, so the # API will return a 404 and the client will raise HTTPError. @@ -692,6 +693,7 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_ remaining_messages=recipients_remaining_messages, international_sms=current_service.has_permission("international_sms"), max_rows=get_csv_max_rows(service_id), + user_language=user_language, ) if request.args.get("from_test"): @@ -764,7 +766,8 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_ ) @user_has_permissions("send_messages", restrict_admin_usage=True) def check_messages(service_id, template_id, upload_id, row_index=2): - data = _check_messages(service_id, template_id, upload_id, row_index) + current_lang = get_current_locale(current_app) + data = _check_messages(service_id, template_id, upload_id, row_index, user_language=current_lang) all_statistics_daily = template_statistics_client.get_template_statistics_for_service(service_id, limit_days=1) data["stats_daily"] = aggregate_notifications_stats(all_statistics_daily) data["time_to_reset"] = get_limit_reset_time_et() @@ -1142,9 +1145,10 @@ def get_sms_sender_from_session(): def get_spreadsheet_column_headings_from_template(template): + current_lang = get_current_locale(current_app) column_headings = [] - for column_heading in first_column_headings[template.template_type] + list(template.placeholders): + for column_heading in first_column_headings[current_lang][template.template_type] + list(template.placeholders): if column_heading not in Columns.from_keys(column_headings): column_headings.append(column_heading) diff --git a/poetry.lock b/poetry.lock index 249239f8c8..e47ed34d7e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1455,7 +1455,7 @@ requests = ">=2.0.0" [[package]] name = "notifications-utils" -version = "52.0.9" +version = "52.0.11" description = "Shared python code for Notification - Provides logging utils etc." category = "main" optional = false @@ -1489,8 +1489,8 @@ werkzeug = "2.3.7" [package.source] type = "git" url = "https://github.com/cds-snc/notifier-utils.git" -reference = "52.0.9" -resolved_reference = "f63ebcc2868839ee0a7b3bb7c4f2b77164130c35" +reference = "52.0.11" +resolved_reference = "08ba5512ae392390b6c991042858f3cbe4e8aa95" [[package]] name = "openpyxl" @@ -2564,4 +2564,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "~3.10.8" -content-hash = "2dd2004c68a9bd24a649847213a046c3c0f9487398903c0b6853a8a889837982" +content-hash = "c0ce490148b66505860c4cf997491b6733410a9e75dd01e50398f69205fe3d2f" diff --git a/pyproject.toml b/pyproject.toml index c2d7c9d24f..8c3f6694dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,7 @@ awscli-cwlogs = "^1.4.6" # Putting upgrade on hold due to v1.0.0 using sha512 instead of sha1 by default itsdangerous = "2.1.2" # pyup: <1.0.0 -notifications-utils = {git = "https://github.com/cds-snc/notifier-utils.git", rev = "52.0.9"} +notifications-utils = {git = "https://github.com/cds-snc/notifier-utils.git", rev = "52.0.11"} rsa = "^4.1" # not directly required, pinned by Snyk to avoid a vulnerability unidecode = "^1.3.6" diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index d015de22c4..39d9e59444 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -2124,37 +2124,6 @@ def test_test_message_can_only_be_sent_now( assert 'name="scheduled_for"' not in content -def test_letter_can_only_be_sent_now( - client_request, - mocker, - mock_get_live_service, - mock_get_service_letter_template, - mock_get_users_by_service, - mock_get_service_statistics, - mock_get_template_statistics, - mock_s3_set_metadata, - mock_get_job_doesnt_exist, - mock_get_jobs, - fake_uuid, -): - mocker.patch( - "app.main.views.send.s3download", - return_value="addressline1, addressline2, postcode\na,b,c", - ) - mocker.patch("app.main.views.send.set_metadata_on_csv_upload") - mocker.patch("app.main.views.send.get_page_count_for_letter", return_value=1) - - page = client_request.get( - "main.check_messages", - service_id=SERVICE_ONE_ID, - upload_id=fake_uuid, - template_id=fake_uuid, - ) - - assert 'name="scheduled_for"' not in page - assert normalize_spaces(page.select_one("[type=submit]").text) == ("Send all now") - - @pytest.mark.parametrize("when", ["", "2016-08-25T13:04:21.767198"]) def test_create_job_should_call_api( client_request, @@ -2650,127 +2619,6 @@ def test_check_messages_shows_trial_mode_error( ) -@pytest.mark.parametrize( - "restricted, error_should_be_shown", - [ - (True, True), - (False, False), - ], -) -@pytest.mark.parametrize( - "number_of_rows, expected_error_message", - [ - (1, "You cannot send this letter"), - (11, "You cannot send these letters"), # Less than trial mode limit - (111, "You cannot send these letters"), # More than trial mode limit - ], -) -def test_check_messages_shows_trial_mode_error_for_letters( - client_request, - service_one, - mock_get_service_letter_template, - mock_has_permissions, - mock_get_users_by_service, - mock_get_service_statistics, - mock_get_template_statistics, - mock_get_job_doesnt_exist, - mock_get_jobs, - mock_s3_set_metadata, - fake_uuid, - mocker, - restricted, - error_should_be_shown, - number_of_rows, - expected_error_message, -): - service_one["restricted"] = restricted - mocker.patch("app.service_api_client.get_service", return_value={"data": service_one}) - - mocker.patch( - "app.main.views.send.s3download", - return_value="\n".join( - ["address_line_1,address_line_2,postcode,"] + ["First Last, 123 Street, SW1 1AA"] * number_of_rows - ), - ) - mocker.patch( - "app.main.views.send.get_page_count_for_letter", - return_value=3, - ) - - with client_request.session_transaction() as session: - session["file_uploads"] = { - fake_uuid: { - "template_id": "", - } - } - - page = client_request.get( - "main.check_messages", - service_id=SERVICE_ONE_ID, - template_id=fake_uuid, - upload_id=fake_uuid, - _test_page_title=False, - ) - - error = page.select(".banner-dangerous") - - if error_should_be_shown: - assert normalize_spaces(error[0].text) == ("{} " "In trial mode, you can only preview how your letters will look").format( - expected_error_message - ) - else: - assert not error - - assert len(page.select(".letter img")) == 3 - - -def test_check_messages_shows_data_errors_before_trial_mode_errors_for_letters( - mocker, - client_request, - mock_get_service_letter_template, - mock_has_permissions, - mock_get_users_by_service, - mock_get_service_statistics, - mock_get_template_statistics, - mock_get_job_doesnt_exist, - mock_get_jobs, - fake_uuid, -): - mocker.patch( - "app.main.views.send.s3download", - return_value="\n".join( - ["address_line_1,address_line_2,postcode,"] - + [" , ,11SW1 1AA"] - + [" , ,11SW1 1AA"] - ), - ) - - mocker.patch( - "app.main.views.send.get_page_count_for_letter", - return_value=5, - ) - - with client_request.session_transaction() as session: - session["file_uploads"] = { - fake_uuid: { - "template_id": "", - "original_file_name": "example.xlsx", - } - } - - page = client_request.get( - "main.check_messages", - service_id=SERVICE_ONE_ID, - template_id=fake_uuid, - upload_id=fake_uuid, - _test_page_title=False, - original_file_name="example.xlsx", - ) - - assert normalize_spaces(page.find(role="alert").text) == ("Enter missing data in 2 rows") - assert not page.select(".table-field-index a") - - @pytest.mark.parametrize( "uploaded_file_name", ( @@ -2895,157 +2743,6 @@ def test_check_messages_adds_sender_id_in_session_to_metadata( ) -@pytest.mark.parametrize( - "extra_args", - ( - {}, - {"from_test": True}, - ), -) -def test_letters_from_csv_files_dont_have_download_link( - client_request, - mocker, - mock_get_service, - mock_get_service_letter_template, - mock_has_permissions, - fake_uuid, - mock_get_users_by_service, - mock_get_service_statistics, - mock_get_template_statistics, - mock_get_job_doesnt_exist, - mock_get_jobs, - mock_s3_set_metadata, - extra_args, -): - mocker.patch( - "app.main.views.send.s3download", - return_value=""" - address_line_1,address_line_2,postcode, - First Last, 123 Street, SW1 1AA - """, - ) - - mocker.patch( - "app.main.views.send.get_page_count_for_letter", - return_value=5, - ) - - with client_request.session_transaction() as session: - session["file_uploads"] = { - fake_uuid: { - "template_id": "", - } - } - - page = client_request.get( - "main.check_messages", - service_id=SERVICE_ONE_ID, - template_id=fake_uuid, - upload_id=fake_uuid, - _test_page_title=False, - **extra_args, - ) - - assert normalize_spaces(page.select_one(".banner-dangerous").text) == normalize_spaces( - "You cannot send this letter " "In trial mode, you can only preview how your letters will look" - ) - - assert len(page.select(".letter img")) == 5 - assert not page.select("a[download]") - - -@pytest.mark.parametrize("restricted", [True, False]) -def test_one_off_letters_have_download_link( - client_request, - mocker, - api_user_active, - mock_get_service_letter_template, - mock_has_permissions, - fake_uuid, - mock_get_users_by_service, - mock_get_service_statistics, - mock_get_template_statistics, - restricted, - service_one, -): - service_one["restricted"] = restricted - mocker.patch("app.service_api_client.get_service", return_value={"data": service_one}) - - mocker.patch( - "app.main.views.send.get_page_count_for_letter", - return_value=5, - ) - - with client_request.session_transaction() as session: - session["recipient"] = None - session["placeholders"] = { - "address_line_1": "First Last", - "address_line_2": "123 Street", - "postcode": "SW1 1AA", - } - - page = client_request.get( - "main.check_notification", - service_id=SERVICE_ONE_ID, - template_id=fake_uuid, - _test_page_title=False, - ) - - assert len(page.select(".letter img")) == 5 - - assert page.select_one("a[download]")["href"] == url_for( - "main.check_notification_preview", - service_id=SERVICE_ONE_ID, - template_id=fake_uuid, - filetype="pdf", - ) - assert page.select_one("a[download]").text == "Download as a PDF" - - -def test_send_one_off_letter_errors_in_trial_mode( - client_request, - mocker, - mock_get_service, - mock_get_service_letter_template, - mock_has_permissions, - fake_uuid, - mock_get_users_by_service, - mock_get_service_statistics, - mock_get_template_statistics, - mock_get_job_doesnt_exist, - mock_s3_set_metadata, -): - mocker.patch( - "app.main.views.send.get_page_count_for_letter", - return_value=5, - ) - - with client_request.session_transaction() as session: - session["recipient"] = None - session["placeholders"] = { - "address_line_1": "First Last", - "address_line_2": "123 Street", - "postcode": "SW1 1AA", - } - - page = client_request.get( - "main.check_notification", - service_id=SERVICE_ONE_ID, - template_id=fake_uuid, - _test_page_title=False, - ) - - assert normalize_spaces(page.select(".banner-dangerous")) == normalize_spaces( - "You cannot send this letter " "In trial mode, you can only preview how your letters will look" - ) - - assert len(page.select(".letter img")) == 5 - - assert not page.select("[type=submit]") - assert page.select_one(".back-link").text == "Back" - assert page.select_one("a[download]").text == "Download as a PDF" - - def test_check_messages_shows_over_max_row_error( client_request, mock_get_users_by_service,