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