@@ -1027,12 +1027,19 @@ def test_update_immunization(self,mock_get_permissions):
10271027 self .assertEqual (response ["statusCode" ], 200 )
10281028 self .assertTrue ("body" not in response )
10291029
1030-
1031- def test_update_immunization_etag_missing (self ):
1030+ @ patch ( "fhir_controller.get_supplier_permissions" )
1031+ def test_update_immunization_etag_missing (self , mock_get_supplier_permissions ):
10321032 """it should update Immunization"""
10331033 # Given
1034+ mock_get_supplier_permissions .return_value = ["COVID19:update" ]
10341035 imms_id = "valid-id"
10351036 imms = {"id" : "valid-id" }
1037+ self .service .get_immunization_by_id_all .return_value = {
1038+ "id" : imms_id ,
1039+ "Version" : 1 ,
1040+ "VaccineType" : "COVID19" ,
1041+ "DeletedAt" : False
1042+ }
10361043 aws_event = {
10371044 "headers" : {
10381045 "SupplierSystem" : "Test" ,
@@ -1219,7 +1226,7 @@ def test_update_deletedat_immunization_with_version(self, mock_get_supplier_perm
12191226 @patch ("fhir_controller.get_supplier_permissions" )
12201227 def test_update_deletedat_immunization_without_version (self , mock_get_supplier_permissions ):
12211228 """it should reinstate deletedat Immunization"""
1222- mock_get_supplier_permissions .return_value = ["Covid19 :update" ]
1229+ mock_get_supplier_permissions .return_value = ["COVID19 :update" ]
12231230 # Given
12241231 imms = '{"id": "valid-id"}'
12251232 imms_id = "valid-id"
@@ -1239,38 +1246,43 @@ def test_update_deletedat_immunization_without_version(self, mock_get_supplier_p
12391246 response = self .controller .update_immunization (aws_event )
12401247
12411248 self .service .reinstate_immunization .assert_called_once_with (
1242- imms_id , json .loads (imms ), 1 , "COVID19:update" , "Test"
1249+ imms_id , json .loads (imms ), 1 , [ "COVID19:update" ] , "Test"
12431250 )
12441251 mock_get_supplier_permissions .assert_called_once_with ("Test" )
12451252 self .assertEqual (response ["statusCode" ], 200 )
12461253 self .assertTrue ("body" not in response )
12471254
1248- def test_update_record_exists (self ):
1255+ @patch ("fhir_controller.get_supplier_permissions" )
1256+ def test_update_record_exists (self , mock_get_supplier_permissions ):
12491257 """it should return not-found OperationOutcome if ID doesn't exist"""
12501258 # Given
1259+ mock_get_supplier_permissions .return_value = ["COVID19:update" ]
12511260 imms_id = "a-non-existing-id"
12521261 self .service .get_immunization_by_id .return_value = None
12531262 lambda_event = {
1254- "headers" : {"E-Tag" : 1 , "VaccineTypePermissions" : "COVID19:update" , " SupplierSystem" : "Test" },
1263+ "headers" : {"E-Tag" : 1 , "SupplierSystem" : "Test" },
12551264 "pathParameters" : {"id" : imms_id },
12561265 }
12571266
12581267 # When
12591268 response = self .controller .get_immunization_by_id (lambda_event )
12601269
12611270 # Then
1262- self .service .get_immunization_by_id .assert_called_once_with (imms_id , "COVID19:update" )
1271+ self .service .get_immunization_by_id .assert_called_once_with (imms_id , [ "COVID19:update" ] )
12631272
12641273 self .assertEqual (response ["statusCode" ], 404 )
12651274 body = json .loads (response ["body" ])
12661275 self .assertEqual (body ["resourceType" ], "OperationOutcome" )
12671276 self .assertEqual (body ["issue" ][0 ]["code" ], "not-found" )
12681277
1269- def test_validation_error (self ):
1278+ @patch ("fhir_controller.get_supplier_permissions" )
1279+ def test_validation_error (self , mock_get_supplier_permissions ):
12701280 """it should return 400 if Immunization is invalid"""
1281+ mock_get_supplier_permissions .return_value = ["COVID19:update" ]
1282+ # Given
12711283 imms = '{"id": "valid-id"}'
12721284 aws_event = {
1273- "headers" : {"E-Tag" : 1 , "VaccineTypePermissions" : "COVID19:update" , " SupplierSystem" : "Test" },
1285+ "headers" : {"E-Tag" : 1 , "SupplierSystem" : "Test" },
12741286 "body" : imms ,
12751287 "pathParameters" : {"id" : "valid-id" },
12761288 }
@@ -1288,20 +1300,16 @@ def test_validation_error(self):
12881300 body = json .loads (response ["body" ])
12891301 self .assertEqual (body ["resourceType" ], "OperationOutcome" )
12901302
1291- @patch ("fhir_controller.sqs_client.send_message" )
1292- def test_validation_error_for_batch (self , mock_send_message ):
1303+
1304+ @patch ("fhir_controller.get_supplier_permissions" )
1305+ def test_validation_error_for_batch (self , mock_get_supplier_permissions ):
12931306 """it should return 400 if Immunization is invalid"""
1307+ mock_get_supplier_permissions .return_value = ["COVID19:update" ]
12941308 imms = '{"id": 123}'
12951309 aws_event = {
12961310 "headers" : {
12971311 "E-Tag" : 1 ,
1298- "VaccineTypePermissions" : "COVID19:update" ,
1299- "SupplierSystem" : "Imms-Batch-App" ,
1300- "BatchSupplierSystem" : "Test" ,
1301- "file_key" : "test" ,
1302- "row_id" : "123" ,
1303- "created_at_formatted_string" : "2020-01-01" ,
1304- "local_id" : ValidValues .test_local_id ,
1312+ "SupplierSystem" : "Test" ,
13051313 "operation_requested" : "update"
13061314 },
13071315 "body" : imms ,
@@ -1316,21 +1324,23 @@ def test_validation_error_for_batch(self, mock_send_message):
13161324 "VaccineType" : "COVID19" ,
13171325 }
13181326 response = self .controller .update_immunization (aws_event )
1319- mock_send_message .assert_called_once ()
13201327 self .assertEqual (400 , response ["statusCode" ])
1328+ mock_get_supplier_permissions .assert_called_once_with ("Test" )
13211329 body = json .loads (response ["body" ])
13221330 self .assertEqual (body ["resourceType" ], "OperationOutcome" )
13231331
1324- def test_validation_superseded_number_to_give_bad_request_for_update_immunization (self ):
1332+ @patch ("fhir_controller.get_supplier_permissions" )
1333+ def test_validation_superseded_number_to_give_bad_request_for_update_immunization (self , mock_get_supplier_permissions ):
13251334 """it should return 400 if Immunization has superseded nhs number."""
1335+ mock_get_supplier_permissions .return_value = ["COVID19:update" ]
13261336 update_result = {
13271337 "diagnostics" : "Validation errors: contained[?(@.resourceType=='Patient')].identifier[0].value does not exists"
13281338 }
13291339 self .service .update_immunization .return_value = None , update_result
13301340 req_imms = '{"id": "valid-id"}'
13311341 path_id = "valid-id"
13321342 aws_event = {
1333- "headers" : {"E-Tag" : 1 , "VaccineTypePermissions" : "COVID19:update" , " SupplierSystem" : "Test" },
1343+ "headers" : {"E-Tag" : 1 , "SupplierSystem" : "Test" },
13341344 "body" : req_imms ,
13351345 "pathParameters" : {"id" : path_id },
13361346 }
@@ -1348,8 +1358,10 @@ def test_validation_superseded_number_to_give_bad_request_for_update_immunizatio
13481358 body = json .loads (response ["body" ])
13491359 self .assertEqual (body ["resourceType" ], "OperationOutcome" )
13501360
1351- def test_validation_identifier_to_give_bad_request_for_update_immunization (self ):
1361+ @patch ("fhir_controller.get_supplier_permissions" )
1362+ def test_validation_identifier_to_give_bad_request_for_update_immunization (self , mock_get_supplier_permissions ):
13521363 """it should return 400 if Identifier system and value doesn't match with the stored content."""
1364+ mock_get_supplier_permissions .return_value = ["COVID19:update" ]
13531365 req_imms = '{"id": "valid-id"}'
13541366 path_id = "valid-id"
13551367 aws_event = {
@@ -1367,8 +1379,10 @@ def test_validation_identifier_to_give_bad_request_for_update_immunization(self)
13671379 body = json .loads (response ["body" ])
13681380 self .assertEqual (body ["resourceType" ], "OperationOutcome" )
13691381
1370- def test_version_mismatch_for_update_immunization (self ):
1382+ @patch ("fhir_controller.get_supplier_permissions" )
1383+ def test_version_mismatch_for_update_immunization (self , mock_get_supplier_permissions ):
13711384 """it should return 400 if resource version mismatch"""
1385+ mock_get_supplier_permissions .return_value = ["COVID19:update" ]
13721386 update_result = {
13731387 "diagnostics" : "Validation errors: contained[?(@.resourceType=='Patient')].identifier[0].value does not exists"
13741388 }
@@ -1393,53 +1407,13 @@ def test_version_mismatch_for_update_immunization(self):
13931407 body = json .loads (response ["body" ])
13941408 self .assertEqual (body ["resourceType" ], "OperationOutcome" )
13951409
1396- def test_inconsistent_imms_id (self ):
1397- """Immunization[id] should be the same as request"""
1398- bad_json = '{"id": "a-diff-id"}'
1399- aws_event = {
1400- "headers" : {"E-Tag" : 1 , "VaccineTypePermissions" : "COVID19:create" , "SupplierSystem" : "Test" },
1401- "body" : bad_json ,
1402- "pathParameters" : {"id" : "an-id" },
1403- }
1404- response = self .controller .update_immunization (aws_event )
1405- self .assertEqual (response ["statusCode" ], 400 )
1406- self .assertIn (
1407- "The provided immunization id:an-id doesn't match with the content of the request body" ,
1408- json .loads (response ["body" ])["issue" ][0 ]["diagnostics" ],
1409- )
1410-
1411- @patch ("fhir_controller.sqs_client.send_message" )
1412- def test_inconsistent_imms_id_for_batch (self , mock_sqs_message ):
1413- """Immunization[id] should be the same as request"""
1414- bad_json = {"id" : "a-diff-id" }
1415- aws_event = {
1416- "headers" : {
1417- "E-Tag" : 1 ,
1418- "VaccineTypePermissions" : "COVID19:update" ,
1419- "SupplierSystem" : "Imms-Batch-App" ,
1420- "BatchSupplierSystem" : "Test" ,
1421- "file_key" : "test" ,
1422- "row_id" : "123" ,
1423- "created_at_formatted_string" : "2020-01-01" ,
1424- "local_id" : ValidValues .test_local_id ,
1425- "operation_requested" : "update"
1426- },
1427- "body" : bad_json ,
1428- "pathParameters" : {"id" : "an-id" },
1429- }
1430- response = self .controller .update_immunization (aws_event )
1431- mock_sqs_message .assert_called_once ()
1432- self .assertEqual (response ["statusCode" ], 400 )
1433- self .assertIn (
1434- "The provided immunization id:an-id doesn't match with the content of the request body" ,
1435- json .loads (response ["body" ])["issue" ][0 ]["diagnostics" ],
1436- )
1437-
1438- def test_missing_imms_id (self ):
1410+ @patch ("fhir_controller.get_supplier_permissions" )
1411+ def test_update_immunization_for_batch (self , mock_get_supplier_permissions ):
14391412 """Immunization[id] should exist and be the same as request"""
1413+ mock_get_supplier_permissions .return_value = ["COVID19:update" ]
14401414 bad_json = "{}"
14411415 aws_event = {
1442- "headers" : {"E-Tag" : 1 , "VaccineTypePermissions" : "COVID19:create" , " SupplierSystem" : "Test" },
1416+ "headers" : {"E-Tag" : 1 , "SupplierSystem" : "Test" },
14431417 "body" : bad_json ,
14441418 "pathParameters" : {"id" : "an-id" },
14451419 }
@@ -1450,24 +1424,10 @@ def test_missing_imms_id(self):
14501424 json .loads (response ["body" ])["issue" ][0 ]["diagnostics" ],
14511425 )
14521426
1453- def test_malformed_resource (self ):
1454- """it should return 400 if json is malformed"""
1455- bad_json = '{foo: "bar"}'
1456- aws_event = {
1457- "headers" : {"E-Tag" : 1 , "VaccineTypePermissions" : "COVID19:create" , "SupplierSystem" : "Test" },
1458- "body" : bad_json ,
1459- "pathParameters" : {"id" : "valid-id" },
1460- }
1461-
1462- response = self .controller .update_immunization (aws_event )
1463-
1464- self .assertEqual (self .service .update_immunization .call_count , 0 )
1465- self .assertEqual (response ["statusCode" ], 400 )
1466- outcome = json .loads (response ["body" ])
1467- self .assertEqual (outcome ["resourceType" ], "OperationOutcome" )
1468-
1469- def test_validate_imms_id (self ):
1427+ @patch ("fhir_controller.get_supplier_permissions" )
1428+ def test_update_immunization_for_batch_with_invalid_json (self , mock_get_supplier_permissions ):
14701429 """it should validate lambda's Immunization id"""
1430+ mock_get_supplier_permissions .return_value = ["COVID19:update" ]
14711431 aws_event = {
14721432 "headers" : {"E-Tag" : 1 , "VaccineTypePermissions" : "COVID19:create" , "SupplierSystem" : "Test" },
14731433 "pathParameters" : {"id" : "invalid %$ id" },
@@ -1480,33 +1440,6 @@ def test_validate_imms_id(self):
14801440 outcome = json .loads (response ["body" ])
14811441 self .assertEqual (outcome ["resourceType" ], "OperationOutcome" )
14821442
1483- @patch ("fhir_controller.sqs_client.send_message" )
1484- def test_validate_imms_id_for_batch (self , mock_sqs_message ):
1485- """it should validate lambda's Immunization id"""
1486- valid_json = '{"foo": "bar"}'
1487- aws_event = {
1488- "headers" : {
1489- "E-Tag" : 1 ,
1490- "VaccineTypePermissions" : "COVID19:update" ,
1491- "SupplierSystem" : "Imms-Batch-App" ,
1492- "BatchSupplierSystem" : "Test" ,
1493- "file_key" : "test" ,
1494- "row_id" : "123" ,
1495- "created_at_formatted_string" : "2020-01-01" ,
1496- "local_id" : ValidValues .test_local_id ,
1497- "operation_requested" : "update"
1498- },
1499- "pathParameters" : {"id" : "invalid %$ id" },
1500- "body" : valid_json ,
1501- }
1502-
1503- response = self .controller .update_immunization (aws_event )
1504- mock_sqs_message .assert_called_once ()
1505- self .assertEqual (self .service .update_immunization .call_count , 0 )
1506- self .assertEqual (response ["statusCode" ], 400 )
1507- outcome = json .loads (response ["body" ])
1508- self .assertEqual (outcome ["resourceType" ], "OperationOutcome" )
1509-
15101443
15111444class TestDeleteImmunization (unittest .TestCase ):
15121445 def setUp (self ):
0 commit comments