11"""Tests for convert_to_fhir_imms_resource"""
22import unittest
3+ from typing import Tuple , List
34from unittest .mock import patch
45
56from tests .utils_for_recordprocessor_tests .values_for_recordprocessor_tests import (
1011from tests .utils_for_recordprocessor_tests .mock_environment_variables import MOCK_ENVIRONMENT_DICT
1112
1213with patch ("os.environ" , MOCK_ENVIRONMENT_DICT ):
13- from convert_to_fhir_imms_resource import convert_to_fhir_imms_resource
14+ from convert_to_fhir_imms_resource import (
15+ _decorate_immunization ,
16+ _get_decorators_for_action_flag ,
17+ all_decorators ,
18+ convert_to_fhir_imms_resource ,
19+ ImmunizationDecorator
20+ )
1421
1522
1623class TestConvertToFhirImmsResource (unittest .TestCase ):
@@ -22,22 +29,46 @@ def test_convert_to_fhir_imms_resource(self):
2229 outputted FHIR Immunization Resource matches the expected output.
2330 """
2431
25- # Test cases tuples are structure as (test_name, input_values, expected_output)
26- cases = [
27- ("All fields" , MockFieldDictionaries .all_fields , MockFhirImmsResources .all_fields ),
32+ # Test cases tuples are structured as (test_name, input_values, expected_output, action_flag )
33+ test_cases = [
34+ ("All fields" , MockFieldDictionaries .all_fields , MockFhirImmsResources .all_fields , "UPDATE" ),
2835 (
2936 "Mandatory fields only" ,
3037 MockFieldDictionaries .mandatory_fields_only ,
3138 MockFhirImmsResources .mandatory_fields_only ,
39+ "UPDATE"
3240 ),
3341 (
3442 "Critical fields only" ,
3543 MockFieldDictionaries .critical_fields_only ,
3644 MockFhirImmsResources .critical_fields ,
45+ "NEW"
3746 ),
47+ (
48+ "Delete action only converts minimal fields" ,
49+ MockFieldDictionaries .mandatory_fields_delete_action ,
50+ MockFhirImmsResources .delete_operation_fields ,
51+ "DELETE"
52+ )
3853 ]
3954
40- for test_name , input_values , expected_output in cases :
55+ for test_name , input_values , expected_output , action_flag in test_cases :
4156 with self .subTest (test_name ):
42- output = convert_to_fhir_imms_resource (input_values , TargetDiseaseElements .RSV )
57+ output = convert_to_fhir_imms_resource (input_values , TargetDiseaseElements .RSV , action_flag )
4358 self .assertEqual (output , expected_output )
59+
60+ def test_get_decorators_for_action_flag (self ):
61+ """
62+ Test that the _test_get_decorators_for_action_flag function returns the correct list of decorators based on the
63+ action flag provided.
64+ """
65+ test_cases : List [Tuple [str , str , List [ImmunizationDecorator ]]] = [
66+ ("Delete action only returns one decorator" , "DELETE" , [_decorate_immunization ]),
67+ ("Update action returns all decorators" , "UPDATE" , all_decorators ),
68+ ("Create action returns all decorators" , "CREATE" , all_decorators )
69+ ]
70+
71+ for test_name , action_flag , expected_decorators in test_cases :
72+ with self .subTest (test_name ):
73+ result = _get_decorators_for_action_flag (action_flag )
74+ self .assertEqual (result , expected_decorators )
0 commit comments