Skip to content

Commit

Permalink
[PRMP-1367] reverting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NogaNHS committed Jan 24, 2025
1 parent bfa0177 commit 49439c8
Showing 1 changed file with 114 additions and 10 deletions.
124 changes: 114 additions & 10 deletions lambdas/tests/unit/utils/test_lloyd_george_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
validate_lg_files,
validate_patient_date_of_birth,
validate_patient_name_strict,
validate_patient_name_lenient
validate_patient_name_lenient, validate_patient_name_using_full_name_history
)


Expand Down Expand Up @@ -260,6 +260,9 @@ def test_validate_nhs_id_with_pds_service(mock_pds_patient):
with expect_not_to_raise(LGInvalidFilesException):
validate_filename_with_patient_details_lenient(lg_file_list, mock_pds_patient)

with expect_not_to_raise(LGInvalidFilesException):
validate_filename_with_patient_details_strict(lg_file_list, mock_pds_patient)


def test_mismatch_nhs_id(mocker):
lg_file_list = [
Expand All @@ -271,13 +274,20 @@ def test_mismatch_nhs_id(mocker):
mocker.patch(
"utils.lloyd_george_validator.check_for_number_of_files_match_expected"
)
mocker.patch("utils.lloyd_george_validator.validate_file_name")

with pytest.raises(LGInvalidFilesException):
validate_lg_file_names(lg_file_list, "9000000009")

def test_mismatch_name_with_pds_service_strict(mock_pds_patient):
lg_file_list = [
"1of2_Lloyd_George_Record_[Jake Plain Smith]_[9000000009]_[22-10-2010].pdf",
"2of2_Lloyd_George_Record_[Jake Plain Smith]_[9000000009]_[22-10-2010].pdf",
]

def test_mismatch_name_with_pds_service(mock_pds_patient):
with pytest.raises(LGInvalidFilesException):
validate_filename_with_patient_details_strict(lg_file_list, mock_pds_patient)

def test_mismatch_name_with_pds_service_lenient(mock_pds_patient):
lg_file_list = [
"1of2_Lloyd_George_Record_[Jake Plain Moody]_[9000000009]_[22-10-2010].pdf",
"2of2_Lloyd_George_Record_[Jake Plain Moody]_[9000000009]_[22-10-2010].pdf",
Expand All @@ -287,7 +297,7 @@ def test_mismatch_name_with_pds_service(mock_pds_patient):
validate_filename_with_patient_details_lenient(lg_file_list, mock_pds_patient)


def test_validate_name_with_correct_name(mocker, mock_pds_patient):
def test_validate_name_with_correct_name_lenient(mocker, mock_pds_patient):
lg_file_patient_name = "Jane Smith"
mock_validate_name = mocker.patch(
"utils.lloyd_george_validator.validate_patient_name_lenient"
Expand All @@ -305,8 +315,41 @@ def test_validate_name_with_correct_name(mocker, mock_pds_patient):
assert actual_is_name_validation_based_on_historic_name is False
assert actual_score == ValidationScore.FULL_MATCH

def test_validate_name_with_correct_name_strict(mocker, mock_pds_patient):
lg_file_patient_name = "Jane Smith"
mock_validate_name = mocker.patch(
"utils.lloyd_george_validator.validate_patient_name_strict"
)
with expect_not_to_raise(LGInvalidFilesException):
validate_patient_name_using_full_name_history(
lg_file_patient_name, mock_pds_patient
)
assert mock_validate_name.call_count == 1


def test_validate_name_with_file_missing_middle_name(mocker):
lg_file_patient_name = "Jane Smith"
patient = Patient.model_validate(PDS_PATIENT_WITH_MIDDLE_NAME)
mock_validate_name = mocker.patch("utils.lloyd_george_validator.validate_patient_name_strict")
with expect_not_to_raise(LGInvalidFilesException):
validate_patient_name_using_full_name_history(lg_file_patient_name, patient)

def test_validate_name_with_additional_middle_name_in_file_mismatching_pds(mocker):
assert mock_validate_name.call_count == 1


def test_validate_name_with_additional_middle_name_in_file_mismatching_pds_strict(mocker):
lg_file_patient_name = "Jane David Smith"
mock_validate_name = mocker.patch(
"utils.lloyd_george_validator.validate_patient_name_strict"
)
patient = Patient.model_validate(PDS_PATIENT_WITH_MIDDLE_NAME)
with expect_not_to_raise(LGInvalidFilesException):
actual_is_name_validation_based_on_historic_name = validate_patient_name_using_full_name_history(lg_file_patient_name, patient)
assert mock_validate_name.call_count == 1
assert actual_is_name_validation_based_on_historic_name is False


def test_validate_name_with_additional_middle_name_in_file_mismatching_pds_lenient(mocker):
lg_file_patient_name = "Jane David Smith"
mock_validate_name = mocker.patch(
"utils.lloyd_george_validator.validate_patient_name_lenient"
Expand All @@ -326,6 +369,21 @@ def test_validate_name_with_additional_middle_name_in_file_mismatching_pds(mocke
assert actual_score == ValidationScore.FULL_MATCH


def test_validate_name_with_additional_middle_name_in_file_but_none_in_pds_strict(
mock_pds_patient, mocker
):
lg_file_patient_name = "Jane David Smith"
mock_validate_name = mocker.patch(
"utils.lloyd_george_validator.validate_patient_name_strict"
)

actual_is_name_validation_based_on_historic_name = (
validate_patient_name_using_full_name_history(lg_file_patient_name, mock_pds_patient)
)

assert mock_validate_name.call_count == 1
assert actual_is_name_validation_based_on_historic_name is False

def test_validate_name_with_additional_middle_name_in_file_but_none_in_pds(
mock_pds_patient, mocker
):
Expand All @@ -335,7 +393,8 @@ def test_validate_name_with_additional_middle_name_in_file_but_none_in_pds(
)
mock_validate_name.return_value = ValidationResult(
score=ValidationScore.FULL_MATCH,
name_match=["Jane", "Smith"],
given_name_match=["Jane"],
family_name_match="Smith",
)
actual_score, actual_is_name_validation_based_on_historic_name, result_message = (
calculate_validation_score(lg_file_patient_name, mock_pds_patient)
Expand All @@ -346,7 +405,16 @@ def test_validate_name_with_additional_middle_name_in_file_but_none_in_pds(
assert actual_score == ValidationScore.FULL_MATCH


def test_validate_name_with_wrong_first_name(mocker, mock_pds_patient):
def test_validate_name_with_wrong_first_name_strict(mocker, mock_pds_patient):
lg_file_patient_name = "John Smith"
mock_validate_name = mocker.patch("utils.lloyd_george_validator.validate_patient_name_strict")
mock_validate_name.return_value = False
with pytest.raises(LGInvalidFilesException):
validate_patient_name_using_full_name_history(lg_file_patient_name, mock_pds_patient)
assert mock_validate_name.call_count == 3


def test_validate_name_with_wrong_first_name_lenient(mock_pds_patient):
lg_file_patient_name = "John Smith"

actual_response = validate_patient_name_lenient(
Expand All @@ -360,7 +428,16 @@ def test_validate_name_with_wrong_first_name(mocker, mock_pds_patient):
)


def test_validate_name_with_wrong_family_name(mocker, mock_pds_patient):
def test_validate_name_with_wrong_family_name_strict(mocker, mock_pds_patient):
lg_file_patient_name = "John Johnson"
mock_validate_name = mocker.patch("utils.lloyd_george_validator.validate_patient_name_strict")
mock_validate_name.return_value = False
with pytest.raises(LGInvalidFilesException):
validate_patient_name_using_full_name_history(lg_file_patient_name, mock_pds_patient)
assert mock_validate_name.call_count == 3


def test_validate_name_with_wrong_family_name_lenient(mock_pds_patient):
lg_file_patient_name = "Jane Johnson"
actual_response = validate_patient_name_lenient(
lg_file_patient_name,
Expand All @@ -373,7 +450,19 @@ def test_validate_name_with_wrong_family_name(mocker, mock_pds_patient):
)


def test_validate_name_with_historical_name(mocker, mock_pds_patient):
def test_validate_name_with_historical_name_strict(mocker, mock_pds_patient):
lg_file_patient_name = "Jim Stevens"
mock_validate_name = mocker.patch(
"utils.lloyd_george_validator.validate_patient_name_strict"
)
mock_validate_name.side_effect = [False, True]
with expect_not_to_raise(LGInvalidFilesException):
actual_is_name_validation_based_on_historic_name = (validate_patient_name_using_full_name_history(lg_file_patient_name, mock_pds_patient))

assert mock_validate_name.call_count == 2
assert actual_is_name_validation_based_on_historic_name is True

def test_validate_name_with_historical_name_lenient(mocker, mock_pds_patient):
lg_file_patient_name = "Jim Stevens"
mock_validate_name = mocker.patch(
"utils.lloyd_george_validator.validate_patient_name_lenient"
Expand All @@ -394,7 +483,22 @@ def test_validate_name_with_historical_name(mocker, mock_pds_patient):
assert actual_is_validate_on_historic is True


def test_validate_name_without_given_name(mocker, mock_pds_patient):
def test_validate_name_without_given_name_strict(mocker, mock_pds_patient):
lg_file_patient_name = "Jane Smith"
mock_pds_patient.name[0].given = [""]
mock_validate_name = mocker.patch(
"utils.lloyd_george_validator.validate_patient_name_strict"
)

with expect_not_to_raise(LGInvalidFilesException):
actual_is_validate_on_historic = (validate_patient_name_using_full_name_history(lg_file_patient_name, mock_pds_patient))

assert actual_is_validate_on_historic is False
assert mock_validate_name.call_count == 1



def test_validate_name_without_given_name_lenient(mocker, mock_pds_patient):
lg_file_patient_name = "Jane Smith"
mock_pds_patient.name[0].given = [""]
mock_validate_name = mocker.patch(
Expand Down

0 comments on commit 49439c8

Please sign in to comment.