Elastic Beanstalk - Rename and Add Implementation Coverage
This commit is contained in:
parent
c32c17a13e
commit
7d524eaec9
@ -2878,15 +2878,15 @@
|
||||
- [ ] test_failover
|
||||
|
||||
## elasticbeanstalk
|
||||
0% implemented
|
||||
13% implemented
|
||||
- [ ] abort_environment_update
|
||||
- [ ] apply_environment_managed_action
|
||||
- [ ] check_dns_availability
|
||||
- [ ] compose_environments
|
||||
- [ ] create_application
|
||||
- [X] create_application
|
||||
- [ ] create_application_version
|
||||
- [ ] create_configuration_template
|
||||
- [ ] create_environment
|
||||
- [X] create_environment
|
||||
- [ ] create_platform_version
|
||||
- [ ] create_storage_location
|
||||
- [ ] delete_application
|
||||
@ -2903,13 +2903,13 @@
|
||||
- [ ] describe_environment_managed_action_history
|
||||
- [ ] describe_environment_managed_actions
|
||||
- [ ] describe_environment_resources
|
||||
- [ ] describe_environments
|
||||
- [X] describe_environments
|
||||
- [ ] describe_events
|
||||
- [ ] describe_instances_health
|
||||
- [ ] describe_platform_version
|
||||
- [ ] list_available_solution_stacks
|
||||
- [X] list_available_solution_stacks
|
||||
- [ ] list_platform_versions
|
||||
- [ ] list_tags_for_resource
|
||||
- [X] list_tags_for_resource
|
||||
- [ ] rebuild_environment
|
||||
- [ ] request_environment_info
|
||||
- [ ] restart_app_server
|
||||
@ -2921,7 +2921,7 @@
|
||||
- [ ] update_application_version
|
||||
- [ ] update_configuration_template
|
||||
- [ ] update_environment
|
||||
- [ ] update_tags_for_resource
|
||||
- [X] update_tags_for_resource
|
||||
- [ ] validate_configuration_settings
|
||||
|
||||
## elastictranscoder
|
||||
|
@ -21,7 +21,7 @@ from .datasync import mock_datasync # noqa
|
||||
from .dynamodb import mock_dynamodb, mock_dynamodb_deprecated # noqa
|
||||
from .dynamodb2 import mock_dynamodb2, mock_dynamodb2_deprecated # noqa
|
||||
from .dynamodbstreams import mock_dynamodbstreams # noqa
|
||||
from .eb import mock_eb # noqa
|
||||
from .elasticbeanstalk import mock_elasticbeanstalk # noqa
|
||||
from .ec2 import mock_ec2, mock_ec2_deprecated # noqa
|
||||
from .ec2_instance_connect import mock_ec2_instance_connect # noqa
|
||||
from .ecr import mock_ecr, mock_ecr_deprecated # noqa
|
||||
|
@ -1,4 +1,4 @@
|
||||
from .models import eb_backends
|
||||
from moto.core.models import base_decorator
|
||||
|
||||
mock_eb = base_decorator(eb_backends)
|
||||
mock_elasticbeanstalk = base_decorator(eb_backends)
|
@ -3,7 +3,7 @@ import weakref
|
||||
import boto.beanstalk
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from .exceptions import InvalidParameterValueError
|
||||
from .exceptions import InvalidParameterValueError, ResourceNotFoundException
|
||||
|
||||
|
||||
class FakeEnvironment(BaseModel):
|
||||
@ -90,6 +90,54 @@ class EBBackend(BaseBackend):
|
||||
self.applications[application_name] = new_app
|
||||
return new_app
|
||||
|
||||
def create_environment(self, app, environment_name, stack_name, tags):
|
||||
return app.create_environment(
|
||||
environment_name=environment_name,
|
||||
solution_stack_name=stack_name,
|
||||
tags=tags,
|
||||
)
|
||||
|
||||
def describe_environments(self):
|
||||
envs = []
|
||||
for app in self.applications.values():
|
||||
for env in app.environments.values():
|
||||
envs.append(env)
|
||||
return envs
|
||||
|
||||
def list_available_solution_stacks(self):
|
||||
# Implemented in response.py
|
||||
pass
|
||||
|
||||
def update_tags_for_resource(self, resource_arn, tags_to_add, tags_to_remove):
|
||||
try:
|
||||
res = self._find_environment_by_arn(resource_arn)
|
||||
except KeyError:
|
||||
raise ResourceNotFoundException(
|
||||
"Resource not found for ARN '{}'.".format(resource_arn)
|
||||
)
|
||||
|
||||
for key, value in tags_to_add.items():
|
||||
res.tags[key] = value
|
||||
|
||||
for key in tags_to_remove:
|
||||
del res.tags[key]
|
||||
|
||||
def list_tags_for_resource(self, resource_arn):
|
||||
try:
|
||||
res = self._find_environment_by_arn(resource_arn)
|
||||
except KeyError:
|
||||
raise ResourceNotFoundException(
|
||||
"Resource not found for ARN '{}'.".format(resource_arn)
|
||||
)
|
||||
return res.tags
|
||||
|
||||
def _find_environment_by_arn(self, arn):
|
||||
for app in self.applications.keys():
|
||||
for env in self.applications[app].environments.values():
|
||||
if env.environment_arn == arn:
|
||||
return env
|
||||
raise KeyError()
|
||||
|
||||
|
||||
eb_backends = dict(
|
||||
(region.name, EBBackend(region.name)) for region in boto.beanstalk.regions()
|
@ -1,7 +1,7 @@
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import tags_from_query_string
|
||||
from .models import eb_backends
|
||||
from .exceptions import InvalidParameterValueError, ResourceNotFoundException
|
||||
from .exceptions import InvalidParameterValueError
|
||||
|
||||
|
||||
class EBResponse(BaseResponse):
|
||||
@ -34,9 +34,10 @@ class EBResponse(BaseResponse):
|
||||
)
|
||||
|
||||
tags = tags_from_query_string(self.querystring, prefix="Tags.member")
|
||||
env = app.create_environment(
|
||||
env = self.backend.create_environment(
|
||||
app,
|
||||
environment_name=self._get_param("EnvironmentName"),
|
||||
solution_stack_name=self._get_param("SolutionStackName"),
|
||||
stack_name=self._get_param("SolutionStackName"),
|
||||
tags=tags,
|
||||
)
|
||||
|
||||
@ -44,11 +45,7 @@ class EBResponse(BaseResponse):
|
||||
return template.render(environment=env, region=self.backend.region,)
|
||||
|
||||
def describe_environments(self):
|
||||
envs = []
|
||||
|
||||
for app in self.backend.applications.values():
|
||||
for env in app.environments.values():
|
||||
envs.append(env)
|
||||
envs = self.backend.describe_environments()
|
||||
|
||||
template = self.response_template(EB_DESCRIBE_ENVIRONMENTS)
|
||||
return template.render(environments=envs,)
|
||||
@ -57,43 +54,19 @@ class EBResponse(BaseResponse):
|
||||
def list_available_solution_stacks():
|
||||
return EB_LIST_AVAILABLE_SOLUTION_STACKS
|
||||
|
||||
def _find_environment_by_arn(self, arn):
|
||||
for app in self.backend.applications.keys():
|
||||
for env in self.backend.applications[app].environments.values():
|
||||
if env.environment_arn == arn:
|
||||
return env
|
||||
raise KeyError()
|
||||
|
||||
def update_tags_for_resource(self):
|
||||
resource_arn = self._get_param("ResourceArn")
|
||||
try:
|
||||
res = self._find_environment_by_arn(resource_arn)
|
||||
except KeyError:
|
||||
raise ResourceNotFoundException(
|
||||
"Resource not found for ARN '{}'.".format(resource_arn)
|
||||
)
|
||||
|
||||
tags_to_add = tags_from_query_string(
|
||||
self.querystring, prefix="TagsToAdd.member"
|
||||
)
|
||||
for key, value in tags_to_add.items():
|
||||
res.tags[key] = value
|
||||
|
||||
tags_to_remove = self._get_multi_param("TagsToRemove.member")
|
||||
for key in tags_to_remove:
|
||||
del res.tags[key]
|
||||
self.backend.update_tags_for_resource(resource_arn, tags_to_add, tags_to_remove)
|
||||
|
||||
return EB_UPDATE_TAGS_FOR_RESOURCE
|
||||
|
||||
def list_tags_for_resource(self):
|
||||
resource_arn = self._get_param("ResourceArn")
|
||||
try:
|
||||
res = self._find_environment_by_arn(resource_arn)
|
||||
except KeyError:
|
||||
raise ResourceNotFoundException(
|
||||
"Resource not found for ARN '{}'.".format(resource_arn)
|
||||
)
|
||||
tags = res.tags
|
||||
tags = self.backend.list_tags_for_resource(resource_arn)
|
||||
|
||||
template = self.response_template(EB_LIST_TAGS_FOR_RESOURCE)
|
||||
return template.render(tags=tags, arn=resource_arn,)
|
@ -2,10 +2,10 @@ import boto3
|
||||
import sure # noqa
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
from moto import mock_eb
|
||||
from moto import mock_elasticbeanstalk
|
||||
|
||||
|
||||
@mock_eb
|
||||
@mock_elasticbeanstalk
|
||||
def test_create_application():
|
||||
# Create Elastic Beanstalk Application
|
||||
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
||||
@ -13,7 +13,7 @@ def test_create_application():
|
||||
app["Application"]["ApplicationName"].should.equal("myapp")
|
||||
|
||||
|
||||
@mock_eb
|
||||
@mock_elasticbeanstalk
|
||||
def test_create_application_dup():
|
||||
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
||||
conn.create_application(ApplicationName="myapp",)
|
||||
@ -22,7 +22,7 @@ def test_create_application_dup():
|
||||
)
|
||||
|
||||
|
||||
@mock_eb
|
||||
@mock_elasticbeanstalk
|
||||
def test_describe_applications():
|
||||
# Create Elastic Beanstalk Application
|
||||
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
||||
@ -33,7 +33,7 @@ def test_describe_applications():
|
||||
apps["Applications"][0]["ApplicationName"].should.equal("myapp")
|
||||
|
||||
|
||||
@mock_eb
|
||||
@mock_elasticbeanstalk
|
||||
def test_create_environment():
|
||||
# Create Elastic Beanstalk Environment
|
||||
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
||||
@ -42,7 +42,7 @@ def test_create_environment():
|
||||
env["EnvironmentName"].should.equal("myenv")
|
||||
|
||||
|
||||
@mock_eb
|
||||
@mock_elasticbeanstalk
|
||||
def test_describe_environments():
|
||||
# List Elastic Beanstalk Envs
|
||||
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
||||
@ -72,7 +72,7 @@ def tags_list_to_dict(tag_list):
|
||||
return tag_dict
|
||||
|
||||
|
||||
@mock_eb
|
||||
@mock_elasticbeanstalk
|
||||
def test_create_environment_tags():
|
||||
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
||||
conn.create_application(ApplicationName="myapp",)
|
||||
@ -88,7 +88,7 @@ def test_create_environment_tags():
|
||||
tags_list_to_dict(tags["ResourceTags"]).should.equal(env_tags)
|
||||
|
||||
|
||||
@mock_eb
|
||||
@mock_elasticbeanstalk
|
||||
def test_update_tags():
|
||||
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
||||
conn.create_application(ApplicationName="myapp",)
|
||||
@ -122,7 +122,7 @@ def test_update_tags():
|
||||
tags_list_to_dict(tags["ResourceTags"]).should.equal(total_env_tags)
|
||||
|
||||
|
||||
@mock_eb
|
||||
@mock_elasticbeanstalk
|
||||
def test_list_available_solution_stacks():
|
||||
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
||||
stacks = conn.list_available_solution_stacks()
|
||||
|
Loading…
Reference in New Issue
Block a user