Make API Gateway tests Python2/3 compatible
This commit is contained in:
parent
2d32ee18a6
commit
f0e2d44c5d
@ -8,7 +8,10 @@ import requests
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from boto3.session import Session
|
from boto3.session import Session
|
||||||
from urlparse import urlparse
|
try:
|
||||||
|
from urlparse import urlparse
|
||||||
|
except ImportError:
|
||||||
|
from urllib.parse import urlparse
|
||||||
import responses
|
import responses
|
||||||
from moto.core import BaseBackend, BaseModel
|
from moto.core import BaseBackend, BaseModel
|
||||||
from .utils import create_id
|
from .utils import create_id
|
||||||
@ -728,16 +731,15 @@ class APIGatewayBackend(BaseBackend):
|
|||||||
stage_variables = {}
|
stage_variables = {}
|
||||||
api = self.get_rest_api(function_id)
|
api = self.get_rest_api(function_id)
|
||||||
methods = [
|
methods = [
|
||||||
res.resource_methods.values()[0] for res in self.list_resources(function_id)
|
list(res.resource_methods.values()) for res in self.list_resources(function_id)
|
||||||
]
|
][0]
|
||||||
if not any(methods):
|
if not any(methods):
|
||||||
raise NoMethodDefined()
|
raise NoMethodDefined()
|
||||||
method_integrations = [
|
method_integrations = [
|
||||||
method["methodIntegration"]
|
method["methodIntegration"] if "methodIntegration" in method else None
|
||||||
for method in methods
|
for method in methods
|
||||||
if "methodIntegration" in method
|
|
||||||
]
|
]
|
||||||
if not all(method_integrations):
|
if not any(method_integrations):
|
||||||
raise NoIntegrationDefined()
|
raise NoIntegrationDefined()
|
||||||
deployment = api.create_deployment(name, description, stage_variables)
|
deployment = api.create_deployment(name, description, stage_variables)
|
||||||
return deployment
|
return deployment
|
||||||
|
@ -814,7 +814,7 @@ def test_put_integration_response_requires_responseTemplate():
|
|||||||
# Works fine if responseTemplate is defined
|
# Works fine if responseTemplate is defined
|
||||||
client.put_integration_response(
|
client.put_integration_response(
|
||||||
restApiId=api_id,
|
restApiId=api_id,
|
||||||
resourceId=resource["id"],
|
resourceId=root_id,
|
||||||
httpMethod="GET",
|
httpMethod="GET",
|
||||||
statusCode="200",
|
statusCode="200",
|
||||||
responseTemplates={},
|
responseTemplates={},
|
||||||
@ -1018,15 +1018,15 @@ def test_delete_stage():
|
|||||||
variables={"env": "dev"},
|
variables={"env": "dev"},
|
||||||
)
|
)
|
||||||
stages = client.get_stages(restApiId=api_id)["item"]
|
stages = client.get_stages(restApiId=api_id)["item"]
|
||||||
[stage["stageName"] for stage in stages].should.equal(
|
sorted([stage["stageName"] for stage in stages]).should.equal(
|
||||||
[new_stage_name, new_stage_name_with_vars, stage_name]
|
sorted([new_stage_name, new_stage_name_with_vars, stage_name])
|
||||||
)
|
)
|
||||||
# delete stage
|
# delete stage
|
||||||
response = client.delete_stage(restApiId=api_id, stageName=new_stage_name_with_vars)
|
response = client.delete_stage(restApiId=api_id, stageName=new_stage_name_with_vars)
|
||||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(202)
|
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(202)
|
||||||
# verify other stage still exists
|
# verify other stage still exists
|
||||||
stages = client.get_stages(restApiId=api_id)["item"]
|
stages = client.get_stages(restApiId=api_id)["item"]
|
||||||
[stage["stageName"] for stage in stages].should.equal([new_stage_name, stage_name])
|
sorted([stage["stageName"] for stage in stages]).should.equal(sorted([new_stage_name, stage_name]))
|
||||||
|
|
||||||
|
|
||||||
@mock_apigateway
|
@mock_apigateway
|
||||||
|
Loading…
x
Reference in New Issue
Block a user