def test_delete(self): event = { "RequestType": "Delete", "StackId": "1", "RequestId": "2", "LogicalResourceId": "3", "ResponseURL": "http://response" } handler = self.handler(delete=lambda self, *args: Success( "PhysicalResourceId", {"Meta": "Data"})) handler(event, context=None) (_, (url, data), kwargs), = Responder._upload_response_data.mock_calls self.assertEqual(url, "http://response") self.assertEqual( json.loads(data), { "StackId": "1", "RequestId": "2", "LogicalResourceId": "3", "Status": "SUCCESS", "PhysicalResourceId": "PhysicalResourceId", "Data": { "Meta": "Data" } }) self.assertEqual(kwargs, {})
def test_schema_validation_pass(self): event = { "RequestType": "Create", "StackId": "1", "RequestId": "2", "LogicalResourceId": "3", "ResponseURL": "http://response", "ResourceProperties": {}, "OldResourceProperties": {} } handler = self.handler(create=lambda self, *args: Success( "PhysicalResourceId", {"Meta": "Data"}), schema={}) handler(event, context=None) (_, (url, data), kwargs), = Responder._upload_response_data.mock_calls self.assertEqual(url, "http://response") self.assertEqual( json.loads(data), { "StackId": "1", "RequestId": "2", "LogicalResourceId": "3", "Status": "SUCCESS", "PhysicalResourceId": "PhysicalResourceId", "Data": { "Meta": "Data" } }) self.assertEqual(kwargs, {})
def test_schema_validation_old_resource_properties_fail(self): event = { "RequestType": "Create", "StackId": "1", "RequestId": "2", "LogicalResourceId": "3", "ResponseURL": "http://response", "ResourceProperties": { "Validating": True }, "OldResourceProperties": {} } handler = self.handler(create=lambda self, *args: Success( "PhysicalResourceId", {"Meta": "Data"}), schema={ "required": ["Validating"], "properties": { "Validating": { "enum": [True] } } }) handler(event, context=None) (_, (url, data), kwargs), = Responder._upload_response_data.mock_calls self.assertEqual(url, "http://response") self.assertEqual( json.loads(data), { "StackId": "1", "RequestId": "2", "LogicalResourceId": "3", "Status": "FAILED", "PhysicalResourceId": "n/a", "Reason": ("'Validating' is a required property\n" "\n" "Failed validating 'required' in schema:\n" " {'properties': {'Validating': {'enum': [True]}},\n" " 'required': ['Validating']}\n" "\n" "On instance:\n" " {}") }) self.assertEqual(kwargs, {})