APIGateway - rework tests to work with botocore 1.22 (#4451)

This commit is contained in:
Bert Blommers 2021-10-20 22:02:20 +00:00 committed by GitHub
parent fff69b9faa
commit 125936d269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 51 deletions

View File

@ -1330,49 +1330,6 @@ def test_create_simple_deployment_with_post_method():
assert "id" in deployment
@mock_apigateway
# https://github.com/aws/aws-sdk-js/issues/2588
def test_put_integration_response_requires_responseTemplate():
client = boto3.client("apigateway", region_name="us-west-2")
response = client.create_rest_api(name="my_api", description="this is my api")
api_id = response["id"]
resources = client.get_resources(restApiId=api_id)
root_id = [resource for resource in resources["items"] if resource["path"] == "/"][
0
]["id"]
client.put_method(
restApiId=api_id, resourceId=root_id, httpMethod="GET", authorizationType="NONE"
)
client.put_method_response(
restApiId=api_id, resourceId=root_id, httpMethod="GET", statusCode="200"
)
client.put_integration(
restApiId=api_id,
resourceId=root_id,
httpMethod="GET",
type="HTTP",
uri="http://httpbin.org/robots.txt",
integrationHttpMethod="POST",
)
with pytest.raises(ClientError) as ex:
client.put_integration_response(
restApiId=api_id, resourceId=root_id, httpMethod="GET", statusCode="200"
)
ex.value.response["Error"]["Code"].should.equal("BadRequestException")
ex.value.response["Error"]["Message"].should.equal("Invalid request input")
# Works fine if responseTemplate is defined
client.put_integration_response(
restApiId=api_id,
resourceId=root_id,
httpMethod="GET",
statusCode="200",
responseTemplates={},
)
@mock_apigateway
def test_put_integration_response_with_response_template():
client = boto3.client("apigateway", region_name="us-west-2")
@ -1398,14 +1355,6 @@ def test_put_integration_response_with_response_template():
integrationHttpMethod="POST",
)
with pytest.raises(ClientError) as ex:
client.put_integration_response(
restApiId=api_id, resourceId=root_id, httpMethod="GET", statusCode="200"
)
ex.value.response["Error"]["Code"].should.equal("BadRequestException")
ex.value.response["Error"]["Message"].should.equal("Invalid request input")
client.put_integration_response(
restApiId=api_id,
resourceId=root_id,

View File

@ -122,3 +122,33 @@ def test_create_usage_plans_key_non_existent_api_key():
data=json.dumps({"keyId": "non-existent", "keyType": "API_KEY"}),
)
res.status_code.should.equal(404)
def test_put_integration_response_without_body():
# Method under test: put_integration_response
#
# Moto/Boto3 requires the responseTemplates-parameter to have a value - even if it's an empty dict
# Botocore <= 1.21.65 does not automatically pass this parameter, so Moto will successfully throw an error if it's not supplied
# However: As of botocore >= 1.22.0, the responseTemplates is automatically supplied - which means we can no longer test this using boto3
#
# This was the equivalent boto3-test:
# with pytest.raises(ClientError) as ex:
# client.put_integration_response(
# restApiId=api_id, resourceId=root_id, httpMethod="GET", statusCode="200"
# )
# ex.value.response["Error"]["Code"].should.equal("BadRequestException")
# ex.value.response["Error"]["Message"].should.equal("Invalid request input")
#
# As a workaround, we can create a PUT-request without body, which will force the error
# Related: # https://github.com/aws/aws-sdk-js/issues/2588
#
backend = server.create_backend_app("apigateway")
test_client = backend.test_client()
res = test_client.put(
"/restapis/f_id/resources/r_id/methods/m_id/integration/responses/200/"
)
res.status_code.should.equal(400)
json.loads(res.data).should.equal(
{"__type": "BadRequestException", "message": "Invalid request input"}
)