@@ -1654,7 +1654,7 @@ def test_get_search_immunizations(self, mock_get_supplier_permissions):
16541654 """it should search based on patient_identifier and immunization_target"""
16551655 mock_get_supplier_permissions .return_value = ["COVID19.S" ]
16561656 search_result = Bundle .construct ()
1657- self .service .search_immunizations .return_value = search_result
1657+ self .service .search_immunizations .return_value = search_result , False
16581658
16591659 vaccine_type = "COVID19"
16601660 params = f"{ self .immunization_target_key } ={ vaccine_type } &" + urllib .parse .urlencode (
@@ -1677,18 +1677,18 @@ def test_get_search_immunizations(self, mock_get_supplier_permissions):
16771677 # Then
16781678 mock_get_supplier_permissions .assert_called_once_with ("test" )
16791679 self .service .search_immunizations .assert_called_once_with (
1680- self .nhs_number_valid_value , [vaccine_type ], params , ANY , ANY
1680+ self .nhs_number_valid_value , [vaccine_type ], params , "test" , ANY , ANY
16811681 )
16821682 self .assertEqual (response ["statusCode" ], 200 )
16831683 body = json .loads (response ["body" ])
16841684 self .assertEqual (body ["resourceType" ], "Bundle" )
16851685
16861686 @patch ("fhir_controller.get_supplier_permissions" )
16871687 def test_get_search_immunizations_vax_permission_check (self , mock_get_supplier_permissions ):
1688- """it should search based on patient_identifier and immunization_target"""
1689- mock_get_supplier_permissions .return_value = []
1688+ """it should return a 403 error if the service raises an unauthorized error"""
16901689 search_result = Bundle .construct ()
1691- self .service .search_immunizations .return_value = search_result
1690+ mock_get_supplier_permissions .return_value = []
1691+ self .service .search_immunizations .side_effect = UnauthorizedVaxError ()
16921692
16931693 vaccine_type = "COVID19"
16941694 lambda_event = {
@@ -1704,14 +1704,16 @@ def test_get_search_immunizations_vax_permission_check(self, mock_get_supplier_p
17041704
17051705 # Then
17061706 self .assertEqual (response ["statusCode" ], 403 )
1707+ body = json .loads (response ["body" ])
1708+ self .assertEqual (body ["resourceType" ], "OperationOutcome" )
17071709
17081710 @patch ("fhir_controller.get_supplier_permissions" )
17091711 def test_get_search_immunizations_for_unauthorized_vaccine_type_search (self , mock_get_supplier_permissions ):
17101712 """it should return 200 and contains warning operation outcome as the user is not having authorization for one of the vaccine type"""
17111713 search_result = load_json_data ("sample_immunization_response _for _not_done_event.json" )
17121714 mock_get_supplier_permissions .return_value = ["covid19.S" ]
17131715 bundle = Bundle .parse_obj (search_result )
1714- self .service .search_immunizations .return_value = bundle
1716+ self .service .search_immunizations .return_value = bundle , True
17151717
17161718 vaccine_type = ["COVID19" , "FLU" ]
17171719 vaccine_type = "," .join (vaccine_type )
@@ -1737,11 +1739,11 @@ def test_get_search_immunizations_for_unauthorized_vaccine_type_search(self, moc
17371739
17381740 @patch ("fhir_controller.get_supplier_permissions" )
17391741 def test_get_search_immunizations_for_unauthorized_vaccine_type_search_400 (self ,mock_get_supplier_permissions ):
1740- """it should return 400 as the the request is having invalid vaccine type"""
1742+ """it should return 400 as the request has an invalid vaccine type"""
17411743 search_result = load_json_data ("sample_immunization_response _for _not_done_event.json" )
17421744 mock_get_supplier_permissions .return_value = ["covid19.S" ]
17431745 bundle = Bundle .parse_obj (search_result )
1744- self .service .search_immunizations .return_value = bundle
1746+ self .service .search_immunizations .return_value = bundle , False
17451747
17461748 vaccine_type = "FLUE"
17471749
@@ -1759,60 +1761,12 @@ def test_get_search_immunizations_for_unauthorized_vaccine_type_search_400(self,
17591761 body = json .loads (response ["body" ])
17601762 self .assertEqual (body ["resourceType" ], "OperationOutcome" )
17611763
1762- @patch ("fhir_controller.get_supplier_permissions" )
1763- def test_get_search_immunizations_for_unauthorized_vaccine_type_search_403 (self , mock_get_supplier_permissions ):
1764- """it should return 403 as the user doesnt have vaccinetype permission"""
1765- search_result = load_json_data ("sample_immunization_response _for _not_done_event.json" )
1766- bundle = Bundle .parse_obj (search_result )
1767- mock_get_supplier_permissions .return_value = []
1768- self .service .search_immunizations .return_value = bundle
1769-
1770- vaccine_type = "COVID19,FLU"
1771- lambda_event = {
1772- "headers" : {"Content-Type" : "application/x-www-form-urlencoded" , "SupplierSystem" : "test" ,},
1773- "multiValueQueryStringParameters" : {
1774- self .immunization_target_key : [vaccine_type ],
1775- self .patient_identifier_key : [self .patient_identifier_valid_value ],
1776- },
1777- }
1778-
1779- # When
1780- response = self .controller .search_immunizations (lambda_event )
1781- mock_get_supplier_permissions .assert_called_once_with ("test" )
1782- self .assertEqual (response ["statusCode" ], 403 )
1783- body = json .loads (response ["body" ])
1784- self .assertEqual (body ["resourceType" ], "OperationOutcome" )
1785-
1786- @patch ("fhir_controller.get_supplier_permissions" )
1787- def test_get_search_immunizations_unauthorized (self , mock_get_supplier_permissions ):
1788- """it should search based on patient_identifier and immunization_target"""
1789- search_result = Bundle .construct ()
1790- mock_get_supplier_permissions .return_value = []
1791- self .service .search_immunizations .return_value = search_result
1792-
1793- vaccine_type = "COVID19"
1794- params = f"{ self .immunization_target_key } ={ vaccine_type } &" + urllib .parse .urlencode (
1795- [(f"{ self .patient_identifier_key } " , f"{ self .patient_identifier_valid_value } " )]
1796- )
1797- lambda_event = {
1798- "headers" : {"Content-Type" : "application/x-www-form-urlencoded" , "SupplierSystem" : "test" },
1799- "multiValueQueryStringParameters" : {
1800- self .immunization_target_key : [vaccine_type ],
1801- self .patient_identifier_key : [self .patient_identifier_valid_value ],
1802- },
1803- }
1804-
1805- # When
1806- response = self .controller .search_immunizations (lambda_event )
1807- mock_get_supplier_permissions .assert_called_once_with ("test" )
1808- self .assertEqual (response ["statusCode" ], 403 )
1809-
18101764 @patch ("fhir_controller.get_supplier_permissions" )
18111765 def test_post_search_immunizations (self ,mock_get_supplier_permissions ):
18121766 """it should search based on patient_identifier and immunization_target"""
18131767 mock_get_supplier_permissions .return_value = ["covid19.s" ]
18141768 search_result = Bundle .construct ()
1815- self .service .search_immunizations .return_value = search_result
1769+ self .service .search_immunizations .return_value = search_result , False
18161770
18171771 vaccine_type = "COVID19"
18181772 params = f"{ self .immunization_target_key } ={ vaccine_type } &" + urllib .parse .urlencode (
@@ -1837,7 +1791,7 @@ def test_post_search_immunizations(self,mock_get_supplier_permissions):
18371791 response = self .controller .search_immunizations (lambda_event )
18381792 # Then
18391793 self .service .search_immunizations .assert_called_once_with (
1840- self .nhs_number_valid_value , [vaccine_type ], params , ANY , ANY
1794+ self .nhs_number_valid_value , [vaccine_type ], params , "Test" , ANY , ANY
18411795 )
18421796 self .assertEqual (response ["statusCode" ], 200 )
18431797 mock_get_supplier_permissions .assert_called_once_with ("Test" )
@@ -1849,7 +1803,7 @@ def test_post_search_immunizations_for_unauthorized_vaccine_type_search(self,moc
18491803 """it should return 200 and contains warning operation outcome as the user is not having authorization for one of the vaccine type"""
18501804 search_result = load_json_data ("sample_immunization_response _for _not_done_event.json" )
18511805 bundle = Bundle .parse_obj (search_result )
1852- self .service .search_immunizations .return_value = bundle
1806+ self .service .search_immunizations .return_value = bundle , True
18531807 mock_get_supplier_permissions .return_value = ["covid19.s" ]
18541808
18551809 vaccine_type = "COVID19" , "FLU"
@@ -1881,10 +1835,10 @@ def test_post_search_immunizations_for_unauthorized_vaccine_type_search(self,moc
18811835 self .assertTrue (operation_outcome_present , "OperationOutcome resource is not present in the response" )
18821836
18831837 def test_post_search_immunizations_for_unauthorized_vaccine_type_search_400 (self ):
1884- """it should return 400 as the the request is having invalid vaccine type"""
1838+ """it should return 400 as the request is having invalid vaccine type"""
18851839 search_result = load_json_data ("sample_immunization_response _for _not_done_event.json" )
18861840 bundle = Bundle .parse_obj (search_result )
1887- self .service .search_immunizations .return_value = bundle
1841+ self .service .search_immunizations .return_value = bundle , False
18881842
18891843 vaccine_type = "FLUE"
18901844
@@ -1915,7 +1869,7 @@ def test_post_search_immunizations_for_unauthorized_vaccine_type_search_403(self
19151869 search_result = load_json_data ("sample_immunization_response _for _not_done_event.json" )
19161870 bundle = Bundle .parse_obj (search_result )
19171871 mock_get_supplier_permissions .return_value = []
1918- self .service .search_immunizations .return_value = bundle
1872+ self .service .search_immunizations .side_effect = UnauthorizedVaxError ()
19191873
19201874 vaccine_type = ["COVID19" , "FLU" ]
19211875 vaccine_type = "," .join (vaccine_type )
@@ -1981,11 +1935,11 @@ def test_search_immunizations_returns_400_on_ParameterException_from_parameter_p
19811935
19821936 @patch ("fhir_controller.get_supplier_permissions" )
19831937 def test_search_immunizations_returns_400_on_passing_superseded_nhs_number (self , mock_get_supplier_permissions ):
1984- "This method should return 400 as input paramter has superseded nhs number."
1938+ """ This method should return 400 as input parameter has superseded nhs number."" "
19851939 search_result = {
19861940 "diagnostics" : "Validation errors: contained[?(@.resourceType=='Patient')].identifier[0].value does not exists"
19871941 }
1988- self .service .search_immunizations .return_value = search_result
1942+ self .service .search_immunizations .return_value = search_result , False
19891943 mock_get_supplier_permissions .return_value = ["covid19.s" ]
19901944
19911945 vaccine_type = "COVID19"
@@ -2010,11 +1964,11 @@ def test_search_immunizations_returns_400_on_passing_superseded_nhs_number(self,
20101964
20111965 @patch ("fhir_controller.get_supplier_permissions" )
20121966 def test_search_immunizations_returns_200_remove_vaccine_not_done (self , mock_get_supplier_permissions ):
2013- "This method should return 200 but remove the data which has status as not done."
1967+ """ This method should return 200 but remove the data which has status as not done."" "
20141968 search_result = load_json_data ("sample_immunization_response _for _not_done_event.json" )
20151969 bundle = Bundle .parse_obj (search_result )
20161970 mock_get_supplier_permissions .return_value = ["COVID19.CRUDS" ]
2017- self .service .search_immunizations .return_value = bundle
1971+ self .service .search_immunizations .return_value = bundle , False
20181972 vaccine_type = "COVID19"
20191973 lambda_event = {
20201974 "headers" : {
@@ -2038,7 +1992,7 @@ def test_search_immunizations_returns_200_remove_vaccine_not_done(self, mock_get
20381992 @patch ("fhir_controller.get_supplier_permissions" )
20391993 def test_self_link_excludes_extraneous_params (self , mock_get_supplier_permissions ):
20401994 search_result = Bundle .construct ()
2041- self .service .search_immunizations .return_value = search_result
1995+ self .service .search_immunizations .return_value = search_result , False
20421996 vaccine_type = "COVID19"
20431997 mock_get_supplier_permissions .return_value = ["covid19.CUDS" ]
20441998 params = f"{ self .immunization_target_key } ={ vaccine_type } &" + urllib .parse .urlencode (
@@ -2063,5 +2017,5 @@ def test_self_link_excludes_extraneous_params(self, mock_get_supplier_permission
20632017 self .controller .search_immunizations (lambda_event )
20642018
20652019 self .service .search_immunizations .assert_called_once_with (
2066- self .nhs_number_valid_value , [vaccine_type ], params , ANY , ANY
2020+ self .nhs_number_valid_value , [vaccine_type ], params , "Test" , ANY , ANY
20672021 )
0 commit comments