55import unittest
66import uuid
77
8- from unittest .mock import patch
98from fhir .resources .R4B .bundle import Bundle
109from fhir .resources .R4B .immunization import Immunization
1110from unittest .mock import create_autospec , ANY , patch , Mock
1211from urllib .parse import urlencode
1312import urllib .parse
14- from moto import mock_aws
1513from authorization import Authorization
1614from fhir_controller import FhirController
1715from fhir_repository import ImmunizationRepository
2220 InvalidPatientId ,
2321 CustomValidationError ,
2422 ParameterException ,
25- InconsistentIdError ,
2623 UnauthorizedVaxError ,
27- UnauthorizedError ,
2824 IdentifierDuplicationError ,
2925)
3026from tests .utils .immunization_utils import create_covid_19_immunization
3127from parameter_parser import patient_identifier_system , process_search_params
3228from tests .utils .generic_utils import load_json_data
33- from tests .utils .values_for_tests import ValidValues
3429
3530class TestFhirControllerBase (unittest .TestCase ):
3631 """Base class for all tests to set up common fixtures"""
@@ -211,7 +206,7 @@ def test_get_imms_by_identifer_patient_identifier_and_element_present(self, mock
211206 # When
212207 response = self .controller .get_immunization_by_identifier (lambda_event )
213208 # Then
214- self .service .get_immunization_by_identifier .assert_not_called
209+ self .service .get_immunization_by_identifier .assert_not_called ()
215210
216211 self .assertEqual (response ["statusCode" ], 400 )
217212 body = json .loads (response ["body" ])
@@ -234,7 +229,30 @@ def test_get_imms_by_identifer_both_body_and_query_params_present(self, mock_get
234229 # When
235230 response = self .controller .get_immunization_by_identifier (lambda_event )
236231 # Then
237- self .service .get_immunization_by_identifier .assert_not_called
232+ self .service .get_immunization_by_identifier .assert_not_called ()
233+
234+ self .assertEqual (response ["statusCode" ], 400 )
235+ body = json .loads (response ["body" ])
236+ self .assertEqual (body ["resourceType" ], "OperationOutcome" )
237+
238+ @patch ("fhir_controller.get_supplier_permissions" )
239+ def test_get_imms_by_identifer_imms_identifier_and_element_not_present (self , mock_get_supplier_permissions ):
240+ """it should return Immunization Id if it exists"""
241+ # Given
242+ mock_get_supplier_permissions .return_value = ["COVID19.CRUDS" ]
243+ self .service .get_immunization_by_identifier .return_value = {"id" : "test" , "Version" : 1 }
244+ lambda_event = {
245+ "headers" : {"SupplierSystem" : "test" },
246+ "queryStringParameters" : {
247+ "-immunization.target" : "test" ,
248+ "immunization.identifier" : "https://supplierABC/identifiers/vacc|f10b59b3-fc73-4616-99c9-9e882ab31184" ,
249+ },
250+ "body" : None ,
251+ }
252+ # When
253+ response = self .controller .get_immunization_by_identifier (lambda_event )
254+ # Then
255+ self .service .get_immunization_by_identifier .assert_not_called ()
238256
239257 self .assertEqual (response ["statusCode" ], 400 )
240258 body = json .loads (response ["body" ])
@@ -258,7 +276,7 @@ def test_get_imms_by_identifer_both_identifier_present(self, mock_get_supplier_p
258276 # When
259277 response = self .controller .get_immunization_by_identifier (lambda_event )
260278 # Then
261- self .service .get_immunization_by_identifier .assert_not_called
279+ self .service .get_immunization_by_identifier .assert_not_called ()
262280
263281 self .assertEqual (response ["statusCode" ], 400 )
264282 body = json .loads (response ["body" ])
@@ -512,7 +530,7 @@ def test_get_imms_by_identifer_patient_identifier_and_element_present(self, mock
512530 # When
513531 response = self .controller .get_immunization_by_identifier (lambda_event )
514532 # Then
515- self .service .get_immunization_by_identifier .assert_not_called
533+ self .service .get_immunization_by_identifier .assert_not_called ()
516534
517535 self .assertEqual (response ["statusCode" ], 400 )
518536 body = json .loads (response ["body" ])
@@ -532,7 +550,7 @@ def test_get_imms_by_identifer_imms_identifier_and_element_not_present(self,mock
532550 # When
533551 response = self .controller .get_immunization_by_identifier (lambda_event )
534552 # Then
535- self .service .get_immunization_by_identifier .assert_not_called
553+ self .service .get_immunization_by_identifier .assert_not_called ()
536554
537555 self .assertEqual (response ["statusCode" ], 400 )
538556 body = json .loads (response ["body" ])
@@ -616,7 +634,7 @@ def test_get_imms_by_identifer_both_identifier_present(self, mock_get_supplier_p
616634 # When
617635 response = self .controller .get_immunization_by_identifier (lambda_event )
618636 # Then
619- self .service .get_immunization_by_identifier .assert_not_called
637+ self .service .get_immunization_by_identifier .assert_not_called ()
620638
621639 self .assertEqual (response ["statusCode" ], 400 )
622640 body = json .loads (response ["body" ])
@@ -757,7 +775,7 @@ def test_get_imms_by_id(self, mock_permissions):
757775 response = self .controller .get_immunization_by_id (lambda_event )
758776 # Then
759777 mock_permissions .assert_called_once_with ("test" )
760- self .service .get_immunization_by_id .assert_called_once_with (imms_id , [ "COVID19.CRUDS" ] )
778+ self .service .get_immunization_by_id .assert_called_once_with (imms_id , "test" )
761779
762780 self .assertEqual (response ["statusCode" ], 200 )
763781 body = json .loads (response ["body" ])
@@ -780,6 +798,7 @@ def test_get_imms_by_id_unauthorised_vax_error(self,mock_permissions):
780798 # Then
781799 mock_permissions .assert_called_once_with ("test" )
782800 self .assertEqual (response ["statusCode" ], 403 )
801+
783802 @patch ("fhir_controller.get_supplier_permissions" )
784803 def test_get_imms_by_id_no_vax_permission (self , mock_permissions ):
785804 """it should return Immunization Id if it exists"""
@@ -814,7 +833,7 @@ def test_not_found(self,mock_permissions):
814833
815834 # Then
816835 mock_permissions .assert_called_once_with ("test" )
817- self .service .get_immunization_by_id .assert_called_once_with (imms_id , [ "COVID19.CRUDS" ] )
836+ self .service .get_immunization_by_id .assert_called_once_with (imms_id , "test" )
818837
819838 self .assertEqual (response ["statusCode" ], 404 )
820839 body = json .loads (response ["body" ])
@@ -860,7 +879,7 @@ def test_create_immunization(self,mock_get_permissions):
860879
861880 imms_obj = json .loads (aws_event ["body" ])
862881 mock_get_permissions .assert_called_once_with ("Test" )
863- self .service .create_immunization .assert_called_once_with (imms_obj , [ "COVID19.CRUDS" , "FLU.CRUDS" ], "Test" )
882+ self .service .create_immunization .assert_called_once_with (imms_obj , "Test" )
864883 self .assertEqual (response ["statusCode" ], 201 )
865884 self .assertTrue ("body" not in response )
866885 self .assertTrue (response ["headers" ]["Location" ].endswith (f"Immunization/{ imms_id } " ))
@@ -1271,7 +1290,7 @@ def test_update_record_exists(self, mock_get_supplier_permissions):
12711290 response = self .controller .get_immunization_by_id (lambda_event )
12721291
12731292 # Then
1274- self .service .get_immunization_by_id .assert_called_once_with (imms_id , [ "COVID19.CRUDS" ] )
1293+ self .service .get_immunization_by_id .assert_called_once_with (imms_id , "Test" )
12751294
12761295 self .assertEqual (response ["statusCode" ], 404 )
12771296 body = json .loads (response ["body" ])
0 commit comments