|
42 | 42 |
|
43 | 43 | OBLIGATION_DUE_EMAIL_PATH = 'compliance.tasks.retryable_send_notice_of_obligation_due_email' |
44 | 44 |
|
| 45 | +PAST_DEADLINE_EMAIL_PATH = 'compliance.tasks.retryable_notice_of_supplementary_report_post_deadline_increases_emissions' |
| 46 | + |
45 | 47 | SYNC_WITH_ELICENSING_PATH = ( |
46 | 48 | f"{ELICENSING_OBLIGATION_SERVICE_PATH}.ElicensingOperatorService.sync_client_with_elicensing" |
47 | 49 | ) |
@@ -133,6 +135,12 @@ def mock_retryable_obligation_due_email(): |
133 | 135 | yield mock |
134 | 136 |
|
135 | 137 |
|
| 138 | +@pytest.fixture |
| 139 | +def mock_retryable_notice_of_supplementary_report_post_deadline_increases_emissions(): |
| 140 | + with patch(PAST_DEADLINE_EMAIL_PATH) as mock: |
| 141 | + yield mock |
| 142 | + |
| 143 | + |
136 | 144 | @pytest.fixture |
137 | 145 | def mock_update_status(): |
138 | 146 | with patch(UPDATE_COMPLIANCE_STATUS_PATH) as mock: |
@@ -257,17 +265,19 @@ def test_map_obligation_to_invoice_data(self, mock_obligation: MagicMock) -> Non |
257 | 265 | assert result["businessAreaCode"] == "OBPS" |
258 | 266 | assert result["fees"] == [fee_id] |
259 | 267 |
|
260 | | - def test_process_obligation_integration_success( |
| 268 | + def test_process_obligation_integration_success_before_deadline( |
261 | 269 | self, |
262 | 270 | mock_update_status, |
263 | 271 | mock_refresh_by_invoice, |
264 | 272 | mock_create_invoice, |
265 | 273 | mock_create_fees, |
266 | 274 | mock_retryable_obligation_due_email, |
| 275 | + mock_retryable_notice_of_supplementary_report_post_deadline_increases_emissions, |
| 276 | + mock_timezone, |
267 | 277 | ) -> None: |
268 | 278 | """Test successful full obligation integration process""" |
269 | 279 | # Setup mocks |
270 | | - |
| 280 | + self._set_vancouver_today(mock_timezone, date(2025, 11, 30)) |
271 | 281 | obligation = make_recipe('compliance.tests.utils.compliance_obligation') |
272 | 282 | client_operator = make_recipe( |
273 | 283 | 'compliance.tests.utils.elicensing_client_operator', |
@@ -301,6 +311,63 @@ def test_process_obligation_integration_success( |
301 | 311 |
|
302 | 312 | mock_update_status.assert_called_once_with(obligation.compliance_report_version) |
303 | 313 | mock_retryable_obligation_due_email.execute.assert_called_once_with(obligation.pk) |
| 314 | + mock_retryable_notice_of_supplementary_report_post_deadline_increases_emissions.execute.assert_not_called() |
| 315 | + |
| 316 | + def test_process_obligation_integration_success_after_deadline( |
| 317 | + self, |
| 318 | + mock_update_status, |
| 319 | + mock_refresh_by_invoice, |
| 320 | + mock_create_invoice, |
| 321 | + mock_create_fees, |
| 322 | + mock_retryable_obligation_due_email, |
| 323 | + mock_retryable_notice_of_supplementary_report_post_deadline_increases_emissions, |
| 324 | + mock_timezone, |
| 325 | + ) -> None: |
| 326 | + """Test successful full obligation integration process if a supplmentary report has been submitted after the deadline.""" |
| 327 | + # Setup mocks |
| 328 | + self._set_vancouver_today(mock_timezone, date(2025, 12, 1)) |
| 329 | + |
| 330 | + obligation = make_recipe('compliance.tests.utils.compliance_obligation') |
| 331 | + compliance_report_version = obligation.compliance_report_version |
| 332 | + compliance_report_version.is_supplementary = True |
| 333 | + compliance_report_version.save() |
| 334 | + |
| 335 | + client_operator = make_recipe( |
| 336 | + 'compliance.tests.utils.elicensing_client_operator', |
| 337 | + operator_id=obligation.compliance_report_version.compliance_report.report.operator_id, |
| 338 | + ) |
| 339 | + |
| 340 | + # Setup API responses |
| 341 | + mock_fee_response = FeeResponse( |
| 342 | + clientObjectId=client_operator.client_object_id, |
| 343 | + clientGUID=client_operator.client_guid, |
| 344 | + fees=[FeeItem(feeGUID=str(uuid.uuid4()), feeObjectId="1")], |
| 345 | + ) |
| 346 | + |
| 347 | + mock_create_fees.return_value = mock_fee_response |
| 348 | + |
| 349 | + mock_invoice_response = TestInvoiceResponse(invoiceNumber='inv-001') |
| 350 | + mock_create_invoice.return_value = mock_invoice_response |
| 351 | + |
| 352 | + mock_refresh_by_invoice.return_value = None |
| 353 | + mock_update_status.return_value = None |
| 354 | + |
| 355 | + invoice = make_recipe('compliance.tests.utils.elicensing_invoice', invoice_number='inv-001') |
| 356 | + |
| 357 | + # Call the method |
| 358 | + ElicensingObligationService.process_obligation_integration(obligation.id) |
| 359 | + |
| 360 | + obligation.refresh_from_db() |
| 361 | + |
| 362 | + # Invoice has been assigned to obligation |
| 363 | + assert obligation.elicensing_invoice_id == invoice.id |
| 364 | + |
| 365 | + mock_update_status.assert_called_once_with(obligation.compliance_report_version) |
| 366 | + # brianna |
| 367 | + mock_retryable_obligation_due_email.execute.assert_not_called() |
| 368 | + mock_retryable_notice_of_supplementary_report_post_deadline_increases_emissions.execute.assert_called_once_with( |
| 369 | + obligation.pk |
| 370 | + ) |
304 | 371 |
|
305 | 372 | def test_process_obligation_integration_failure_sets_pending_status_and_does_not_email( |
306 | 373 | self, mock_sync_client, mock_create_fees, mock_retryable_obligation_due_email |
|
0 commit comments