3232from parameter_parser import patient_identifier_system , process_search_params
3333from tests .utils .generic_utils import load_json_data
3434from tests .utils .values_for_tests import ValidValues
35- from utils .mock_redis import MOCK_REDIS_V2D_RESPONSE
3635
37- class TestFhirControllerBase (unittest .TestCase ):
38- """Base class for all tests to set up common fixtures"""
36+ "test"
3937
38+
39+ class TestFhirController (unittest .TestCase ):
4040 def setUp (self ):
41- super ().setUp ()
42- self .redis_patcher = patch ("parameter_parser.redis_client" )
43- self .mock_redis_client = self .redis_patcher .start ()
44- self .logger_info_patcher = patch ("logging.Logger.info" )
45- self .mock_logger_info = self .logger_info_patcher .start ()
46-
47- def tearDown (self ):
48- self .redis_patcher .stop ()
49- self .logger_info_patcher .stop ()
50- super ().tearDown ()
51-
52- class TestFhirController (TestFhirControllerBase ):
53- def setUp (self ):
54- super ().setUp ()
5541 self .service = create_autospec (FhirService )
5642 self .repository = create_autospec (ImmunizationRepository )
5743 self .authorizer = create_autospec (Authorization )
5844 self .controller = FhirController (self .authorizer , self .service )
5945
60- def tearDown (self ):
61- self .redis_patcher .stop ()
62- super ().tearDown ()
63-
6446 def test_create_response (self ):
6547 """it should return application/fhir+json with correct status code"""
6648 body = {"message" : "a body" }
@@ -151,7 +133,7 @@ def test_get_imms_by_identifer_header_missing(self):
151133 response = self .controller .get_immunization_by_identifier (lambda_event )
152134
153135 self .assertEqual (response ["statusCode" ], 403 )
154-
136+
155137 @patch ("fhir_controller.get_supplier_permissions" )
156138 def test_not_found_for_identifier (self , mock_get_permissions ):
157139 """it should return not-found OperationOutcome if it doesn't exist"""
@@ -183,7 +165,7 @@ def test_not_found_for_identifier(self, mock_get_permissions):
183165
184166 imms = identifier .replace ("|" , "#" )
185167 # When
186-
168+
187169 response = self .controller .get_immunization_by_identifier (lambda_event )
188170
189171 # Then
@@ -218,7 +200,7 @@ def test_get_imms_by_identifer_patient_identifier_and_element_present(self, mock
218200 self .assertEqual (response ["statusCode" ], 400 )
219201 body = json .loads (response ["body" ])
220202 self .assertEqual (body ["resourceType" ], "OperationOutcome" )
221-
203+
222204 @patch ("fhir_controller.get_supplier_permissions" )
223205 def test_get_imms_by_identifer_both_body_and_query_params_present (self , mock_get_supplier_permissions ):
224206 """it should return Immunization Id if it exists"""
@@ -440,7 +422,7 @@ def test_validate_immunization_identifier_having_whitespace(self,mock_get_suppli
440422 self .assertEqual (response ["statusCode" ], 400 )
441423 outcome = json .loads (response ["body" ])
442424 self .assertEqual (outcome ["resourceType" ], "OperationOutcome" )
443-
425+
444426 @patch ("fhir_controller.get_supplier_permissions" )
445427 def test_validate_imms_id_invalid_vaccinetype (self , mock_get_permissions ):
446428 """it should validate lambda's Immunization id"""
@@ -756,7 +738,7 @@ def test_validate_immunization_identifier_having_whitespace(self,mock_get_suppli
756738 self .assertEqual (response ["statusCode" ], 400 )
757739 outcome = json .loads (response ["body" ])
758740 self .assertEqual (outcome ["resourceType" ], "OperationOutcome" )
759-
741+
760742 @patch ("fhir_controller.get_supplier_permissions" )
761743 def test_validate_imms_id_invalid_vaccinetype (self , mock_get_permissions ):
762744 """it should validate lambda's Immunization id"""
@@ -838,7 +820,7 @@ def test_get_imms_by_id_unauthorised_vax_error(self,mock_permissions):
838820 # Then
839821 mock_permissions .assert_called_once_with ("test" )
840822 self .assertEqual (response ["statusCode" ], 403 )
841-
823+
842824 @patch ("fhir_controller.get_supplier_permissions" )
843825 def test_get_imms_by_id_no_vax_permission (self , mock_permissions ):
844826 """it should return Immunization Id if it exists"""
@@ -1160,7 +1142,7 @@ def test_update_immunization_UnauthorizedVaxError(self, mock_get_supplier_permis
11601142 response = self .controller .update_immunization (aws_event )
11611143 mock_get_supplier_permissions .assert_called_once_with ("Test" )
11621144 self .assertEqual (response ["statusCode" ], 403 )
1163-
1145+
11641146 @patch ("fhir_controller.get_supplier_permissions" )
11651147 def test_update_immunization_UnauthorizedVaxError_check_for_non_batch (self , mock_get_supplier_permissions ):
11661148 """it should not update the Immunization record"""
@@ -1591,7 +1573,7 @@ def test_immunization_exception_not_found(self, mock_get_permissions):
15911573 body = json .loads (response ["body" ])
15921574 self .assertEqual (body ["resourceType" ], "OperationOutcome" )
15931575 self .assertEqual (body ["issue" ][0 ]["code" ], "not-found" )
1594-
1576+
15951577 @patch ("fhir_controller.get_supplier_permissions" )
15961578 def test_immunization_unhandled_error (self , mock_get_supplier_permissions ):
15971579 """it should return server-error OperationOutcome if service throws UnhandledResponseError"""
@@ -1614,9 +1596,8 @@ def test_immunization_unhandled_error(self, mock_get_supplier_permissions):
16141596 self .assertEqual (body ["resourceType" ], "OperationOutcome" )
16151597 self .assertEqual (body ["issue" ][0 ]["code" ], "exception" )
16161598
1617- class TestSearchImmunizations (TestFhirControllerBase ):
1599+ class TestSearchImmunizations (unittest . TestCase ):
16181600 def setUp (self ):
1619- super ().setUp ()
16201601 self .service = create_autospec (FhirService )
16211602 self .authorizer = create_autospec (Authorization )
16221603 self .controller = FhirController (self .authorizer , self .service )
@@ -1626,15 +1607,11 @@ def setUp(self):
16261607 self .date_to_key = "-date.to"
16271608 self .nhs_number_valid_value = "9000000009"
16281609 self .patient_identifier_valid_value = f"{ patient_identifier_system } |{ self .nhs_number_valid_value } "
1629- self .mock_redis_client .hkeys .return_value = MOCK_REDIS_V2D_RESPONSE
1630-
1631- def tearDown (self ):
1632- return super ().tearDown ()
16331610
16341611 @patch ("fhir_controller.get_supplier_permissions" )
16351612 def test_get_search_immunizations (self , mock_get_supplier_permissions ):
16361613 """it should search based on patient_identifier and immunization_target"""
1637-
1614+
16381615 mock_get_supplier_permissions .return_value = ["COVID19.S" ]
16391616 search_result = Bundle .construct ()
16401617 self .service .search_immunizations .return_value = search_result
@@ -1818,7 +1795,7 @@ def test_post_search_immunizations(self,mock_get_supplier_permissions):
18181795 "headers" : {"Content-Type" : "application/x-www-form-urlencoded" , "SupplierSystem" : "Test" },
18191796 "body" : base64_encoded_body ,
18201797 }
1821-
1798+
18221799 # When
18231800 response = self .controller .search_immunizations (lambda_event )
18241801 # Then
@@ -1929,7 +1906,6 @@ def test_post_search_immunizations_for_unauthorized_vaccine_type_search_403(self
19291906
19301907 @patch ("fhir_controller.process_search_params" , wraps = process_search_params )
19311908 def test_uses_parameter_parser (self , process_search_params : Mock ):
1932- self .mock_redis_client .hkeys .return_value = MOCK_REDIS_V2D_RESPONSE
19331909 lambda_event = {
19341910 "multiValueQueryStringParameters" : {
19351911 self .patient_identifier_key : ["https://fhir.nhs.uk/Id/nhs-number|9000000009" ],
0 commit comments