Skip to content

Commit 0c05e84

Browse files
committed
dose_number unit tests
1 parent de41361 commit 0c05e84

File tree

3 files changed

+250
-234
lines changed

3 files changed

+250
-234
lines changed

backend/src/models/fhir_immunization_pre_validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,16 +626,16 @@ def pre_validate_protocol_applied(self, values: dict) -> dict:
626626
PreValidation.for_list(field_value, "protocolApplied", defined_length=1)
627627
except KeyError:
628628
pass
629-
629+
DOSE_NUMBER_MAX_VALUE = 9
630630
def pre_validate_dose_number_positive_int(self, values: dict) -> dict:
631631
"""
632632
Pre-validate that, if protocolApplied[0].doseNumberPositiveInt (legacy CSV field : dose_sequence)
633-
exists, then it is an integer from 1 to 9
633+
exists, then it is an integer from 1 to 9 (DOSE_NUMBER_MAX_VALUE)
634634
"""
635635
field_location = "protocolApplied[0].doseNumberPositiveInt"
636636
try:
637637
field_value = values["protocolApplied"][0]["doseNumberPositiveInt"]
638-
PreValidation.for_positive_integer(field_value, field_location)
638+
PreValidation.for_positive_integer(field_value, field_location, self.DOSE_NUMBER_MAX_VALUE)
639639
except (KeyError, IndexError):
640640
pass
641641

backend/tests/test_immunization_pre_validator.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from utils.pre_validation_test_utils import ValidatorModelTests
2626
from utils.values_for_tests import ValidValues, InvalidValues
2727
from models.constants import Constants
28+
from models.fhir_immunization_pre_validators import PreValidators
2829

2930
class TestImmunizationModelPreValidationRules(unittest.TestCase):
3031
"""Test immunization pre validation rules on the FHIR model using the covid sample data"""
@@ -818,7 +819,35 @@ def test_pre_validate_protocol_applied(self):
818819
valid_list_element=valid_list_element,
819820
)
820821

822+
# SAW
821823
def test_pre_validate_protocol_applied_dose_number_positive_int(self):
824+
"""
825+
Test pre_validate_protocol_applied_dose_number_positive_int accepts valid values and
826+
rejects invalid values
827+
"""
828+
for value in range(1, PreValidators.DOSE_NUMBER_MAX_VALUE + 1):
829+
data = {
830+
"protocolApplied": [
831+
{"doseNumberPositiveInt": value}
832+
]
833+
}
834+
validator = PreValidators(data)
835+
# Should not raise
836+
validator.pre_validate_dose_number_positive_int(data)
837+
838+
def test_out_of_range_dose_number(self):
839+
# Invalid: doseNumberPositiveInt < 1 or > 9
840+
for value in [0, PreValidators.DOSE_NUMBER_MAX_VALUE + 1, -1]:
841+
data = {
842+
"protocolApplied": [
843+
{"doseNumberPositiveInt": value}
844+
]
845+
}
846+
validator = PreValidators(data)
847+
with self.assertRaises(ValueError):
848+
validator.pre_validate_dose_number_positive_int(data)
849+
850+
def test_test_positive_integer_value(self):
822851
"""
823852
Test pre_validate_protocol_applied_dose_number_positive_int accepts valid values and
824853
rejects invalid values

0 commit comments

Comments
 (0)