|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | from botocore.exceptions import ClientError |
| 5 | +from enums.feature_flags import FeatureFlags |
5 | 6 | from enums.patient_ods_inactive_status import PatientOdsInactiveStatus |
6 | 7 | from models.document_reference import DocumentReference |
7 | 8 | from models.document_review import DocumentUploadReviewReference |
8 | 9 | from models.sqs.mns_sqs_message import MNSSQSMessage |
| 10 | +from services.feature_flags_service import FeatureFlagService |
9 | 11 | from services.process_mns_message_service import MNSNotificationService |
10 | 12 | from tests.unit.conftest import TEST_CURRENT_GP_ODS, TEST_NHS_NUMBER |
11 | 13 | from tests.unit.handlers.test_mns_notification_handler import ( |
|
18 | 20 |
|
19 | 21 |
|
20 | 22 | @pytest.fixture |
21 | | -def mns_service(mocker, set_env, monkeypatch): |
| 23 | +def mns_service(mocker, set_env, monkeypatch, mock_upload_document_iteration_3_enabled): |
| 24 | + monkeypatch.setenv("PDS_FHIR_IS_STUBBED", "False") |
| 25 | + service = MNSNotificationService() |
| 26 | + mocker.patch.object(service, "pds_service") |
| 27 | + mocker.patch.object(service, "document_review_service") |
| 28 | + mocker.patch.object(service, "lg_document_service") |
| 29 | + mocker.patch.object(service, "sqs_service") |
| 30 | + yield service |
| 31 | + |
| 32 | + |
| 33 | +@pytest.fixture |
| 34 | +def mns_service_feature_disabled( |
| 35 | + mocker, set_env, monkeypatch, mock_upload_document_iteration_3_disabled |
| 36 | +): |
22 | 37 | monkeypatch.setenv("PDS_FHIR_IS_STUBBED", "False") |
23 | 38 | service = MNSNotificationService() |
24 | 39 | mocker.patch.object(service, "pds_service") |
@@ -69,6 +84,24 @@ def mock_document_review_references(mocker): |
69 | 84 | return reviews |
70 | 85 |
|
71 | 86 |
|
| 87 | +@pytest.fixture |
| 88 | +def mock_upload_document_iteration_3_enabled(mocker): |
| 89 | + mock_function = mocker.patch.object(FeatureFlagService, "get_feature_flags_by_flag") |
| 90 | + mock_feature_flag = mock_function.return_value = { |
| 91 | + FeatureFlags.UPLOAD_DOCUMENT_ITERATION_3_ENABLED: True |
| 92 | + } |
| 93 | + yield mock_feature_flag |
| 94 | + |
| 95 | + |
| 96 | +@pytest.fixture |
| 97 | +def mock_upload_document_iteration_3_disabled(mocker): |
| 98 | + mock_function = mocker.patch.object(FeatureFlagService, "get_feature_flags_by_flag") |
| 99 | + mock_feature_flag = mock_function.return_value = { |
| 100 | + FeatureFlags.UPLOAD_DOCUMENT_ITERATION_3_ENABLED: False |
| 101 | + } |
| 102 | + yield mock_feature_flag |
| 103 | + |
| 104 | + |
72 | 105 | MOCK_UPDATE_TIME = "2024-01-01 12:00:00" |
73 | 106 | NEW_ODS_CODE = "NEW123" |
74 | 107 |
|
@@ -249,7 +282,6 @@ def test_handle_death_notification_formal_no_documents(mns_service, mocker): |
249 | 282 | mns_service.update_all_patient_documents.assert_not_called() |
250 | 283 |
|
251 | 284 |
|
252 | | - |
253 | 285 | def test_get_updated_gp_ods(mns_service): |
254 | 286 | expected_ods = NEW_ODS_CODE |
255 | 287 | patient_details_mock = MagicMock() |
@@ -343,7 +375,6 @@ def test_update_all_patient_documents_with_only_review_documents( |
343 | 375 | ) |
344 | 376 |
|
345 | 377 |
|
346 | | - |
347 | 378 | def test_handle_gp_change_notification_with_only_lg_documents( |
348 | 379 | mns_service, mock_document_references, mocker |
349 | 380 | ): |
@@ -496,3 +527,93 @@ def test_handle_death_notification_removed_with_only_review_documents( |
496 | 527 | mns_service.update_all_patient_documents.assert_called_once_with( |
497 | 528 | [], mock_document_review_references, NEW_ODS_CODE |
498 | 529 | ) |
| 530 | + |
| 531 | + |
| 532 | +def test_get_all_patient_documents_when_feature_disabled( |
| 533 | + mns_service_feature_disabled, mocker |
| 534 | +): |
| 535 | + """Test that review documents are not fetched when feature flag is disabled""" |
| 536 | + expected_lg_docs = [MagicMock(spec=DocumentReference)] |
| 537 | + |
| 538 | + mns_service_feature_disabled.lg_document_service.fetch_documents_from_table_with_nhs_number.return_value = ( |
| 539 | + expected_lg_docs |
| 540 | + ) |
| 541 | + |
| 542 | + lg_docs, review_docs = mns_service_feature_disabled.get_all_patient_documents( |
| 543 | + TEST_NHS_NUMBER |
| 544 | + ) |
| 545 | + |
| 546 | + assert lg_docs == expected_lg_docs |
| 547 | + assert review_docs == [] |
| 548 | + mns_service_feature_disabled.lg_document_service.fetch_documents_from_table_with_nhs_number.assert_called_once_with( |
| 549 | + TEST_NHS_NUMBER |
| 550 | + ) |
| 551 | + mns_service_feature_disabled.document_review_service.fetch_documents_from_table_with_nhs_number.assert_not_called() |
| 552 | + |
| 553 | + |
| 554 | +def test_update_all_patient_documents_when_feature_disabled( |
| 555 | + mns_service_feature_disabled, |
| 556 | + mock_document_references, |
| 557 | + mock_document_review_references, |
| 558 | + mocker, |
| 559 | +): |
| 560 | + """Test that review documents are not updated when feature flag is disabled""" |
| 561 | + mns_service_feature_disabled.update_all_patient_documents( |
| 562 | + mock_document_references, mock_document_review_references, NEW_ODS_CODE |
| 563 | + ) |
| 564 | + |
| 565 | + mns_service_feature_disabled.lg_document_service.update_patient_ods_code.assert_called_once_with( |
| 566 | + mock_document_references, NEW_ODS_CODE |
| 567 | + ) |
| 568 | + mns_service_feature_disabled.document_review_service.update_document_review_custodian.assert_not_called() |
| 569 | + |
| 570 | + |
| 571 | +def test_handle_gp_change_notification_when_feature_disabled( |
| 572 | + mns_service_feature_disabled, mock_document_references, mocker |
| 573 | +): |
| 574 | + """Test GP change notification handling when feature flag is disabled""" |
| 575 | + mocker.patch.object(mns_service_feature_disabled, "get_all_patient_documents") |
| 576 | + mns_service_feature_disabled.get_all_patient_documents.return_value = ( |
| 577 | + mock_document_references, |
| 578 | + [], |
| 579 | + ) |
| 580 | + mocker.patch.object(mns_service_feature_disabled, "get_updated_gp_ods") |
| 581 | + mns_service_feature_disabled.get_updated_gp_ods.return_value = NEW_ODS_CODE |
| 582 | + mocker.patch.object(mns_service_feature_disabled, "update_all_patient_documents") |
| 583 | + |
| 584 | + mns_service_feature_disabled.handle_gp_change_notification(gp_change_message) |
| 585 | + |
| 586 | + mns_service_feature_disabled.get_all_patient_documents.assert_called_once_with( |
| 587 | + gp_change_message.subject.nhs_number |
| 588 | + ) |
| 589 | + mns_service_feature_disabled.get_updated_gp_ods.assert_called_once_with( |
| 590 | + gp_change_message.subject.nhs_number |
| 591 | + ) |
| 592 | + mns_service_feature_disabled.update_all_patient_documents.assert_called_once_with( |
| 593 | + mock_document_references, [], NEW_ODS_CODE |
| 594 | + ) |
| 595 | + |
| 596 | + |
| 597 | +def test_handle_death_notification_formal_when_feature_disabled( |
| 598 | + mns_service_feature_disabled, mock_document_references, mocker |
| 599 | +): |
| 600 | + """Test formal death notification when feature flag is disabled""" |
| 601 | + mocker.patch.object(mns_service_feature_disabled, "get_all_patient_documents") |
| 602 | + mocker.patch.object(mns_service_feature_disabled, "get_updated_gp_ods") |
| 603 | + mocker.patch.object(mns_service_feature_disabled, "update_all_patient_documents") |
| 604 | + mns_service_feature_disabled.get_all_patient_documents.return_value = ( |
| 605 | + mock_document_references, |
| 606 | + [], |
| 607 | + ) |
| 608 | + |
| 609 | + mns_service_feature_disabled.handle_death_notification(death_notification_message) |
| 610 | + |
| 611 | + mns_service_feature_disabled.get_all_patient_documents.assert_called_once_with( |
| 612 | + death_notification_message.subject.nhs_number |
| 613 | + ) |
| 614 | + mns_service_feature_disabled.update_all_patient_documents.assert_called_once_with( |
| 615 | + mock_document_references, |
| 616 | + [], |
| 617 | + PatientOdsInactiveStatus.DECEASED, |
| 618 | + ) |
| 619 | + mns_service_feature_disabled.get_updated_gp_ods.assert_not_called() |
0 commit comments