fix timezone related cancel letter job bug

This commit is contained in:
Leo Hemsted
2020-04-14 13:08:38 +01:00
parent f90c475126
commit 7fe075393d
4 changed files with 30 additions and 14 deletions

View File

@@ -26,5 +26,4 @@ notifications-python-client==5.5.1
# PaaS # PaaS
awscli-cwlogs>=1.4,<1.5 awscli-cwlogs>=1.4,<1.5
git+https://github.com/alphagov/notifications-utils.git@36.12.2#egg=notifications-utils==36.12.2
git+https://github.com/alphagov/notifications-utils.git@36.12.0#egg=notifications-utils==36.12.0

View File

@@ -29,20 +29,20 @@ notifications-python-client==5.5.1
awscli-cwlogs>=1.4,<1.5 awscli-cwlogs>=1.4,<1.5
git+https://github.com/alphagov/notifications-utils.git@36.12.0#egg=notifications-utils==36.12.0 git+https://github.com/alphagov/notifications-utils.git@36.12.2#egg=notifications-utils==36.12.2
## The following requirements were added by pip freeze: ## The following requirements were added by pip freeze:
alembic==1.4.2 alembic==1.4.2
amqp==1.4.9 amqp==1.4.9
anyjson==0.3.3 anyjson==0.3.3
attrs==19.3.0 attrs==19.3.0
awscli==1.18.37 awscli==1.18.39
bcrypt==3.1.7 bcrypt==3.1.7
billiard==3.3.0.23 billiard==3.3.0.23
bleach==3.1.4 bleach==3.1.4
boto==2.49.0 boto==2.49.0
boto3==1.10.38 boto3==1.10.38
botocore==1.15.37 botocore==1.15.39
certifi==2020.4.5.1 certifi==2020.4.5.1
chardet==3.0.4 chardet==3.0.4
click==7.1.1 click==7.1.1
@@ -54,7 +54,7 @@ future==0.18.2
greenlet==0.4.15 greenlet==0.4.15
idna==2.9 idna==2.9
importlib-metadata==1.6.0 importlib-metadata==1.6.0
Jinja2==2.11.1 Jinja2==2.11.2
jmespath==0.9.5 jmespath==0.9.5
kombu==3.0.37 kombu==3.0.37
Mako==1.1.2 Mako==1.1.2

View File

