mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 05:58:53 -04:00
Merge pull request #2075 from alphagov/process-returned-letters-list
Process returned letters list
This commit is contained in:
@@ -27,6 +27,7 @@ from app.celery.tasks import (
|
||||
get_template_class,
|
||||
s3,
|
||||
send_inbound_sms_to_service,
|
||||
process_returned_letters_list,
|
||||
)
|
||||
from app.config import QueueNames
|
||||
from app.dao import jobs_dao, services_dao
|
||||
@@ -1551,3 +1552,14 @@ def test_process_incomplete_jobs_sets_status_to_in_progress_and_resets_processin
|
||||
assert job2.processing_started == datetime.utcnow()
|
||||
|
||||
assert mock_process_incomplete_job.mock_calls == [call(str(job1.id)), call(str(job2.id))]
|
||||
|
||||
|
||||
def test_process_returned_letters_list(mocker, sample_letter_template):
|
||||
create_notification(sample_letter_template, reference='ref1')
|
||||
create_notification(sample_letter_template, reference='ref2')
|
||||
|
||||
process_returned_letters_list(['ref1', 'ref2', 'unknown-ref'])
|
||||
|
||||
assert [
|
||||
n.status for n in Notification.query.all()
|
||||
] == ['returned-letter', 'returned-letter']
|
||||
|
||||
@@ -1653,10 +1653,13 @@ def test_dao_update_notifications_by_reference_updated_notificaitons_and_history
|
||||
notification_1 = create_notification(template=sample_template, reference='ref')
|
||||
notification_2 = create_notification(template=sample_template, reference='ref')
|
||||
|
||||
updated_count = dao_update_notifications_by_reference(references=['ref'],
|
||||
update_dict={"status": "delivered",
|
||||
"billable_units": 2}
|
||||
)
|
||||
updated_count, updated_history_count = dao_update_notifications_by_reference(
|
||||
references=['ref'],
|
||||
update_dict={
|
||||
"status": "delivered",
|
||||
"billable_units": 2
|
||||
}
|
||||
)
|
||||
assert updated_count == 2
|
||||
updated_1 = Notification.query.get(notification_1.id)
|
||||
assert updated_1.billable_units == 2
|
||||
@@ -1665,6 +1668,7 @@ def test_dao_update_notifications_by_reference_updated_notificaitons_and_history
|
||||
assert updated_2.billable_units == 2
|
||||
assert updated_2.status == 'delivered'
|
||||
|
||||
assert updated_history_count == 2
|
||||
updated_history_1 = NotificationHistory.query.get(notification_1.id)
|
||||
assert updated_history_1.billable_units == 2
|
||||
assert updated_history_1.status == 'delivered'
|
||||
@@ -1676,11 +1680,29 @@ def test_dao_update_notifications_by_reference_updated_notificaitons_and_history
|
||||
|
||||
|
||||
def test_dao_update_notifications_by_reference_returns_zero_when_no_notifications_to_update(notify_db):
|
||||
updated_count = dao_update_notifications_by_reference(references=['ref'],
|
||||
update_dict={"status": "delivered",
|
||||
"billable_units": 2}
|
||||
)
|
||||
updated_count, updated_history_count = dao_update_notifications_by_reference(
|
||||
references=['ref'],
|
||||
update_dict={
|
||||
"status": "delivered",
|
||||
"billable_units": 2
|
||||
}
|
||||
)
|
||||
|
||||
assert updated_count == 0
|
||||
assert updated_history_count == 0
|
||||
|
||||
|
||||
def test_dao_update_notifications_by_reference_set_returned_letter_status(sample_letter_template):
|
||||
notification = create_notification(template=sample_letter_template, reference='ref')
|
||||
|
||||
updated_count, updated_history_count = dao_update_notifications_by_reference(
|
||||
references=['ref'],
|
||||
update_dict={"status": "returned-letter"}
|
||||
)
|
||||
|
||||
assert updated_count == 1
|
||||
assert updated_history_count == 1
|
||||
assert Notification.query.get(notification.id).status == 'returned-letter'
|
||||
|
||||
|
||||
def test_dao_get_notification_by_reference_with_one_match_returns_notification(sample_letter_template, notify_db):
|
||||
|
||||
23
tests/app/letters/test_returned_letters.py
Normal file
23
tests/app/letters/test_returned_letters.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize('status, references', [
|
||||
(200, ["1234567890ABCDEF", "1234567890ABCDEG"]),
|
||||
(400, ["1234567890ABCDEFG", "1234567890ABCDEG"]),
|
||||
(400, ["1234567890ABCDE", "1234567890ABCDEG"]),
|
||||
(400, ["1234567890ABCDE\u26d4", "1234567890ABCDEG"]),
|
||||
(400, ["NOTIFY0001234567890ABCDEF", "1234567890ABCDEG"]),
|
||||
])
|
||||
def test_process_returned_letters(status, references, admin_request, mocker):
|
||||
mock_celery = mocker.patch("app.letters.rest.process_returned_letters_list.apply_async")
|
||||
|
||||
response = admin_request.post(
|
||||
'letter-job.create_process_returned_letters_job',
|
||||
_data={"references": references},
|
||||
_expected_status=status
|
||||
)
|
||||
|
||||
if status != 200:
|
||||
assert '{} does not match'.format(references[0]) in response['errors'][0]['message']
|
||||
else:
|
||||
mock_celery.assert_called_once_with([references], queue='database-tasks')
|
||||
@@ -443,7 +443,7 @@ def test_get_all_notifications_filter_by_status_invalid_status(client, sample_no
|
||||
assert len(json_response['errors']) == 1
|
||||
assert json_response['errors'][0]['message'] == "status elephant is not one of [cancelled, created, sending, " \
|
||||
"sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, " \
|
||||
"pending-virus-check, virus-scan-failed, accepted, received]"
|
||||
"pending-virus-check, virus-scan-failed, returned-letter, accepted, received]"
|
||||
|
||||
|
||||
def test_get_all_notifications_filter_by_multiple_statuses(client, sample_template):
|
||||
|
||||
@@ -44,7 +44,7 @@ def test_get_notifications_request_invalid_statuses(
|
||||
partial_error_status = "is not one of " \
|
||||
"[cancelled, created, sending, sent, delivered, pending, failed, " \
|
||||
"technical-failure, temporary-failure, permanent-failure, pending-virus-check, " \
|
||||
"virus-scan-failed, accepted, received]"
|
||||
"virus-scan-failed, returned-letter, accepted, received]"
|
||||
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate({'status': invalid_statuses + valid_statuses}, get_notifications_request)
|
||||
@@ -92,7 +92,7 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
|
||||
for invalid_status in ["elephant", "giraffe"]:
|
||||
assert "status {} is not one of [cancelled, created, sending, sent, delivered, " \
|
||||
"pending, failed, technical-failure, temporary-failure, permanent-failure, " \
|
||||
"pending-virus-check, virus-scan-failed, accepted, received]".format(
|
||||
"pending-virus-check, virus-scan-failed, returned-letter, accepted, received]".format(
|
||||
invalid_status
|
||||
) in error_messages
|
||||
|
||||
|
||||
Reference in New Issue
Block a user