add integrations.
This commit is contained in:
parent
aaaddf13e8
commit
bd57233b10
@ -6,6 +6,13 @@ from moto.core.utils import iso_8601_datetime_with_milliseconds
|
||||
from .utils import create_id
|
||||
|
||||
|
||||
class Integration(dict):
|
||||
def __init__(self, integration_type, uri):
|
||||
super(Integration, self).__init__()
|
||||
self['type'] = integration_type
|
||||
self['uri'] = uri
|
||||
|
||||
|
||||
class MethodResponse(dict):
|
||||
def __init__(self, status_code):
|
||||
super(MethodResponse, self).__init__()
|
||||
@ -65,6 +72,17 @@ class Resource(object):
|
||||
def get_method(self, method_type):
|
||||
return self.resource_methods[method_type]
|
||||
|
||||
def add_integration(self, method_type, integration_type, uri):
|
||||
integration = Integration(integration_type, uri)
|
||||
self.resource_methods[method_type]['methodIntegration'] = integration
|
||||
return integration
|
||||
|
||||
def get_integration(self, method_type):
|
||||
return self.resource_methods[method_type]['methodIntegration']
|
||||
|
||||
def delete_integration(self, method_type):
|
||||
return self.resource_methods[method_type].pop('methodIntegration')
|
||||
|
||||
|
||||
class RestAPI(object):
|
||||
def __init__(self, id, name, description):
|
||||
@ -165,6 +183,19 @@ class APIGatewayBackend(BaseBackend):
|
||||
method_response = method.delete_response(response_code)
|
||||
return method_response
|
||||
|
||||
def create_integration(self, function_id, resource_id, method_type, integration_type, uri):
|
||||
resource = self.get_resource(function_id, resource_id)
|
||||
integration = resource.add_integration(method_type, integration_type, uri)
|
||||
return integration
|
||||
|
||||
def get_integration(self, function_id, resource_id, method_type):
|
||||
resource = self.get_resource(function_id, resource_id)
|
||||
return resource.get_integration(method_type)
|
||||
|
||||
def delete_integration(self, function_id, resource_id, method_type):
|
||||
resource = self.get_resource(function_id, resource_id)
|
||||
return resource.delete_integration(method_type)
|
||||
|
||||
apigateway_backends = {}
|
||||
for region_name in ['us-east-1', 'us-west-2', 'eu-west-1', 'ap-northeast-1']: # Not available in boto yet
|
||||
apigateway_backends[region_name] = APIGatewayBackend(region_name)
|
||||
|
@ -98,3 +98,22 @@ class APIGatewayResponse(BaseResponse):
|
||||
elif self.method == 'DELETE':
|
||||
method_response = self.backend.delete_method_response(function_id, resource_id, method_type, response_code)
|
||||
return 200, headers, json.dumps(method_response)
|
||||
|
||||
def integrations(self, request, full_url, headers):
|
||||
self.setup_class(request, full_url, headers)
|
||||
url_path_parts = self.path.split("/")
|
||||
function_id = url_path_parts[2]
|
||||
resource_id = url_path_parts[4]
|
||||
method_type = url_path_parts[6]
|
||||
|
||||
if self.method == 'GET':
|
||||
integration_response = self.backend.get_integration(function_id, resource_id, method_type)
|
||||
return 200, headers, json.dumps(integration_response)
|
||||
elif self.method == 'PUT':
|
||||
integration_type = self._get_param('type')
|
||||
uri = self._get_param('uri')
|
||||
integration_response = self.backend.create_integration(function_id, resource_id, method_type, integration_type, uri)
|
||||
return 200, headers, json.dumps(integration_response)
|
||||
elif self.method == 'DELETE':
|
||||
integration_response = self.backend.delete_integration(function_id, resource_id, method_type)
|
||||
return 200, headers, json.dumps(integration_response)
|
||||
|
@ -12,4 +12,5 @@ url_paths = {
|
||||
'{0}/restapis/(?P<function_id>[^/]+)/resources/(?P<resource_id>[^/]+)/?$': APIGatewayResponse().resource_individual,
|
||||
'{0}/restapis/(?P<function_id>[^/]+)/resources/(?P<resource_id>[^/]+)/methods/(?P<method_name>[^/]+)/?$': APIGatewayResponse().resource_methods,
|
||||
'{0}/restapis/(?P<function_id>[^/]+)/resources/(?P<resource_id>[^/]+)/methods/(?P<method_name>[^/]+)/responses/200$': APIGatewayResponse().resource_method_responses,
|
||||
'{0}/restapis/(?P<function_id>[^/]+)/resources/(?P<resource_id>[^/]+)/methods/(?P<method_name>[^/]+)/integration/?$': APIGatewayResponse().integrations,
|
||||
}
|
||||
|
@ -208,12 +208,6 @@ def test_integrations():
|
||||
authorizationType='none',
|
||||
)
|
||||
|
||||
client.get_method(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
httpMethod='GET'
|
||||
)
|
||||
|
||||
client.put_method_response(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
@ -228,3 +222,40 @@ def test_integrations():
|
||||
type='HTTP',
|
||||
uri='http://httpbin.org/robots.txt',
|
||||
)
|
||||
response.should.equal({
|
||||
'type': 'HTTP',
|
||||
'uri': 'http://httpbin.org/robots.txt',
|
||||
'ResponseMetadata': {'HTTPStatusCode': 200}
|
||||
})
|
||||
|
||||
response = client.get_integration(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
httpMethod='GET'
|
||||
)
|
||||
response.should.equal({
|
||||
'type': 'HTTP',
|
||||
'uri': 'http://httpbin.org/robots.txt',
|
||||
'ResponseMetadata': {'HTTPStatusCode': 200}
|
||||
})
|
||||
|
||||
response = client.get_resource(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
)
|
||||
response['resourceMethods']['GET']['methodIntegration'].should.equal({
|
||||
'type': 'HTTP',
|
||||
'uri': 'http://httpbin.org/robots.txt'
|
||||
})
|
||||
|
||||
client.delete_integration(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
httpMethod='GET'
|
||||
)
|
||||
|
||||
response = client.get_resource(
|
||||
restApiId=api_id,
|
||||
resourceId=root_id,
|
||||
)
|
||||
response['resourceMethods']['GET'].shouldnt.contain("methodIntegration")
|
||||
|
Loading…
Reference in New Issue
Block a user