Added more tests and coverage
This commit is contained in:
parent
856c07de63
commit
af57cfc7ec
4 changed files with 103 additions and 23 deletions
|
|
@ -120,6 +120,16 @@ class ApiKeyAlreadyExists(RESTError):
|
|||
"ConflictException", "API Key already exists"
|
||||
)
|
||||
|
||||
|
||||
class InvalidDomainName(BadRequestException):
|
||||
code = 404
|
||||
|
||||
def __init__(self):
|
||||
super(InvalidDomainName, self).__init__(
|
||||
"BadRequestException", "No Domain Name specified"
|
||||
)
|
||||
|
||||
|
||||
class DomainNameNotFound(RESTError):
|
||||
code = 404
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ from .exceptions import (
|
|||
NoIntegrationDefined,
|
||||
NoMethodDefined,
|
||||
ApiKeyAlreadyExists,
|
||||
DomainNameNotFound
|
||||
DomainNameNotFound,
|
||||
InvalidDomainName
|
||||
)
|
||||
|
||||
STAGE_URL = "https://{api_id}.execute-api.{region_name}.amazonaws.com/{stage_name}"
|
||||
|
|
@ -1047,25 +1048,26 @@ class APIGatewayBackend(BaseBackend):
|
|||
except Exception:
|
||||
return False
|
||||
|
||||
def create_domain_name(self, domain_name,
|
||||
certificate_name=None, tags=None,
|
||||
certificate_arn=None, certificate_body=None,
|
||||
certificate_private_key=None,
|
||||
def create_domain_name(self,domain_name,
|
||||
certificate_name=None,certificate_private_key=None,
|
||||
tags=None, certificate_arn=None,
|
||||
certificate_body=None,
|
||||
certificate_chain=None,
|
||||
regional_certificate_name=None,
|
||||
regional_certificate_arn=None,
|
||||
endpoint_configuration=None,
|
||||
security_policy=None,
|
||||
generate_cli_skeleton=None):
|
||||
|
||||
if not domain_name:
|
||||
raise DomainNameNotFound()
|
||||
raise InvalidDomainName()
|
||||
|
||||
new_domain_name = DomainName(
|
||||
domain_name=domain_name,
|
||||
certificate_name=certificate_name,
|
||||
certificate_private_key=certificate_private_key,
|
||||
certificate_arn=certificate_arn,
|
||||
certificate_body=certificate_body,
|
||||
certificate_private_key=certificate_private_key,
|
||||
certificate_chain=certificate_chain,
|
||||
regional_certificate_name=regional_certificate_name,
|
||||
regional_certificate_arn=regional_certificate_arn,
|
||||
|
|
@ -1081,7 +1083,11 @@ class APIGatewayBackend(BaseBackend):
|
|||
return list(self.domain_names.values())
|
||||
|
||||
def get_domain_name(self, domain_name):
|
||||
return self.domain_names[domain_name]
|
||||
domain_info = self.domain_names.get(domain_name)
|
||||
if domain_info is None:
|
||||
raise DomainNameNotFound
|
||||
else:
|
||||
return self.domain_names[domain_name]
|
||||
|
||||
|
||||
apigateway_backends = {}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ from .exceptions import (
|
|||
AuthorizerNotFoundException,
|
||||
StageNotFoundException,
|
||||
ApiKeyAlreadyExists,
|
||||
DomainNameNotFound,
|
||||
InvalidDomainName
|
||||
)
|
||||
|
||||
API_KEY_SOURCES = ["AUTHORIZER", "HEADER"]
|
||||
|
|
@ -561,17 +563,22 @@ class APIGatewayResponse(BaseResponse):
|
|||
"generateCliSkeleton"
|
||||
)
|
||||
domain_name_resp = self.backend.create_domain_name(
|
||||
domain_name, certificate_name, tags, certificate_arn,
|
||||
certificate_body, certificate_private_key,
|
||||
certificate_chain, regional_certificate_name,
|
||||
regional_certificate_arn, endpoint_configuration,
|
||||
security_policy, generate_cli_skeleton
|
||||
domain_name, certificate_name,
|
||||
certificate_private_key,tags, certificate_arn,
|
||||
certificate_body, certificate_chain,
|
||||
regional_certificate_name, regional_certificate_arn,
|
||||
endpoint_configuration, security_policy,
|
||||
generate_cli_skeleton
|
||||
)
|
||||
|
||||
return 200, {}, json.dumps(domain_name_resp)
|
||||
except BadRequestException as e:
|
||||
return self.error(
|
||||
"com.amazonaws.dynamodb.v20111205#BadRequestException", e.message
|
||||
|
||||
except InvalidDomainName as error:
|
||||
return (
|
||||
error.code,
|
||||
{},
|
||||
'{{"message":"{0}","code":"{1}"}}'.format(
|
||||
error.message, error.error_type
|
||||
),
|
||||
)
|
||||
|
||||
def domain_name_induvidual(self, request, full_url, headers):
|
||||
|
|
@ -580,9 +587,19 @@ class APIGatewayResponse(BaseResponse):
|
|||
url_path_parts = self.path.split("/")
|
||||
domain_name = url_path_parts[2]
|
||||
domain_names={}
|
||||
try:
|
||||
if self.method == "GET":
|
||||
if domain_name is not None:
|
||||
domain_names = self.backend.get_domain_name(domain_name)
|
||||
return 200, {}, json.dumps(domain_names)
|
||||
|
||||
except DomainNameNotFound as error:
|
||||
return (
|
||||
error.code,
|
||||
{},
|
||||
'{{"message":"{0}","code":"{1}"}}'.format(
|
||||
error.message, error.error_type
|
||||
),
|
||||
)
|
||||
|
||||
if self.method == "GET":
|
||||
if domain_name is not None:
|
||||
domain_names = self.backend.get_domain_name(domain_name)
|
||||
|
||||
return 200, {}, json.dumps(domain_names)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue