2022-02-18 23:31:33 +00:00
|
|
|
import boto3
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from botocore.exceptions import ClientError
|
|
|
|
from moto import mock_apigateway
|
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_put_gateway_response_minimal():
|
|
|
|
client = boto3.client("apigateway", region_name="us-east-2")
|
|
|
|
api_id = client.create_rest_api(name="my_api", description="d")["id"]
|
|
|
|
|
|
|
|
resp = client.put_gateway_response(restApiId=api_id, responseType="DEFAULT_4XX")
|
|
|
|
|
2023-06-07 09:46:18 +00:00
|
|
|
assert resp["responseType"] == "DEFAULT_4XX"
|
|
|
|
assert resp["defaultResponse"] is False
|
2022-02-18 23:31:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_put_gateway_response():
|
|
|
|
client = boto3.client("apigateway", region_name="us-east-2")
|
|
|
|
api_id = client.create_rest_api(name="my_api", description="d")["id"]
|
|
|
|
|
|
|
|
resp = client.put_gateway_response(
|
|
|
|
restApiId=api_id,
|
|
|
|
responseType="DEFAULT_4XX",
|
|
|
|
statusCode="401",
|
|
|
|
responseParameters={"gatewayresponse.header.Authorization": "'Basic'"},
|
|
|
|
responseTemplates={
|
|
|
|
"application/xml": "#set($inputRoot = $input.path('$'))\n{ }"
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-06-07 09:46:18 +00:00
|
|
|
assert resp["responseType"] == "DEFAULT_4XX"
|
|
|
|
assert resp["defaultResponse"] is False
|
|
|
|
assert resp["statusCode"] == "401"
|
|
|
|
assert resp["responseParameters"] == {
|
|
|
|
"gatewayresponse.header.Authorization": "'Basic'"
|
|
|
|
}
|
|
|
|
assert resp["responseTemplates"] == {
|
|
|
|
"application/xml": "#set($inputRoot = $input.path('$'))\n{ }"
|
|
|
|
}
|
2022-02-18 23:31:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_get_gateway_response_minimal():
|
|
|
|
client = boto3.client("apigateway", region_name="ap-southeast-1")
|
|
|
|
api_id = client.create_rest_api(name="my_api", description="d")["id"]
|
|
|
|
|
|
|
|
client.put_gateway_response(restApiId=api_id, responseType="DEFAULT_4XX")
|
|
|
|
|
|
|
|
resp = client.get_gateway_response(restApiId=api_id, responseType="DEFAULT_4XX")
|
|
|
|
|
2023-06-07 09:46:18 +00:00
|
|
|
assert resp["responseType"] == "DEFAULT_4XX"
|
|
|
|
assert resp["defaultResponse"] is False
|
2022-02-18 23:31:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_get_gateway_response():
|
|
|
|
client = boto3.client("apigateway", region_name="us-east-2")
|
|
|
|
api_id = client.create_rest_api(name="my_api", description="d")["id"]
|
|
|
|
|
|
|
|
client.put_gateway_response(
|
|
|
|
restApiId=api_id,
|
|
|
|
responseType="DEFAULT_4XX",
|
|
|
|
statusCode="401",
|
|
|
|
responseParameters={"gatewayresponse.header.Authorization": "'Basic'"},
|
|
|
|
responseTemplates={
|
|
|
|
"application/xml": "#set($inputRoot = $input.path('$'))\n{ }"
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
resp = client.get_gateway_response(restApiId=api_id, responseType="DEFAULT_4XX")
|
|
|
|
|
2023-06-07 09:46:18 +00:00
|
|
|
assert resp["responseType"] == "DEFAULT_4XX"
|
|
|
|
assert resp["defaultResponse"] is False
|
|
|
|
assert resp["statusCode"] == "401"
|
|
|
|
assert resp["responseParameters"] == {
|
|
|
|
"gatewayresponse.header.Authorization": "'Basic'"
|
|
|
|
}
|
|
|
|
assert resp["responseTemplates"] == {
|
|
|
|
"application/xml": "#set($inputRoot = $input.path('$'))\n{ }"
|
|
|
|
}
|
2022-02-18 23:31:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_get_gateway_response_unknown():
|
|
|
|
client = boto3.client("apigateway", region_name="us-east-2")
|
|
|
|
api_id = client.create_rest_api(name="my_api", description="d")["id"]
|
|
|
|
|
|
|
|
with pytest.raises(ClientError) as exc:
|
|
|
|
client.get_gateway_response(restApiId=api_id, responseType="DEFAULT_4XX")
|
|
|
|
err = exc.value.response["Error"]
|
2023-06-07 09:46:18 +00:00
|
|
|
assert err["Code"] == "NotFoundException"
|
2022-02-18 23:31:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_get_gateway_responses_empty():
|
|
|
|
client = boto3.client("apigateway", region_name="ap-southeast-1")
|
|
|
|
api_id = client.create_rest_api(name="my_api", description="d")["id"]
|
|
|
|
resp = client.get_gateway_responses(restApiId=api_id)
|
|
|
|
|
2023-06-07 09:46:18 +00:00
|
|
|
assert resp["items"] == []
|
2022-02-18 23:31:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_get_gateway_responses():
|
|
|
|
client = boto3.client("apigateway", region_name="ap-southeast-1")
|
|
|
|
api_id = client.create_rest_api(name="my_api", description="d")["id"]
|
|
|
|
client.put_gateway_response(restApiId=api_id, responseType="DEFAULT_4XX")
|
|
|
|
client.put_gateway_response(
|
|
|
|
restApiId=api_id, responseType="DEFAULT_5XX", statusCode="503"
|
|
|
|
)
|
|
|
|
|
|
|
|
resp = client.get_gateway_responses(restApiId=api_id)
|
2023-06-07 09:46:18 +00:00
|
|
|
assert len(resp["items"]) == 2
|
2022-02-18 23:31:33 +00:00
|
|
|
|
2023-06-07 09:46:18 +00:00
|
|
|
assert {"responseType": "DEFAULT_4XX", "defaultResponse": False} in resp["items"]
|
|
|
|
assert {
|
|
|
|
"responseType": "DEFAULT_5XX",
|
|
|
|
"defaultResponse": False,
|
|
|
|
"statusCode": "503",
|
|
|
|
} in resp["items"]
|
2022-02-18 23:31:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigateway
|
|
|
|
def test_delete_gateway_response():
|
|
|
|
client = boto3.client("apigateway", region_name="ap-southeast-1")
|
|
|
|
api_id = client.create_rest_api(name="my_api", description="d")["id"]
|
|
|
|
client.put_gateway_response(restApiId=api_id, responseType="DEFAULT_4XX")
|
|
|
|
client.put_gateway_response(
|
|
|
|
restApiId=api_id, responseType="DEFAULT_5XX", statusCode="503"
|
|
|
|
)
|
|
|
|
|
|
|
|
resp = client.get_gateway_responses(restApiId=api_id)
|
2023-06-07 09:46:18 +00:00
|
|
|
assert len(resp["items"]) == 2
|
2022-02-18 23:31:33 +00:00
|
|
|
|
2023-06-07 09:46:18 +00:00
|
|
|
client.delete_gateway_response(restApiId=api_id, responseType="DEFAULT_5XX")
|
2022-02-18 23:31:33 +00:00
|
|
|
|
|
|
|
resp = client.get_gateway_responses(restApiId=api_id)
|
2023-06-07 09:46:18 +00:00
|
|
|
assert len(resp["items"]) == 1
|
|
|
|
assert {"responseType": "DEFAULT_4XX", "defaultResponse": False} in resp["items"]
|