add support for requestTemplates parameter in apigateway mock
This commit is contained in:
parent
ae938223d4
commit
5075f6684f
@ -27,11 +27,12 @@ class IntegrationResponse(dict):
|
|||||||
|
|
||||||
|
|
||||||
class Integration(dict):
|
class Integration(dict):
|
||||||
def __init__(self, integration_type, uri, http_method):
|
def __init__(self, integration_type, uri, http_method, request_templates=None):
|
||||||
super(Integration, self).__init__()
|
super(Integration, self).__init__()
|
||||||
self['type'] = integration_type
|
self['type'] = integration_type
|
||||||
self['uri'] = uri
|
self['uri'] = uri
|
||||||
self['httpMethod'] = http_method
|
self['httpMethod'] = http_method
|
||||||
|
self['requestTemplates'] = request_templates
|
||||||
self["integrationResponses"] = {
|
self["integrationResponses"] = {
|
||||||
"200": IntegrationResponse(200)
|
"200": IntegrationResponse(200)
|
||||||
}
|
}
|
||||||
@ -136,8 +137,8 @@ class Resource(object):
|
|||||||
def get_method(self, method_type):
|
def get_method(self, method_type):
|
||||||
return self.resource_methods[method_type]
|
return self.resource_methods[method_type]
|
||||||
|
|
||||||
def add_integration(self, method_type, integration_type, uri):
|
def add_integration(self, method_type, integration_type, uri, request_templates=None):
|
||||||
integration = Integration(integration_type, uri, method_type)
|
integration = Integration(integration_type, uri, method_type, request_templates=request_templates)
|
||||||
self.resource_methods[method_type]['methodIntegration'] = integration
|
self.resource_methods[method_type]['methodIntegration'] = integration
|
||||||
return integration
|
return integration
|
||||||
|
|
||||||
@ -290,9 +291,11 @@ class APIGatewayBackend(BaseBackend):
|
|||||||
method_response = method.delete_response(response_code)
|
method_response = method.delete_response(response_code)
|
||||||
return method_response
|
return method_response
|
||||||
|
|
||||||
def create_integration(self, function_id, resource_id, method_type, integration_type, uri):
|
def create_integration(self, function_id, resource_id, method_type, integration_type, uri,
|
||||||
|
request_templates=None):
|
||||||
resource = self.get_resource(function_id, resource_id)
|
resource = self.get_resource(function_id, resource_id)
|
||||||
integration = resource.add_integration(method_type, integration_type, uri)
|
integration = resource.add_integration(method_type, integration_type, uri,
|
||||||
|
request_templates=request_templates)
|
||||||
return integration
|
return integration
|
||||||
|
|
||||||
def get_integration(self, function_id, resource_id, method_type):
|
def get_integration(self, function_id, resource_id, method_type):
|
||||||
|
@ -107,7 +107,8 @@ class APIGatewayResponse(BaseResponse):
|
|||||||
elif self.method == 'PUT':
|
elif self.method == 'PUT':
|
||||||
integration_type = self._get_param('type')
|
integration_type = self._get_param('type')
|
||||||
uri = self._get_param('uri')
|
uri = self._get_param('uri')
|
||||||
integration_response = self.backend.create_integration(function_id, resource_id, method_type, integration_type, uri)
|
request_templates = self._get_param('requestTemplates')
|
||||||
|
integration_response = self.backend.create_integration(function_id, resource_id, method_type, integration_type, uri, request_templates=request_templates)
|
||||||
elif self.method == 'DELETE':
|
elif self.method == 'DELETE':
|
||||||
integration_response = self.backend.delete_integration(function_id, resource_id, method_type)
|
integration_response = self.backend.delete_integration(function_id, resource_id, method_type)
|
||||||
return 200, headers, json.dumps(integration_response)
|
return 200, headers, json.dumps(integration_response)
|
||||||
|
2
setup.py
2
setup.py
@ -11,6 +11,8 @@ install_requires = [
|
|||||||
"xmltodict",
|
"xmltodict",
|
||||||
"six",
|
"six",
|
||||||
"werkzeug",
|
"werkzeug",
|
||||||
|
"sure",
|
||||||
|
"freezegun"
|
||||||
]
|
]
|
||||||
|
|
||||||
extras_require = {
|
extras_require = {
|
||||||
|
@ -338,6 +338,38 @@ def test_integrations():
|
|||||||
)
|
)
|
||||||
response['resourceMethods']['GET'].shouldnt.contain("methodIntegration")
|
response['resourceMethods']['GET'].shouldnt.contain("methodIntegration")
|
||||||
|
|
||||||
|
# Create a new integration with a requestTemplates config
|
||||||
|
|
||||||
|
client.put_method(
|
||||||
|
restApiId=api_id,
|
||||||
|
resourceId=root_id,
|
||||||
|
httpMethod='POST',
|
||||||
|
authorizationType='none',
|
||||||
|
)
|
||||||
|
|
||||||
|
templates = {
|
||||||
|
# example based on http://docs.aws.amazon.com/apigateway/latest/developerguide/api-as-kinesis-proxy-export-swagger-with-extensions.html
|
||||||
|
'application/json': "{\n \"StreamName\": \"$input.params('stream-name')\",\n \"Records\": []\n}"
|
||||||
|
}
|
||||||
|
test_uri = 'http://example.com/foobar.txt'
|
||||||
|
response = client.put_integration(
|
||||||
|
restApiId=api_id,
|
||||||
|
resourceId=root_id,
|
||||||
|
httpMethod='POST',
|
||||||
|
type='HTTP',
|
||||||
|
uri=test_uri,
|
||||||
|
requestTemplates=templates
|
||||||
|
)
|
||||||
|
response['ResponseMetadata'].should.equal({'HTTPStatusCode': 200})
|
||||||
|
|
||||||
|
response = client.get_integration(
|
||||||
|
restApiId=api_id,
|
||||||
|
resourceId=root_id,
|
||||||
|
httpMethod='POST'
|
||||||
|
)
|
||||||
|
response['uri'].should.equal(test_uri)
|
||||||
|
response['requestTemplates'].should.equal(templates)
|
||||||
|
|
||||||
|
|
||||||
@mock_apigateway
|
@mock_apigateway
|
||||||
def test_integration_response():
|
def test_integration_response():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user