5555 create_notification ,
5656 create_service ,
5757)
58+ from tests .conftest import _with_message_group_id
5859
5960
6061def test_should_have_decorated_tasks_functions ():
@@ -75,7 +76,8 @@ def test_get_pdf_for_templated_letter_happy_path(mocker, sample_letter_notificat
7576 mock_generate_letter_pdf_filename = mocker .patch (
7677 "app.celery.letters_pdf_tasks.generate_letter_pdf_filename" , return_value = "LETTER.PDF"
7778 )
78- get_pdf_for_templated_letter (sample_letter_notification .id )
79+ with _with_message_group_id (get_pdf_for_templated_letter , str (sample_letter_notification .service_id )):
80+ get_pdf_for_templated_letter (sample_letter_notification .id )
7981
8082 letter_data = {
8183 "letter_contact_block" : sample_letter_notification .reply_to_text ,
@@ -97,7 +99,10 @@ def test_get_pdf_for_templated_letter_happy_path(mocker, sample_letter_notificat
9799 }
98100
99101 mock_celery .assert_called_once_with (
100- name = TaskNames .CREATE_PDF_FOR_TEMPLATED_LETTER , args = (ANY ,), queue = QueueNames .SANITISE_LETTERS
102+ name = TaskNames .CREATE_PDF_FOR_TEMPLATED_LETTER ,
103+ args = (ANY ,),
104+ queue = QueueNames .SANITISE_LETTERS ,
105+ MessageGroupId = str (sample_letter_notification .service_id ),
101106 )
102107
103108 actual_data = signing .decode (mock_celery .call_args .kwargs ["args" ][0 ])
@@ -117,7 +122,8 @@ def test_get_pdf_for_templated_letter_with_letter_attachment(mocker, sample_lett
117122
118123 mock_celery = mocker .patch ("app.celery.letters_pdf_tasks.notify_celery.send_task" )
119124 mocker .patch ("app.celery.letters_pdf_tasks.generate_letter_pdf_filename" , return_value = "LETTER.PDF" )
120- get_pdf_for_templated_letter (sample_letter_notification .id )
125+ with _with_message_group_id (get_pdf_for_templated_letter , str (sample_letter_notification .service_id )):
126+ get_pdf_for_templated_letter (sample_letter_notification .id )
121127
122128 actual_data = signing .decode (mock_celery .call_args .kwargs ["args" ][0 ])
123129
@@ -134,8 +140,9 @@ def test_get_pdf_for_templated_letter_retries_upon_error(mocker, sample_letter_n
134140 mocker .patch ("app.celery.letters_pdf_tasks.generate_letter_pdf_filename" , return_value = "LETTER.PDF" )
135141 mock_retry = mocker .patch ("app.celery.letters_pdf_tasks.get_pdf_for_templated_letter.retry" )
136142
137- with caplog .at_level ("ERROR" ):
138- get_pdf_for_templated_letter (sample_letter_notification .id )
143+ with _with_message_group_id (get_pdf_for_templated_letter , str (sample_letter_notification .service_id )):
144+ with caplog .at_level ("ERROR" ):
145+ get_pdf_for_templated_letter (sample_letter_notification .id )
139146
140147 assert mock_celery .called
141148 assert mock_retry .called
@@ -153,8 +160,9 @@ def test_get_pdf_for_templated_letter_sets_technical_failure_max_retries(mocker,
153160 )
154161 mock_update_noti = mocker .patch ("app.celery.letters_pdf_tasks.update_notification_status_by_id" )
155162
156- with pytest .raises (NotificationTechnicalFailureException ) as e :
157- get_pdf_for_templated_letter (sample_letter_notification .id )
163+ with _with_message_group_id (get_pdf_for_templated_letter , str (sample_letter_notification .service_id )):
164+ with pytest .raises (NotificationTechnicalFailureException ) as e :
165+ get_pdf_for_templated_letter (sample_letter_notification .id )
158166
159167 assert (
160168 e .value .args [0 ] == f"RETRY FAILED: Max retries reached. "
@@ -390,9 +398,17 @@ def test_send_letters_volume_email_to_dvla(notify_db_session, mock_celery_task,
390398
391399 emails_to_dvla = Notification .query .all ()
392400 assert len (emails_to_dvla ) == 2
393- send_mock .called = 2
394- send_mock .assert_any_call ([str (emails_to_dvla [0 ].id )], queue = QueueNames .NOTIFY )
395- send_mock .assert_any_call ([str (emails_to_dvla [1 ].id )], queue = QueueNames .NOTIFY )
401+ assert send_mock .call_count == 2
402+ send_mock .assert_any_call (
403+ [str (emails_to_dvla [0 ].id )],
404+ queue = QueueNames .NOTIFY ,
405+ MessageGroupId = str (emails_to_dvla [0 ].service_id ),
406+ )
407+ send_mock .assert_any_call (
408+ [str (emails_to_dvla [1 ].id )],
409+ queue = QueueNames .NOTIFY ,
410+ MessageGroupId = str (emails_to_dvla [1 ].service_id ),
411+ )
396412 for email in emails_to_dvla :
397413 assert str (email .template_id ) == current_app .config ["LETTERS_VOLUME_EMAIL_TEMPLATE_ID" ]
398414 assert email .to in current_app .config ["DVLA_EMAIL_ADDRESSES" ]
@@ -451,7 +467,8 @@ def test_sanitise_letter_calls_template_preview_sanitise_task(
451467 sample_letter_notification .service = create_service (service_permissions = permissions )
452468 sample_letter_notification .status = NOTIFICATION_PENDING_VIRUS_CHECK
453469
454- sanitise_letter (filename )
470+ with _with_message_group_id (sanitise_letter , str (sample_letter_notification .service_id )):
471+ sanitise_letter (filename )
455472
456473 mock_celery .assert_called_once_with (
457474 name = TaskNames .SANITISE_LETTER ,
@@ -461,6 +478,7 @@ def test_sanitise_letter_calls_template_preview_sanitise_task(
461478 "allow_international_letters" : expected_international_letters_allowed ,
462479 },
463480 queue = QueueNames .SANITISE_LETTERS ,
481+ MessageGroupId = str (sample_letter_notification .service_id ),
464482 )
465483
466484
@@ -881,7 +899,8 @@ def test_resanitise_pdf_calls_template_preview_with_letter_details(
881899 sample_letter_notification .created_at = datetime (2021 , 2 , 7 , 12 )
882900 sample_letter_notification .service = create_service (service_permissions = permissions )
883901
884- resanitise_pdf (sample_letter_notification .id )
902+ with _with_message_group_id (resanitise_pdf , str (sample_letter_notification .service_id )):
903+ resanitise_pdf (sample_letter_notification .id )
885904
886905 mock_celery .assert_called_once_with (
887906 name = TaskNames .RECREATE_PDF_FOR_PRECOMPILED_LETTER ,
@@ -904,7 +923,8 @@ def test_resanitise_letter_attachment_calls_template_preview_with_attachment_det
904923 attachment_id = str (uuid .uuid4 ())
905924 original_filename = "test-123abc.pdf"
906925
907- resanitise_letter_attachment (service_id , attachment_id , original_filename )
926+ with _with_message_group_id (resanitise_letter_attachment , service_id ):
927+ resanitise_letter_attachment (service_id , attachment_id , original_filename )
908928
909929 mock_celery .assert_called_once_with (
910930 name = TaskNames .RECREATE_PDF_FOR_TEMPLATE_LETTER_ATTACHMENTS ,
@@ -914,4 +934,5 @@ def test_resanitise_letter_attachment_calls_template_preview_with_attachment_det
914934 "original_filename" : original_filename ,
915935 },
916936 queue = QueueNames .SANITISE_LETTERS ,
937+ MessageGroupId = service_id ,
917938 )
0 commit comments