mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-25 18:39:11 -04:00
- wrap apply_async parameter notification_id in a str() argument
- check if service_callback_api exist before putting tasks on queue - create_service_callback_api in tests before asserting if send_delivery_status_to_service has been called.
This commit is contained in:
@@ -21,7 +21,7 @@ from app.celery.tasks import (
|
||||
update_letter_notifications_to_sent_to_dvla
|
||||
)
|
||||
|
||||
from tests.app.db import create_notification
|
||||
from tests.app.db import create_notification, create_service_callback_api
|
||||
from tests.conftest import set_config
|
||||
|
||||
|
||||
@@ -97,10 +97,11 @@ def test_update_letter_notifications_statuses_persisted(notify_api, mocker, samp
|
||||
billable_units=0)
|
||||
failed_letter = create_notification(sample_letter_template, reference='ref-bar', status=NOTIFICATION_SENDING,
|
||||
billable_units=0)
|
||||
|
||||
create_service_callback_api(service=sample_letter_template.service, url="https://original_url.com")
|
||||
valid_file = '{}|Sent|1|Unsorted\n{}|Failed|2|Sorted'.format(
|
||||
sent_letter.reference, failed_letter.reference)
|
||||
mocker.patch('app.celery.tasks.s3.get_s3_file', return_value=valid_file)
|
||||
|
||||
send_mock = mocker.patch(
|
||||
'app.celery.service_callback_tasks.send_delivery_status_to_service.apply_async'
|
||||
)
|
||||
@@ -144,7 +145,7 @@ def test_update_letter_notifications_to_error_updates_based_on_notification_refe
|
||||
)
|
||||
first = create_notification(sample_letter_template, reference='first ref')
|
||||
second = create_notification(sample_letter_template, reference='second ref')
|
||||
|
||||
create_service_callback_api(service=sample_letter_template.service, url="https://original_url.com")
|
||||
dt = datetime.utcnow()
|
||||
with freeze_time(dt):
|
||||
update_letter_notifications_to_error([first.reference])
|
||||
|
||||
@@ -30,7 +30,7 @@ from app.dao.notifications_dao import (
|
||||
set_scheduled_notification_to_processed,
|
||||
update_notification_status_by_id,
|
||||
update_notification_status_by_reference,
|
||||
dao_get_notifications_by_reference
|
||||
dao_get_notifications_by_references
|
||||
)
|
||||
from app.dao.services_dao import dao_update_service
|
||||
from app.models import (
|
||||
@@ -1997,7 +1997,7 @@ def test_dao_get_notifications_by_reference(sample_template):
|
||||
notification_1 = create_notification(template=sample_template, reference='ref')
|
||||
notification_2 = create_notification(template=sample_template, reference='ref')
|
||||
|
||||
notifications = dao_get_notifications_by_reference(['ref'])
|
||||
notifications = dao_get_notifications_by_references(['ref'])
|
||||
assert len(notifications) == 2
|
||||
assert notifications[0].id in [notification_1.id, notification_2.id]
|
||||
assert notifications[1].id in [notification_1.id, notification_2.id]
|
||||
|
||||
@@ -10,6 +10,7 @@ from app.dao.notifications_dao import (
|
||||
get_notification_by_id
|
||||
)
|
||||
from tests.app.conftest import sample_notification as create_sample_notification
|
||||
from tests.app.db import create_service_callback_api
|
||||
|
||||
|
||||
def firetext_post(client, data):
|
||||
@@ -377,7 +378,7 @@ def test_process_mmg_response_unknown_status_updates_notification_with_failed(
|
||||
"CID": str(notification.id),
|
||||
"MSISDN": "447777349060",
|
||||
"status": 10})
|
||||
|
||||
create_service_callback_api(service=notification.service, url="https://original_url.com")
|
||||
response = mmg_post(client, data)
|
||||
assert response.status_code == 200
|
||||
json_data = json.loads(response.data)
|
||||
|
||||
@@ -10,6 +10,7 @@ from app.notifications.notifications_ses_callback import process_ses_response, r
|
||||
from app.celery.research_mode_tasks import ses_hard_bounce_callback, ses_soft_bounce_callback, ses_notification_callback
|
||||
|
||||
from tests.app.conftest import sample_notification as create_sample_notification
|
||||
from tests.app.db import create_service_callback_api
|
||||
|
||||
|
||||
def test_ses_callback_should_update_notification_status(
|
||||
@@ -35,7 +36,7 @@ def test_ses_callback_should_update_notification_status(
|
||||
status='sending',
|
||||
sent_at=datetime.utcnow()
|
||||
)
|
||||
|
||||
create_service_callback_api(service=sample_email_template.service, url="https://original_url.com")
|
||||
assert get_notification_by_id(notification.id).status == 'sending'
|
||||
|
||||
errors = process_ses_response(ses_notification_callback(reference='ref'))
|
||||
@@ -46,7 +47,7 @@ def test_ses_callback_should_update_notification_status(
|
||||
)
|
||||
statsd_client.incr.assert_any_call("callback.ses.delivered")
|
||||
stats_mock.assert_called_once_with(notification)
|
||||
send_mock.assert_called_once_with([notification.id], queue="notify-internal-tasks")
|
||||
send_mock.assert_called_once_with([str(notification.id)], queue="notify-internal-tasks")
|
||||
|
||||
|
||||
def test_ses_callback_should_update_multiple_notification_status_sent(
|
||||
@@ -85,7 +86,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent(
|
||||
reference='ref3',
|
||||
sent_at=datetime.utcnow(),
|
||||
status='sending')
|
||||
|
||||
create_service_callback_api(service=sample_email_template.service, url="https://original_url.com")
|
||||
assert process_ses_response(ses_notification_callback(reference='ref1')) is None
|
||||
assert process_ses_response(ses_notification_callback(reference='ref2')) is None
|
||||
assert process_ses_response(ses_notification_callback(reference='ref3')) is None
|
||||
@@ -118,6 +119,7 @@ def test_ses_callback_should_set_status_to_temporary_failure(client,
|
||||
status='sending',
|
||||
sent_at=datetime.utcnow()
|
||||
)
|
||||
create_service_callback_api(service=notification.service, url="https://original_url.com")
|
||||
assert get_notification_by_id(notification.id).status == 'sending'
|
||||
assert process_ses_response(ses_soft_bounce_callback(reference='ref')) is None
|
||||
assert get_notification_by_id(notification.id).status == 'temporary-failure'
|
||||
@@ -166,6 +168,7 @@ def test_ses_callback_should_set_status_to_permanent_failure(client,
|
||||
status='sending',
|
||||
sent_at=datetime.utcnow()
|
||||
)
|
||||
create_service_callback_api(service=sample_email_template.service, url="https://original_url.com")
|
||||
|
||||
assert get_notification_by_id(notification.id).status == 'sending'
|
||||
assert process_ses_response(ses_hard_bounce_callback(reference='ref')) is None
|
||||
|
||||
@@ -4,6 +4,7 @@ from app.notifications.process_client_response import (
|
||||
validate_callback_data,
|
||||
process_sms_client_response
|
||||
)
|
||||
from tests.app.db import create_service_callback_api
|
||||
|
||||
|
||||
def test_validate_callback_data_returns_none_when_valid():
|
||||
@@ -54,6 +55,7 @@ def test_outcome_statistics_called_for_successful_callback(sample_notification,
|
||||
send_mock = mocker.patch(
|
||||
'app.celery.service_callback_tasks.send_delivery_status_to_service.apply_async'
|
||||
)
|
||||
create_service_callback_api(service=sample_notification.service, url="https://original_url.com")
|
||||
reference = str(uuid.uuid4())
|
||||
|
||||
success, error = process_sms_client_response(status='3', reference=reference, client_name='MMG')
|
||||
|
||||
Reference in New Issue
Block a user