2022-11-27 22:25:56 +00:00
|
|
|
import boto3
|
|
|
|
import botocore.exceptions
|
2023-11-30 15:55:51 +00:00
|
|
|
import pytest
|
|
|
|
|
2022-11-27 22:25:56 +00:00
|
|
|
from moto import mock_apigatewayv2
|
|
|
|
|
|
|
|
|
|
|
|
@mock_apigatewayv2
|
|
|
|
def test_create_domain_name():
|
|
|
|
client = boto3.client("apigatewayv2", region_name="us-east-1")
|
|
|
|
domain_name = "dev"
|
|
|
|
tags = {"tag": "it"}
|
|
|
|
expected_keys = [
|
|
|
|
"DomainName",
|
|
|
|
"ApiMappingSelectionExpression",
|
|
|
|
"DomainNameConfigurations",
|
|
|
|
"MutualTlsAuthentication",
|
|
|
|
"Tags",
|
|
|
|
]
|
|
|
|
|
|
|
|
post_resp = client.create_domain_name(DomainName=domain_name, Tags=tags)
|
|
|
|
get_resp = client.get_domain_name(DomainName=domain_name)
|
|
|
|
|
|
|
|
# check post response has all keys
|
|
|
|
for key in expected_keys:
|
2023-06-08 11:40:10 +00:00
|
|
|
assert key in post_resp
|
2022-11-27 22:25:56 +00:00
|
|
|
|
|
|
|
# check get response has all keys
|
|
|
|
for key in expected_keys:
|
2023-06-08 11:40:10 +00:00
|
|
|
assert key in get_resp
|
2022-11-27 22:25:56 +00:00
|
|
|
|
|
|
|
# check that values are equal for post and get of same resource
|
|
|
|
for key in expected_keys:
|
2023-06-08 11:40:10 +00:00
|
|
|
assert post_resp.get(key) == get_resp.get(key)
|
2022-11-27 22:25:56 +00:00
|
|
|
|
|
|
|
# ensure known values are set correct in post response
|
2023-06-08 11:40:10 +00:00
|
|
|
assert post_resp.get("DomainName") == domain_name
|
|
|
|
assert post_resp.get("Tags") == tags
|
2022-11-27 22:25:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigatewayv2
|
|
|
|
def test_create_domain_name_already_exists():
|
|
|
|
client = boto3.client("apigatewayv2", region_name="us-east-1")
|
|
|
|
client.create_domain_name(DomainName="exists.io")
|
|
|
|
|
|
|
|
with pytest.raises(botocore.exceptions.ClientError) as exc:
|
|
|
|
client.create_domain_name(DomainName="exists.io")
|
|
|
|
|
|
|
|
err = exc.value.response["Error"]
|
2023-06-08 11:40:10 +00:00
|
|
|
assert err["Code"] == "ConflictException"
|
|
|
|
assert err["Message"] == "The domain name resource already exists."
|
2022-11-27 22:25:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigatewayv2
|
|
|
|
def test_get_domain_names():
|
|
|
|
client = boto3.client("apigatewayv2", region_name="us-east-1")
|
|
|
|
dev_domain = client.create_domain_name(DomainName="dev.service.io")
|
|
|
|
prod_domain = client.create_domain_name(DomainName="prod.service.io")
|
|
|
|
|
|
|
|
# sanity check responses
|
2023-06-08 11:40:10 +00:00
|
|
|
assert dev_domain["DomainName"] == "dev.service.io"
|
|
|
|
assert prod_domain["DomainName"] == "prod.service.io"
|
2022-11-27 22:25:56 +00:00
|
|
|
|
|
|
|
# make comparable
|
|
|
|
del dev_domain["ResponseMetadata"]
|
|
|
|
del prod_domain["ResponseMetadata"]
|
|
|
|
|
|
|
|
get_resp = client.get_domain_names()
|
2023-06-08 11:40:10 +00:00
|
|
|
assert "Items" in get_resp
|
|
|
|
assert dev_domain in get_resp.get("Items")
|
|
|
|
assert prod_domain in get_resp.get("Items")
|
2022-11-27 22:25:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigatewayv2
|
|
|
|
def test_delete_domain_name():
|
|
|
|
client = boto3.client("apigatewayv2", region_name="ap-southeast-1")
|
|
|
|
post_resp = client.create_domain_name(DomainName="dev.service.io")
|
|
|
|
client.delete_domain_name(DomainName="dev.service.io")
|
|
|
|
get_resp = client.get_domain_names()
|
|
|
|
|
|
|
|
del post_resp["ResponseMetadata"]
|
2023-06-08 11:40:10 +00:00
|
|
|
assert "Items" in get_resp
|
|
|
|
assert post_resp not in get_resp.get("Items")
|
2022-11-27 22:25:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_apigatewayv2
|
|
|
|
def test_delete_domain_name_dne():
|
|
|
|
client = boto3.client("apigatewayv2", region_name="ap-southeast-1")
|
|
|
|
with pytest.raises(botocore.exceptions.ClientError) as exc:
|
|
|
|
client.delete_domain_name(DomainName="dne.io")
|
|
|
|
|
|
|
|
err = exc.value.response["Error"]
|
2023-06-08 11:40:10 +00:00
|
|
|
assert err["Code"] == "NotFoundException"
|
|
|
|
assert (
|
|
|
|
err["Message"]
|
|
|
|
== "The domain name resource specified in the request was not found."
|
2022-11-27 22:25:56 +00:00
|
|
|
)
|