Ejemplo n.º 1
0
 def test_if_request_is_valid_with_no_validator(self):
     ctx = ApiInvocationContext("POST", "/", b"", {})
     ctx.api_id = "deadbeef"
     ctx.resource = {
         "resourceMethods": {
             "POST": {
                 "requestValidatorId": " "
             }
         }
     }
     validator = RequestValidator(ctx, None)
     self.assertTrue(validator.is_request_valid())
Ejemplo n.º 2
0
 def test_request_validate_body_with_no_request_model(self):
     apigateway_client = self._mock_client()
     apigateway_client.get_request_validator.return_value = {
         "validateRequestBody": True
     }
     ctx = ApiInvocationContext("POST", "/", '{"id":"1"}', {})
     ctx.api_id = "deadbeef"
     ctx.resource = {
         "resourceMethods": {
             "POST": {
                 "requestValidatorId": "112233",
                 "requestModels": None,
             }
         }
     }
     validator = RequestValidator(ctx, apigateway_client)
     self.assertFalse(validator.is_request_valid())
Ejemplo n.º 3
0
 def test_request_validate_body_with_no_model_for_schema_name(self):
     apigateway_client = Mock(boto3.client(service_name="apigateway"))
     apigateway_client.get_request_validator.return_value = {
         "validateRequestBody": True
     }
     apigateway_client.get_model.return_value = None
     ctx = ApiInvocationContext("POST", "/", '{"id":"1"}', {})
     ctx.api_id = "deadbeef"
     ctx.resource = {
         "resourceMethods": {
             "POST": {
                 "requestValidatorId": "112233",
                 "requestModels": {
                     "application/json": "schemaName"
                 },
             }
         }
     }
     validator = RequestValidator(ctx, apigateway_client)
     self.assertFalse(validator.is_request_valid())
Ejemplo n.º 4
0
 def test_if_request_has_body_validator(self):
     apigateway_client = self._mock_client()
     apigateway_client.get_request_validator.return_value = {
         "validateRequestBody": True
     }
     apigateway_client.get_model.return_value = {
         "schema": '{"type": "object"}'
     }
     ctx = ApiInvocationContext("POST", "/", '{"id":"1"}', {})
     ctx.api_id = "deadbeef"
     ctx.resource = {
         "resourceMethods": {
             "POST": {
                 "requestValidatorId": "112233",
                 "requestModels": {
                     "application/json": "schemaName"
                 },
             }
         }
     }
     validator = RequestValidator(ctx, apigateway_client)
     self.assertTrue(validator.is_request_valid())
Ejemplo n.º 5
0
 def test_if_request_is_valid_with_no_matching_method(self):
     ctx = ApiInvocationContext("POST", "/", b"", {})
     ctx.resource = {"resourceMethods": {"GET": {}}}
     validator = RequestValidator(ctx, None)
     self.assertTrue(validator.is_request_valid())
Ejemplo n.º 6
0
 def test_if_request_is_valid_with_no_resource_methods(self):
     ctx = ApiInvocationContext("POST", "/", b"", {})
     validator = RequestValidator(ctx, None)
     self.assertTrue(validator.is_request_valid())