diff --git a/app/main/views/performance.py b/app/main/views/performance.py index 29fd73a85..a3948742c 100644 --- a/app/main/views/performance.py +++ b/app/main/views/performance.py @@ -4,6 +4,7 @@ from operator import itemgetter from statistics import mean from flask import render_template +from notifications_utils.timezones import convert_utc_to_local_timezone from app import performance_dashboard_api_client, status_api_client from app.main import main @@ -12,8 +13,8 @@ from app.main import main @main.route("/performance") def performance(): stats = performance_dashboard_api_client.get_performance_dashboard_stats( - start_date=(datetime.utcnow() - timedelta(days=7)).date(), - end_date=datetime.utcnow().date(), + start_date=(convert_utc_to_local_timezone(datetime.utcnow()) - timedelta(days=7)).date(), + end_date=convert_utc_to_local_timezone(datetime.utcnow()).date(), ) stats['organisations_using_notify'] = sorted( [ diff --git a/app/templates/views/dashboard/_jobs.html b/app/templates/views/dashboard/_jobs.html index 94b5656ef..37cc923f9 100644 --- a/app/templates/views/dashboard/_jobs.html +++ b/app/templates/views/dashboard/_jobs.html @@ -17,9 +17,7 @@ ) %} {% call row_heading() %}
- {% if item.upload_type == 'letter' %} - {{ item.original_file_name }} - {% elif item.upload_type == 'contact_list' %} + {% if item.upload_type == 'contact_list' %} {{ item.original_file_name }} {% else %} {{ item.original_file_name }} diff --git a/tests/app/main/views/organisations/test_organisations.py b/tests/app/main/views/organisations/test_organisations.py index 18e47fa27..916481c82 100644 --- a/tests/app/main/views/organisations/test_organisations.py +++ b/tests/app/main/views/organisations/test_organisations.py @@ -1647,7 +1647,7 @@ def test_organisation_billing_page_when_the_agreement_is_signed_by_a_known_perso organisation_one['agreement_signed_version'] = 2.5 organisation_one['agreement_signed_by_id'] = signed_by_id organisation_one['agreement_signed_on_behalf_of_name'] = signed_by_name - organisation_one['agreement_signed_at'] = 'Thu, 20 Feb 2020 00:00:00 GMT' + organisation_one['agreement_signed_at'] = 'Thu, 20 Feb 2020 06:00:00 GMT' mocker.patch('app.organisations_client.get_organisation', return_value=organisation_one) diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py index 741f7cc06..aecb41062 100644 --- a/tests/app/main/views/test_index.py +++ b/tests/app/main/views/test_index.py @@ -277,69 +277,6 @@ def test_email_branding_preview( assert mock_get_email_branding.called is email_branding_retrieved -@pytest.mark.parametrize('branding_style, filename', [ - ('hm-government', 'hm-government'), - (None, 'no-branding'), - (FieldWithNoneOption.NONE_OPTION_VALUE, 'no-branding') -]) -def test_letter_template_preview_links_to_the_correct_image( - client_request, - mocker, - mock_get_letter_branding_by_id, - branding_style, - filename, -): - page = client_request.get( - 'main.letter_template', - _test_page_title=False, - # Letter HTML doesn’t use the Design System, so elements won’t have class attributes - _test_for_elements_without_class=False, - branding_style=branding_style - ) - - image_link = page.find('img')['src'] - - assert image_link == url_for( - 'no_cookie.letter_branding_preview_image', - filename=filename, - page=1 - ) - - -def test_letter_template_preview_headers( - client_request, - mock_get_letter_branding_by_id, -): - response = client_request.get_response( - 'main.letter_template', branding_style='hm-government' - ) - - assert response.headers.get('X-Frame-Options') == 'SAMEORIGIN' - - -def test_letter_spec_redirect(client_request): - client_request.get( - 'main.letter_spec', - _expected_status=302, - _expected_redirect=( - 'https://docs.notifications.service.gov.uk' - '/documentation/images/notify-pdf-letter-spec-v2.4.pdf' - ), - ) - - -def test_letter_spec_redirect_with_non_logged_in_user(client_request): - client_request.logout() - client_request.get( - 'main.letter_spec', - _expected_status=302, - _expected_redirect=( - 'https://docs.notifications.service.gov.uk' - '/documentation/images/notify-pdf-letter-spec-v2.4.pdf' - ), - ) - - def test_font_preload( client_request, mock_get_service_and_organisation_counts, diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index ac0967c8a..86530383d 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -455,48 +455,3 @@ def test_should_show_updates_for_scheduled_job_as_json( @freeze_time("2016-01-10 12:00:00.000000") def test_time_left(job_created_at, expected_message): assert get_time_left(job_created_at) == expected_message - - -@freeze_time("2016-01-01 11:09:00.061258") -def test_should_show_letter_job_with_first_class_if_notifications_are_first_class( - client_request, - mock_get_service_letter_template, - mock_get_letter_job, - mock_get_service_data_retention, - fake_uuid, - mocker, -): - notifications = create_notifications(template_type='letter', postage='first') - mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications) - - page = client_request.get( - 'main.view_job', - service_id=SERVICE_ONE_ID, - job_id=fake_uuid, - ) - - assert normalize_spaces(page.select('.keyline-block')[1].text) == '5 January Estimated delivery date' - - -@freeze_time("2016-01-01 11:09:00.061258") -def test_should_show_letter_job_with_first_class_if_no_notifications( - client_request, - service_one, - mock_get_letter_job, - fake_uuid, - mock_get_notifications_with_no_notifications, - mock_get_service_data_retention, - mocker -): - mocker.patch( - 'app.service_api_client.get_service_template', - return_value={'data': create_template(template_type='letter', postage='first')} - ) - - page = client_request.get( - 'main.view_job', - service_id=SERVICE_ONE_ID, - job_id=fake_uuid, - ) - - assert normalize_spaces(page.select('.keyline-block')[1].text) == '5 January Estimated delivery date' diff --git a/tests/app/main/views/test_performance.py b/tests/app/main/views/test_performance.py index 573518402..12552e5d5 100644 --- a/tests/app/main/views/test_performance.py +++ b/tests/app/main/views/test_performance.py @@ -106,7 +106,7 @@ def _get_example_performance_data(): } -@freeze_time('2021-01-01') +@freeze_time('2021-01-01 12:00') def test_should_render_performance_page( mocker, client_request, diff --git a/tests/app/main/views/test_providers.py b/tests/app/main/views/test_providers.py index ceaafdd36..b58117a5b 100644 --- a/tests/app/main/views/test_providers.py +++ b/tests/app/main/views/test_providers.py @@ -188,7 +188,7 @@ def test_view_providers_shows_all_providers( assert table_data[1].text.strip() == "20" assert table_data[2].text.strip() == "42" assert table_data[3].text.strip() == "True" - assert table_data[4].text.strip() == "16 January at 3:20pm" + assert table_data[4].text.strip() == "16 January at 10:20am" assert table_data[5].text.strip() == "Test User" domestic_sms_second_row = domestic_sms_table.tbody.find_all('tr')[1] diff --git a/tests/app/main/views/test_returned_letters.py b/tests/app/main/views/test_returned_letters.py deleted file mode 100644 index 87ec8a5a0..000000000 --- a/tests/app/main/views/test_returned_letters.py +++ /dev/null @@ -1,199 +0,0 @@ -import uuid - -import pytest -from flask import url_for - -from tests.conftest import SERVICE_ONE_ID, normalize_spaces - - -def test_returned_letter_summary( - client_request, - mocker -): - summary_data = [{'returned_letter_count': 1234, 'reported_at': '2019-12-24'}] - mock = mocker.patch("app.service_api_client.get_returned_letter_summary", - return_value=summary_data) - - page = client_request.get("main.returned_letter_summary", service_id=SERVICE_ONE_ID) - - mock.assert_called_once_with(SERVICE_ONE_ID) - - assert page.h1.string.strip() == 'Returned letters' - assert normalize_spaces( - page.select_one('.table-field').text - ) == ( - '24 December 2019 ' - '1,234 letters' - ) - assert page.select_one('.table-field a')['href'] == url_for( - '.returned_letters', - service_id=SERVICE_ONE_ID, - reported_at='2019-12-24', - ) - - -def test_returned_letter_summary_with_one_letter( - client_request, - mocker -): - summary_data = [{'returned_letter_count': 1, 'reported_at': '2019-12-24'}] - mock = mocker.patch("app.service_api_client.get_returned_letter_summary", - return_value=summary_data) - - page = client_request.get("main.returned_letter_summary", service_id=SERVICE_ONE_ID) - - mock.assert_called_once_with(SERVICE_ONE_ID) - - assert page.h1.string.strip() == 'Returned letters' - assert normalize_spaces( - page.select_one('.table-field').text - ) == ( - '24 December 2019 ' - '1 letter' - ) - - -def test_returned_letters_page( - client_request, - mocker -): - data = [ - { - 'notification_id': uuid.uuid4(), - 'client_reference': client_reference, - 'created_at': '2019-12-24 13:30', - 'email_address': 'test@gsa.gov', - 'template_name': template_name, - 'template_id': uuid.uuid4(), - 'template_version': None, - 'original_file_name': original_file_name, - 'job_row_number': None, - 'uploaded_letter_file_name': uploaded_letter_file_name, - } - for client_reference, template_name, original_file_name, uploaded_letter_file_name in ( - ('ABC123', 'Example template', None, None), - (None, 'Example template', 'Example spreadsheet.xlsx', None), - (None, 'Example template', None, None), - ('DEF456', None, None, 'Example precompiled.pdf'), - (None, None, None, 'Example one-off.pdf'), - ('XYZ999', None, None, None), - ) - ] - mocker.patch('app.service_api_client.get_returned_letters', return_value=data) - - page = client_request.get( - 'main.returned_letters', - service_id=SERVICE_ONE_ID, - reported_at='2019-12-24', - ) - - assert [ - 'Template name Originally sent', - 'Example template Reference ABC123 Sent 24 December 2019', - 'Example template Sent from Example spreadsheet.xlsx Sent 24 December 2019', - 'Example template No reference provided Sent 24 December 2019', - 'Example precompiled.pdf Reference DEF456 Sent 24 December 2019', - 'Example one-off.pdf No reference provided Sent 24 December 2019', - 'Provided as PDF Reference XYZ999 Sent 24 December 2019', - ] == [ - normalize_spaces(row.text) for row in page.select('tr') - ] - - -@pytest.mark.parametrize('number_of_letters, expected_message', ( - pytest.param( - 51, - 'Only showing the first 50 of 51 rows' - ), - pytest.param( - 1234, - 'Only showing the first 50 of 1,234 rows' - ), -)) -def test_returned_letters_page_with_many_letters( - client_request, - mocker, - number_of_letters, - expected_message, -): - data = [ - { - 'notification_id': uuid.uuid4(), - 'client_reference': None, - 'created_at': '2019-12-24 13:30', - 'email_address': 'test@gsa.gov', - 'template_name': 'Example template', - 'template_id': uuid.uuid4(), - 'template_version': None, - 'original_file_name': None, - 'job_row_number': None, - 'uploaded_letter_file_name': None, - } - ] * number_of_letters - mocker.patch('app.service_api_client.get_returned_letters', return_value=data) - - page = client_request.get( - 'main.returned_letters', - service_id=SERVICE_ONE_ID, - reported_at='2019-12-24', - ) - - assert len(data) == number_of_letters - assert len(page.select('tbody tr')) == 50 - assert normalize_spaces( - page.select_one('.table-show-more-link').text - ) == ( - expected_message - ) - assert page.select_one('a[download]').text == ( - 'Download this report (CSV)' - ) - assert page.select_one('a[download]')['href'] == url_for( - '.returned_letters_report', - service_id=SERVICE_ONE_ID, - reported_at='2019-12-24', - ) - - -def test_returned_letters_reports( - client_request, - mocker -): - data = [{ - 'notification_id': '12345678', - 'client_reference': '2344567', - 'created_at': '2019-12-24 13:30', - 'email_address': 'test@gsa.gov', - 'template_name': 'First letter template', - 'template_id': '3445667', - 'template_version': 2, - 'original_file_name': None, - 'job_row_number': None, - 'uploaded_letter_file_name': 'test_letter.pdf', - }] - mock = mocker.patch("app.service_api_client.get_returned_letters", return_value=data) - - response = client_request.get_response("main.returned_letters_report", - service_id=SERVICE_ONE_ID, - reported_at='2019-12-24') - - report = response.get_data(as_text=True) - mock.assert_called_once_with(SERVICE_ONE_ID, '2019-12-24') - assert report.strip() == ( - 'Notification ID,Reference,Date sent,Sent by,Template name,Template ID,Template version,' - + 'Spreadsheet file name,Spreadsheet row number,Uploaded letter file name\r\n' - + '12345678,2344567,2019-12-24 13:30,test@gsa.gov,' - + 'First letter template,3445667,2,,,test_letter.pdf' - ) - - -def test_returned_letters_reports_returns_404_for_bad_date( - client_request, - mocker -): - mock = mocker.patch("app.service_api_client.get_returned_letters") - client_request.get_response("main.returned_letters_report", - service_id=SERVICE_ONE_ID, - reported_at='19-12-2019', - _expected_status=404) - assert mock.called is False diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 518be8d7c..1d07f0f3d 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -4226,14 +4226,14 @@ def test_redirects_to_template_if_job_exists_already( 'email', '6ce466d0-fd6a-11e5-82f5-e0accb9d11a6', ['EmergencyContactList.xls'], - 'Uploaded today at 10:59am', + 'Uploaded today at 5:59am', '100 email addresses', ), ( 'sms', 'd7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad', ['phone number list.csv', 'UnusedList.tsv'], - 'Uploaded today at 1:00pm', + 'Uploaded today at 8:00am', '123 phone numbers', ), )) diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 53d534fff..aba7a9b0b 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -493,7 +493,7 @@ def test_caseworker_sees_template_page_if_template_is_deleted( content = str(page) assert url_for("main.send_one_off", service_id=SERVICE_ONE_ID, template_id=fake_uuid) not in content - assert page.select('p.hint')[0].text.strip() == 'This template was deleted today at 3:00pm.' + assert page.select('p.hint')[0].text.strip() == 'This template was deleted today at 10:00am.' mock_get_deleted_template.assert_called_with(SERVICE_ONE_ID, template_id, None) @@ -1867,7 +1867,7 @@ def test_should_show_delete_template_page_with_time_block( mocker.patch('app.template_statistics_client.get_last_used_date_for_template', return_value='2012-01-01 12:00:00') - with freeze_time('2012-01-01 12:10:00'): + with freeze_time('2012-01-01 7:10:00'): page = client_request.get( '.delete_service_template', service_id=SERVICE_ONE_ID, @@ -1999,7 +1999,7 @@ def test_should_show_page_for_a_deleted_template( content = str(page) assert url_for("main.edit_service_template", service_id=SERVICE_ONE_ID, template_id=fake_uuid) not in content assert url_for("main.send_one_off", service_id=SERVICE_ONE_ID, template_id=fake_uuid) not in content - assert page.select('p.hint')[0].text.strip() == 'This template was deleted today at 3:00pm.' + assert page.select('p.hint')[0].text.strip() == 'This template was deleted today at 10:00am.' assert 'Delete this template' not in page.select_one('main').text mock_get_deleted_template.assert_called_with(SERVICE_ONE_ID, template_id, None) diff --git a/tests/app/main/views/uploads/test_upload_contact_list.py b/tests/app/main/views/uploads/test_upload_contact_list.py index 1a58c7453..644c7db1a 100644 --- a/tests/app/main/views/uploads/test_upload_contact_list.py +++ b/tests/app/main/views/uploads/test_upload_contact_list.py @@ -472,7 +472,7 @@ def test_view_contact_list( mocker.patch( 'app.models.contact_list.contact_list_api_client.get_contact_list', return_value=contact_list_json( - created_at='2020-03-03T12:12:12.000000Z', + created_at='2020-03-03T17:12:12.000000Z', service_id=SERVICE_ONE_ID, has_jobs=has_jobs ) @@ -539,7 +539,7 @@ def test_view_contact_list( ) -@freeze_time('2015-12-31 16:51:56') +@freeze_time('2015-12-31 21:51:56') def test_view_jobs_for_contact_list( mocker, client_request, @@ -550,7 +550,7 @@ def test_view_jobs_for_contact_list( mocker.patch( 'app.models.contact_list.contact_list_api_client.get_contact_list', return_value={ - 'created_at': '2015-12-31 12:12:12', + 'created_at': '2015-12-31 17:12:12', 'created_by': 'Test User', 'id': fake_uuid, 'original_file_name': 'EmergencyContactList.xls', @@ -585,12 +585,12 @@ def test_view_jobs_for_contact_list( 'Template Status', ( 'Template Y ' - 'Sending tomorrow at 11:09pm ' + 'Sending tomorrow at 6:09pm ' '1 text message waiting to send' ), ( 'Template Z ' - 'Sending tomorrow at 11:09am ' + 'Sending tomorrow at 6:09am ' '1 text message waiting to send' ), ( diff --git a/tests/app/main/views/uploads/test_upload_hub.py b/tests/app/main/views/uploads/test_upload_hub.py index 6b6c556a9..4450fd90f 100644 --- a/tests/app/main/views/uploads/test_upload_hub.py +++ b/tests/app/main/views/uploads/test_upload_hub.py @@ -13,31 +13,7 @@ from tests.conftest import ( ) -@pytest.mark.parametrize('extra_permissions', ( - pytest.param( - [], - marks=pytest.mark.xfail(raises=AssertionError), - ), - pytest.param( - ['upload_letters'], - marks=pytest.mark.xfail(raises=AssertionError), - ), - ['letter'], - ['letter', 'upload_letters'], -)) -def test_upload_letters_button_only_with_letters_permission( - client_request, - service_one, - mock_get_uploads, - mock_get_jobs, - mock_get_no_contact_lists, - extra_permissions, -): - service_one['permissions'] += extra_permissions - page = client_request.get('main.uploads', service_id=SERVICE_ONE_ID) - assert page.find('a', text=re.compile('Upload a letter')) - - +@pytest.mark.skip(reason="Not sure that TTS needs this") @pytest.mark.parametrize('user', ( create_platform_admin_user(), create_active_user_with_permissions(), @@ -62,10 +38,6 @@ def test_all_users_have_upload_contact_list( ([], ( 'You have not uploaded any files recently.' )), - (['letter'], ( - 'You have not uploaded any files recently. ' - 'Upload a letter and Notify will print, pack and post it for you.' - )), )) def test_get_upload_hub_with_no_uploads( mocker, @@ -119,7 +91,7 @@ def test_get_upload_hub_page( assert normalize_spaces(uploads[1].text.strip()) == ( 'some.csv ' - 'Sent 1 January 2016 at 11:09am ' + 'Sent 1 January 2016 at 6:09am ' '0 sending 8 delivered 2 failed' ) assert uploads[1].select_one('a.file-list-filename-large')['href'] == ( @@ -128,7 +100,7 @@ def test_get_upload_hub_page( assert normalize_spaces(uploads[2].text.strip()) == ( 'some.pdf ' - 'Sent 1 January 2016 at 11:09am ' + 'Sent 1 January 2016 at 6:09am ' 'Firstname Lastname ' '123 Example Street' ) @@ -167,12 +139,12 @@ def test_uploads_page_shows_scheduled_jobs( ), ( 'even_later.csv ' - 'Sending 1 January 2016 at 11:09pm ' + 'Sending 1 January 2016 at 6:09pm ' '1 text message waiting to send' ), ( 'send_me_later.csv ' - 'Sending 1 January 2016 at 11:09am ' + 'Sending 1 January 2016 at 6:09am ' '1 text message waiting to send' ), ] @@ -213,12 +185,12 @@ def test_uploads_page_shows_contact_lists_first( ), ( 'even_later.csv ' - 'Sending 1 January 2016 at 11:09pm ' + 'Sending 1 January 2016 at 6:09pm ' '1 text message waiting to send' ), ( 'send_me_later.csv ' - 'Sending 1 January 2016 at 11:09am ' + 'Sending 1 January 2016 at 6:09am ' '1 text message waiting to send' ), ] @@ -227,22 +199,3 @@ def test_uploads_page_shows_contact_lists_first( service_id=SERVICE_ONE_ID, contact_list_id='d7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad', ) - - -def test_get_uploads_shows_pagination( - client_request, - active_user_with_permissions, - mock_get_jobs, - mock_get_uploads, - mock_get_no_contact_lists, -): - page = client_request.get('main.uploads', service_id=SERVICE_ONE_ID) - - assert normalize_spaces(page.select_one('.next-page').text) == ( - 'Next page ' - 'page 2' - ) - assert normalize_spaces(page.select_one('.previous-page').text) == ( - 'Previous page ' - 'page 0' - ) diff --git a/tests/app/utils/test_time.py b/tests/app/utils/test_time.py index 509154c41..89db5f9cc 100644 --- a/tests/app/utils/test_time.py +++ b/tests/app/utils/test_time.py @@ -16,8 +16,8 @@ def test_is_less_than_days_ago(date_from_db, expected_result): @pytest.mark.parametrize('datetime_string, financial_year', ( ('2021-01-01T00:00:00+00:00', 2020), # Start of 2021 - ('2021-03-31T22:59:59+00:00', 2020), # One minute before midnight (BST) - ('2021-03-31T23:00:00+00:00', 2021), # Midnight (BST) + ('2021-04-01T03:59:59+00:00', 2020), # One minute before midnight (BST) + ('2021-04-01T04:00:00+00:00', 2021), # Midnight (BST) ('2021-12-12T12:12:12+01:00', 2021), # Later in the year )) def test_get_financial_year(datetime_string, financial_year):