4
4
from freezegun import freeze_time
5
5
6
6
from app import statsd_client
7
- from app .aws .mocks import pinpoint_failed_callback , pinpoint_success_callback
7
+ from app .aws .mocks import (
8
+ pinpoint_delivered_callback ,
9
+ pinpoint_failed_callback ,
10
+ pinpoint_successful_callback ,
11
+ )
8
12
from app .celery .process_pinpoint_receipts_tasks import process_pinpoint_results
9
13
from app .dao .notifications_dao import get_notification_by_id
10
14
from app .models import (
@@ -39,7 +43,7 @@ def test_process_pinpoint_results_delivered(sample_template, notify_db, notify_d
39
43
)
40
44
assert get_notification_by_id (notification .id ).status == NOTIFICATION_SENT
41
45
42
- process_pinpoint_results (pinpoint_success_callback (reference = "ref" ))
46
+ process_pinpoint_results (pinpoint_delivered_callback (reference = "ref" ))
43
47
44
48
assert mock_callback_task .called_once_with (get_notification_by_id (notification .id ))
45
49
assert get_notification_by_id (notification .id ).status == NOTIFICATION_DELIVERED
@@ -48,6 +52,27 @@ def test_process_pinpoint_results_delivered(sample_template, notify_db, notify_d
48
52
mock_logger .assert_called_once_with (f"Pinpoint callback return status of delivered for notification: { notification .id } " )
49
53
50
54
55
+ def test_process_pinpoint_results_succeeded (sample_template , notify_db , notify_db_session , mocker ):
56
+ mock_callback_task = mocker .patch ("app.notifications.callbacks._check_and_queue_callback_task" )
57
+
58
+ notification = create_sample_notification (
59
+ notify_db ,
60
+ notify_db_session ,
61
+ template = sample_template ,
62
+ reference = "ref" ,
63
+ status = NOTIFICATION_SENT ,
64
+ sent_by = "pinpoint" ,
65
+ sent_at = datetime .utcnow (),
66
+ )
67
+ assert get_notification_by_id (notification .id ).status == NOTIFICATION_SENT
68
+
69
+ process_pinpoint_results (pinpoint_successful_callback (reference = "ref" ))
70
+
71
+ assert mock_callback_task .not_called ()
72
+ assert get_notification_by_id (notification .id ).status == NOTIFICATION_SENT
73
+ assert get_notification_by_id (notification .id ).provider_response is None
74
+
75
+
51
76
@pytest .mark .parametrize (
52
77
"provider_response, expected_status, should_log_warning, should_save_provider_response" ,
53
78
[
@@ -120,7 +145,7 @@ def test_pinpoint_callback_should_retry_if_notification_is_missing(notify_db, mo
120
145
mock_retry = mocker .patch ("app.celery.process_pinpoint_receipts_tasks.process_pinpoint_results.retry" )
121
146
mock_callback_task = mocker .patch ("app.notifications.callbacks._check_and_queue_callback_task" )
122
147
123
- process_pinpoint_results (pinpoint_success_callback (reference = "ref" ))
148
+ process_pinpoint_results (pinpoint_delivered_callback (reference = "ref" ))
124
149
125
150
mock_callback_task .assert_not_called ()
126
151
assert mock_retry .call_count == 1
@@ -134,7 +159,7 @@ def test_pinpoint_callback_should_give_up_after_max_tries(notify_db, mocker):
134
159
mock_logger = mocker .patch ("app.celery.process_pinpoint_receipts_tasks.current_app.logger.warning" )
135
160
mock_callback_task = mocker .patch ("app.notifications.callbacks._check_and_queue_callback_task" )
136
161
137
- process_pinpoint_results (pinpoint_success_callback (reference = "ref" )) is None
162
+ process_pinpoint_results (pinpoint_delivered_callback (reference = "ref" )) is None
138
163
mock_callback_task .assert_not_called ()
139
164
140
165
mock_logger .assert_called_with ("notification not found for Pinpoint reference: ref (update to delivered). Giving up." )
@@ -156,7 +181,7 @@ def test_process_pinpoint_results_retry_called(sample_template, mocker):
156
181
side_effect = Exception ("EXPECTED" ),
157
182
)
158
183
mocked = mocker .patch ("app.celery.process_pinpoint_receipts_tasks.process_pinpoint_results.retry" )
159
- process_pinpoint_results (response = pinpoint_success_callback (reference = "ref1" ))
184
+ process_pinpoint_results (response = pinpoint_delivered_callback (reference = "ref1" ))
160
185
assert mocked .call_count == 1
161
186
162
187
@@ -173,7 +198,7 @@ def test_process_pinpoint_results_does_not_process_other_providers(sample_templa
173
198
)
174
199
)
175
200
176
- process_pinpoint_results (response = pinpoint_success_callback (reference = "ref1" )) is None
201
+ process_pinpoint_results (response = pinpoint_delivered_callback (reference = "ref1" )) is None
177
202
assert mock_logger .called_once_with ("" )
178
203
assert not mock_dao .called
179
204
@@ -197,7 +222,7 @@ def test_process_pinpoint_results_calls_service_callback(sample_template, notify
197
222
callback_api = create_service_callback_api (service = sample_template .service , url = "https://example.com" )
198
223
assert get_notification_by_id (notification .id ).status == NOTIFICATION_SENT
199
224
200
- process_pinpoint_results (pinpoint_success_callback (reference = "ref" ))
225
+ process_pinpoint_results (pinpoint_delivered_callback (reference = "ref" ))
201
226
202
227
assert mock_callback .called_once_with (get_notification_by_id (notification .id ))
203
228
assert get_notification_by_id (notification .id ).status == NOTIFICATION_DELIVERED
0 commit comments