@@ -336,7 +336,7 @@ def assert_job_stat(job, result, sent, delivered, failed):
@freeze_time('2019-06-13 13:00') @freeze_time('2019-06-13 13:00')
def test_dao_cancel_letter_job_cancels_job_and_returns_number_of_cancelled_notifications( def test_dao_cancel_letter_job_cancels_job_and_returns_number_of_cancelled_notifications(
sample_letter_template, admin_request sample_letter_template
): ):
job = create_job(template=sample_letter_template, notification_count=1, job_status='finished') job = create_job(template=sample_letter_template, notification_count=1, job_status='finished')
notification = create_notification(template=job.template, job=job, status='created') notification = create_notification(template=job.template, job=job, status='created')
@@ -347,7 +347,7 @@ def test_dao_cancel_letter_job_cancels_job_and_returns_number_of_cancelled_notif
@freeze_time('2019-06-13 13:00') @freeze_time('2019-06-13 13:00')
def test_can_letter_job_be_cancelled_returns_true_if_job_can_be_cancelled(sample_letter_template, admin_request): def test_can_letter_job_be_cancelled_returns_true_if_job_can_be_cancelled(sample_letter_template):
job = create_job(template=sample_letter_template, notification_count=1, job_status='finished') job = create_job(template=sample_letter_template, notification_count=1, job_status='finished')
create_notification(template=job.template, job=job, status='created') create_notification(template=job.template, job=job, status='created')
result, errors = can_letter_job_be_cancelled(job) result, errors = can_letter_job_be_cancelled(job)
@@ -357,7 +357,7 @@ def test_can_letter_job_be_cancelled_returns_true_if_job_can_be_cancelled(sample
@freeze_time('2019-06-13 13:00') @freeze_time('2019-06-13 13:00')
def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_notification_status_sending( def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_notification_status_sending(
sample_letter_template, admin_request sample_letter_template
): ):
job = create_job(template=sample_letter_template, notification_count=2, job_status='finished') job = create_job(template=sample_letter_template, notification_count=2, job_status='finished')
create_notification(template=job.template, job=job, status='sending') create_notification(template=job.template, job=job, status='sending')
@@ -368,7 +368,7 @@ def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_notifica
def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_letters_already_sent_to_dvla( def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_letters_already_sent_to_dvla(
sample_letter_template, admin_request sample_letter_template
): ):
with freeze_time('2019-06-13 13:00'): with freeze_time('2019-06-13 13:00'):
job = create_job(template=sample_letter_template, notification_count=1, job_status='finished') job = create_job(template=sample_letter_template, notification_count=1, job_status='finished')
@@ -384,7 +384,7 @@ def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_letters_
@freeze_time('2019-06-13 13:00') @freeze_time('2019-06-13 13:00')
def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_not_a_letter_job( def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_not_a_letter_job(
sample_template, admin_request sample_template
): ):
job = create_job(template=sample_template, notification_count=1, job_status='finished') job = create_job(template=sample_template, notification_count=1, job_status='finished')
create_notification(template=job.template, job=job, status='created') create_notification(template=job.template, job=job, status='created')
@@ -395,7 +395,7 @@ def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_not_a_le
@freeze_time('2019-06-13 13:00') @freeze_time('2019-06-13 13:00')
def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_job_not_finished( def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_job_not_finished(
sample_letter_template, admin_request sample_letter_template
): ):
job = create_job(template=sample_letter_template, notification_count=1, job_status="in progress") job = create_job(template=sample_letter_template, notification_count=1, job_status="in progress")
create_notification(template=job.template, job=job, status='created') create_notification(template=job.template, job=job, status='created')
@@ -406,7 +406,7 @@ def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_job_not_
@freeze_time('2019-06-13 13:00') @freeze_time('2019-06-13 13:00')
def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_notifications_not_in_db_yet( def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_notifications_not_in_db_yet(
sample_letter_template, admin_request sample_letter_template
): ):
job = create_job(template=sample_letter_template, notification_count=2, job_status='finished') job = create_job(template=sample_letter_template, notification_count=2, job_status='finished')
create_notification(template=job.template, job=job, status='created') create_notification(template=job.template, job=job, status='created')
@@ -415,6 +415,17 @@ def test_can_letter_job_be_cancelled_returns_false_and_error_message_if_notifica
assert errors == "We are still processing these letters, please try again in a minute." assert errors == "We are still processing these letters, please try again in a minute."
def test_can_letter_job_be_cancelled_respects_bst(sample_letter_template):
job = create_job(template=sample_letter_template, created_at=datetime(2020, 4, 9, 23, 30), job_status='finished')
create_notification(template=job.template, job=job, status='created', created_at=datetime(2020, 4, 9, 23, 32))
with freeze_time('2020-04-10 10:00'):
result, errors = can_letter_job_be_cancelled(job)
assert not errors
assert result
def test_find_jobs_with_missing_rows(sample_email_template): def test_find_jobs_with_missing_rows(sample_email_template):
healthy_job = create_job(template=sample_email_template, healthy_job = create_job(template=sample_email_template,
notification_count=3, notification_count=3,

View File

@@ -3350,12 +3350,18 @@ def test_cancel_notification_for_service_raises_error_if_its_too_late_to_cancel(
assert response['result'] == 'error' assert response['result'] == 'error'
@pytest.mark.parametrize('created_at', [
datetime(2018, 7, 6, 22, 30), # yesterday evening
datetime(2018, 7, 6, 23, 30), # this morning early hours (in bst)
datetime(2018, 7, 7, 10, 0), # this morning normal hours
])
@freeze_time('2018-7-7 16:00:00') @freeze_time('2018-7-7 16:00:00')
def test_cancel_notification_for_service_updates_letter_if_still_time_to_cancel( def test_cancel_notification_for_service_updates_letter_if_still_time_to_cancel(
admin_request, admin_request,
sample_letter_notification, sample_letter_notification,
created_at,
): ):
sample_letter_notification.created_at = datetime(2018, 7, 7, 10, 0) sample_letter_notification.created_at = created_at
response = admin_request.post( response = admin_request.post(
'service.cancel_notification_for_service', 'service.cancel_notification_for_service',