@@ -461,9 +461,11 @@ def parse_lambda_body(self, lambda_event):
461461 identifiers = converted_identifier .replace ("|" , "#" )
462462 return identifiers , converted_identifier , converted_element
463463
464- def test_get_imms_by_identifier (self ):
464+ @patch ("fhir_controller.get_supplier_permissions" )
465+ def test_get_imms_by_identifier (self ,mock_get_permissions ):
465466 """It should return Immunization Id if it exists"""
466467 # Given
468+ mock_get_permissions .return_value = ["COVID19:search" ]
467469 self .service .get_immunization_by_identifier .return_value = {"id" : "test" , "Version" : 1 }
468470 body = "immunization.identifier=https://supplierABC/identifiers/vacc#f10b59b3-fc73-4616-99c9-9e882ab31184&_element=id|meta"
469471 lambda_event = self .set_up_lambda_event (body )
@@ -473,16 +475,19 @@ def test_get_imms_by_identifier(self):
473475 response = self .controller .get_immunization_by_identifier (lambda_event )
474476
475477 # Then
478+ mock_get_permissions .assert_called_once_with ("test" )
476479 self .service .get_immunization_by_identifier .assert_called_once_with (
477- identifiers , "COVID19:search" , converted_identifier , converted_element , False
480+ identifiers , [ "COVID19:search" ] , converted_identifier , converted_element
478481 )
479482 self .assertEqual (response ["statusCode" ], 200 )
480483 body = json .loads (response ["body" ])
481484 self .assertEqual (body ["id" ], "test" )
482485
483- def test_not_found_for_identifier (self ):
486+ @patch ("fhir_controller.get_supplier_permissions" )
487+ def test_not_found_for_identifier (self , mock_get_permissions ):
484488 """It should return not-found OperationOutcome if it doesn't exist"""
485489 # Given
490+ mock_get_permissions .return_value = ["COVID19:search" ]
486491 self .service .get_immunization_by_identifier .return_value = {
487492 "resourceType" : "Bundle" ,
488493 "type" : "searchset" ,
@@ -503,51 +508,24 @@ def test_not_found_for_identifier(self):
503508 response = self .controller .get_immunization_by_identifier (lambda_event )
504509
505510 # Then
511+ mock_get_permissions .assert_called_once_with ("test" )
506512 self .service .get_immunization_by_identifier .assert_called_once_with (
507- identifiers , "COVID19:search" , converted_identifier , converted_element , False
513+ identifiers , [ "COVID19:search" ] , converted_identifier , converted_element
508514 )
509515 self .assertEqual (response ["statusCode" ], 200 )
510516 body = json .loads (response ["body" ])
511517 self .assertEqual (body ["resourceType" ], "Bundle" )
512518 self .assertEqual (body ["entry" ], [])
513519 self .assertEqual (body ["total" ], 0 )
514520
515- def test_get_imms_by_identifer_for_batch (self ):
516- """it should return Immunization Id if it exists"""
517- # Given
518- self .service .get_immunization_by_identifier .return_value = {"id" : "test" , "Version" : 1 }
519- lambda_event = {
520- "headers" : {"VaccineTypePermissions" : "COVID19:search" , "SupplierSystem" : "Imms-Batch-App" },
521- "queryStringParameters" : None ,
522- "body" : "aW1tdW5pemF0aW9uLmlkZW50aWZpZXI9aHR0cHMlM0ElMkYlMkZzdXBwbGllckFCQyUyRmlkZW50aWZpZXJzJTJGdmFjYyU3Q2YxMGI1OWIzLWZjNzMtNDYxNi05OWM5LTllODgyYWIzMTE4NCZfZWxlbWVudD1pZCUyQ21ldGEmaWQ9cw==" ,
523- }
524- decoded_body = base64 .b64decode (lambda_event ["body" ]).decode ("utf-8" )
525- # Parse the URL encoded body
526- parsed_body = urllib .parse .parse_qs (decoded_body )
527-
528- immunization_identifier = parsed_body .get ("immunization.identifier" , "" )
529- converted_identifer = "" .join (immunization_identifier )
530- element = parsed_body .get ("_element" , "" )
531- converted_element = "" .join (element )
532-
533- identifiers = converted_identifer .replace ("|" , "#" )
534- # When
535- response = self .controller .get_immunization_by_identifier (lambda_event )
536- # Then
537- self .service .get_immunization_by_identifier .assert_called_once_with (
538- identifiers , None , converted_identifer , converted_element , True
539- )
540-
541- self .assertEqual (response ["statusCode" ], 200 )
542- body = json .loads (response ["body" ])
543- self .assertEqual (body ["id" ], "test" )
544-
545- def test_get_imms_by_identifer_patient_identifier_and_element_present (self ):
521+ @patch ("fhir_controller.get_supplier_permissions" )
522+ def test_get_imms_by_identifer_patient_identifier_and_element_present (self , mock_get_permissions ):
546523 """it should return 400 as its having invalid request"""
547524 # Given
525+ mock_get_permissions .return_value = ["COVID19:search" ]
548526 self .service .get_immunization_by_identifier .return_value = {"id" : "test" , "Version" : 1 }
549527 lambda_event = {
550- "headers" : {"VaccineTypePermissions" : "COVID19:search" , " SupplierSystem" : "test" },
528+ "headers" : {"SupplierSystem" : "test" },
551529 "queryStringParameters" : None ,
552530 "body" : "cGF0aWVudC5pZGVudGlmaWVyPWh0dHBzJTNBJTJGJTJGZmhpci5uaHMudWslMkZJZCUyRm5ocy1udW1iZXIlN0M5NjkzNjMyMTA5Jl9lbGVtZW50PWlkJTJDbWV0YQ==" ,
553531 }
@@ -766,69 +744,81 @@ def setUp(self):
766744 self .authorizer = create_autospec (Authorization )
767745 self .controller = FhirController (self .authorizer , self .service )
768746
769- def test_get_imms_by_id (self ):
747+ @patch ("fhir_controller.get_supplier_permissions" )
748+ def test_get_imms_by_id (self , mock_permissions ):
770749 """it should return Immunization resource if it exists"""
771750 # Given
751+ mock_permissions .return_value = ["COVID19:read" ]
772752 imms_id = "a-id"
773753 self .service .get_immunization_by_id .return_value = Immunization .construct ()
774754 lambda_event = {
775- "headers" : {"VaccineTypePermissions " : "COVID19:read " },
755+ "headers" : {"SupplierSystem " : "test " },
776756 "pathParameters" : {"id" : imms_id },
777757 }
778758
779759 # When
780760 response = self .controller .get_immunization_by_id (lambda_event )
781761 # Then
782- self .service .get_immunization_by_id .assert_called_once_with (imms_id , "COVID19:read" )
762+ mock_permissions .assert_called_once_with ("test" )
763+ self .service .get_immunization_by_id .assert_called_once_with (imms_id , ["COVID19:read" ])
783764
784765 self .assertEqual (response ["statusCode" ], 200 )
785766 body = json .loads (response ["body" ])
786767 self .assertEqual (body ["resourceType" ], "Immunization" )
787768
788- def test_get_imms_by_id_unauthorised_vax_error (self ):
769+ @patch ("fhir_controller.get_supplier_permissions" )
770+ def test_get_imms_by_id_unauthorised_vax_error (self ,mock_permissions ):
789771 """it should return Immunization resource if it exists"""
790772 # Given
773+ mock_permissions .return_value = ["COVID19:read" ]
791774 imms_id = "a-id"
792775 self .service .get_immunization_by_id .side_effect = UnauthorizedVaxError
793776 lambda_event = {
794- "headers" : {"VaccineTypePermissions " : "COVID19:read " },
777+ "headers" : {"SupplierSystem " : "test " },
795778 "pathParameters" : {"id" : imms_id },
796779 }
797780
798781 # When
799782 response = self .controller .get_immunization_by_id (lambda_event )
800783 # Then
784+ mock_permissions .assert_called_once_with ("test" )
801785 self .assertEqual (response ["statusCode" ], 403 )
802-
803- def test_get_imms_by_id_no_vax_permission (self ):
786+
787+ @patch ("fhir_controller.get_supplier_permissions" )
788+ def test_get_imms_by_id_no_vax_permission (self , mock_permissions ):
804789 """it should return Immunization Id if it exists"""
805790 # Given
791+ mock_permissions .return_value = []
806792 imms_id = "a-id"
807793 lambda_event = {
808- "headers" : {"VaccineTypePermissions" : "" , " SupplierSystem" : "test" },
794+ "headers" : {"SupplierSystem" : "test" },
809795 "pathParameters" : {"id" : imms_id },
810796 "body" : None ,
811797 }
812798 # When
813799 response = self .controller .get_immunization_by_id (lambda_event )
814800 # Then
801+ mock_permissions .assert_called_once_with ("test" )
815802 self .assertEqual (response ["statusCode" ], 403 )
816803
817- def test_not_found (self ):
804+ @patch ("fhir_controller.get_supplier_permissions" )
805+ def test_not_found (self ,mock_permissions ):
818806 """it should return not-found OperationOutcome if it doesn't exist"""
819807 # Given
808+ mock_permissions .return_value = ["COVID19:read" ]
820809 imms_id = "a-non-existing-id"
821810 self .service .get_immunization_by_id .return_value = None
822811 lambda_event = {
823- "headers" : {"VaccineTypePermissions " : "COVID19:read " },
812+ "headers" : {"SupplierSystem " : "test " },
824813 "pathParameters" : {"id" : imms_id },
825814 }
826815
827816 # When
828817 response = self .controller .get_immunization_by_id (lambda_event )
829818
830819 # Then
831- self .service .get_immunization_by_id .assert_called_once_with (imms_id , "COVID19:read" )
820+ mock_permissions .assert_called_once_with ("test" )
821+ self .service .get_immunization_by_id .assert_called_once_with (imms_id , ["COVID19:read" ])
832822
833823 self .assertEqual (response ["statusCode" ], 404 )
834824 body = json .loads (response ["body" ])
0 commit comments