From efab189ae8ad612a811d0fe1afc2845bce9ef59e Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 28 Sep 2018 17:08:28 +0100 Subject: [PATCH] update jobs to take into account first class --- app/main/views/jobs.py | 8 +++++- requirements-app.txt | 4 ++- requirements.txt | 12 ++++----- requirements_for_test.txt | 2 +- tests/__init__.py | 2 +- tests/app/main/views/test_jobs.py | 45 +++++++++++++++++++++++++++++++ tests/conftest.py | 2 ++ 7 files changed, 65 insertions(+), 10 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index b689f44c1..644e2d5bf 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -380,10 +380,16 @@ def get_job_partials(job, template): ) if template['template_type'] == 'letter': + # there might be no notifications if the job has only just been created and the tasks haven't run yet + if notifications['notifications']: + postage = notifications['notifications'][0]['postage'] + else: + postage = current_service.postage + counts = render_template( 'partials/jobs/count-letters.html', total=job.get('notification_count', 0), - delivery_estimate=get_letter_timings(job['created_at']).earliest_delivery, + delivery_estimate=get_letter_timings(job['created_at'], postage=postage).earliest_delivery, ) else: counts = render_template( diff --git a/requirements-app.txt b/requirements-app.txt index 82491e722..2a7af9c06 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -20,5 +20,7 @@ notifications-python-client==5.2.0 # PaaS awscli-cwlogs>=1.4,<1.5 +awscli==1.15.82 +botocore<1.11.0 -git+https://github.com/alphagov/notifications-utils.git@30.3.1#egg=notifications-utils==30.3.1 +git+https://github.com/alphagov/notifications-utils.git@30.4.0#egg=notifications-utils==30.4.0 diff --git a/requirements.txt b/requirements.txt index d38cebef9..dd8debd87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,17 +22,17 @@ notifications-python-client==5.2.0 # PaaS awscli-cwlogs>=1.4,<1.5 +awscli==1.15.82 +botocore<1.11.0 -git+https://github.com/alphagov/notifications-utils.git@30.3.1#egg=notifications-utils==30.3.1 +git+https://github.com/alphagov/notifications-utils.git@30.4.0#egg=notifications-utils==30.4.0 ## The following requirements were added by pip freeze: -awscli==1.16.20 bleach==2.1.3 boto3==1.6.16 -botocore==1.12.10 certifi==2018.8.24 chardet==3.0.4 -click==6.7 +Click==7.0 colorama==0.3.9 dnspython==1.15.0 docopt==0.6.2 @@ -52,7 +52,7 @@ lxml==4.2.5 MarkupSafe==1.0 mistune==0.8.3 monotonic==1.5 -openpyxl==2.5.7 +openpyxl==2.5.8 orderedset==2.0.1 phonenumbers==8.9.4 pyasn1==0.4.4 @@ -61,7 +61,7 @@ PyJWT==1.6.4 PyPDF2==1.26.0 python-dateutil==2.7.3 python-json-logger==0.1.8 -PyYAML==3.12 +PyYAML==3.13 redis==2.10.6 requests==2.19.1 rsa==3.4.2 diff --git a/requirements_for_test.txt b/requirements_for_test.txt index 52c30e8ff..2d14c978c 100644 --- a/requirements_for_test.txt +++ b/requirements_for_test.txt @@ -4,7 +4,7 @@ pytest==3.8.1 pytest-env==0.6.2 pytest-mock==1.10.0 pytest-cov==2.6.0 -pytest-xdist==1.23.1 +pytest-xdist==1.23.2 coveralls==1.5.1 httpretty==0.9.5 beautifulsoup4==4.6.3 diff --git a/tests/__init__.py b/tests/__init__.py index 1fc6e83db..15a90e7a0 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -390,7 +390,7 @@ def notification_json( status = 'delivered' links = {} if template_type == 'letter': - postage = 'second' + postage = postage or 'second' if with_links: links = { diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index a9eb287df..3c5a6b9fb 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -440,3 +440,48 @@ def test_should_show_updates_for_one_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_job, + fake_uuid, + active_user_with_permissions, + mocker, +): + mock_get_notifications( + mocker, + active_user_with_permissions, + diff_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' + + +@freeze_time("2016-01-01 11:09:00.061258") +def test_should_show_letter_job_with_first_class_if_no_notifications( + client_request, + mock_get_service_letter_template, + mock_get_job, + fake_uuid, + mock_get_notifications_with_no_notifications, + mocker +): + mocker.patch('app.main.views.jobs.current_service', 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/conftest.py b/tests/conftest.py index 4f514fd0c..c00bfd387 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1838,6 +1838,7 @@ def mock_get_notifications( is_precompiled_letter=False, client_reference=None, noti_status=None, + postage=None, ): def _get_notifications( service_id, @@ -1882,6 +1883,7 @@ def mock_get_notifications( client_reference=client_reference, status=noti_status, created_by_name='Firstname Lastname', + postage=postage ) return mocker.patch(