Add minimal mocking of elasticbeanstalk:create_environment, describe_environments and list_available_solution_stacks
This commit is contained in:
parent
336f50349a
commit
6f23a39fc2
@ -1,12 +1,37 @@
|
|||||||
|
import weakref
|
||||||
|
|
||||||
import boto.beanstalk
|
import boto.beanstalk
|
||||||
|
|
||||||
from moto.core import BaseBackend, BaseModel
|
from moto.core import BaseBackend, BaseModel
|
||||||
from .exceptions import InvalidParameterValueError
|
from .exceptions import InvalidParameterValueError
|
||||||
|
|
||||||
|
|
||||||
|
class FakeEnvironment(BaseModel):
|
||||||
|
def __init__(self, application, environment_name):
|
||||||
|
self.environment_name = environment_name
|
||||||
|
self.application = weakref.proxy(application) # weakref to break circular dependencies
|
||||||
|
|
||||||
|
@property
|
||||||
|
def application_name(self):
|
||||||
|
return self.application.application_name
|
||||||
|
|
||||||
|
|
||||||
class FakeApplication(BaseModel):
|
class FakeApplication(BaseModel):
|
||||||
def __init__(self, application_name):
|
def __init__(self, application_name):
|
||||||
self.application_name = application_name
|
self.application_name = application_name
|
||||||
|
self.environments = dict()
|
||||||
|
|
||||||
|
def create_environment(self, environment_name):
|
||||||
|
if environment_name in self.environments:
|
||||||
|
raise InvalidParameterValueError
|
||||||
|
|
||||||
|
env = FakeEnvironment(
|
||||||
|
application=self,
|
||||||
|
environment_name=environment_name,
|
||||||
|
)
|
||||||
|
self.environments[environment_name] = env
|
||||||
|
|
||||||
|
return env
|
||||||
|
|
||||||
|
|
||||||
class EBBackend(BaseBackend):
|
class EBBackend(BaseBackend):
|
||||||
|
1297
moto/eb/responses.py
1297
moto/eb/responses.py
File diff suppressed because it is too large
Load Diff
@ -37,3 +37,44 @@ def test_describe_applications():
|
|||||||
apps = conn.describe_applications()
|
apps = conn.describe_applications()
|
||||||
len(apps['Applications']).should.equal(1)
|
len(apps['Applications']).should.equal(1)
|
||||||
apps['Applications'][0]['ApplicationName'].should.equal('myapp')
|
apps['Applications'][0]['ApplicationName'].should.equal('myapp')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_eb
|
||||||
|
def test_create_environment():
|
||||||
|
# Create Elastic Beanstalk Environment
|
||||||
|
conn = boto3.client('elasticbeanstalk', region_name='us-east-1')
|
||||||
|
app = conn.create_application(
|
||||||
|
ApplicationName="myapp",
|
||||||
|
)
|
||||||
|
env = conn.create_environment(
|
||||||
|
ApplicationName="myapp",
|
||||||
|
EnvironmentName="myenv",
|
||||||
|
)
|
||||||
|
env['EnvironmentName'].should.equal("myenv")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_eb
|
||||||
|
def test_describe_environments():
|
||||||
|
# List Elastic Beanstalk Envs
|
||||||
|
conn = boto3.client('elasticbeanstalk', region_name='us-east-1')
|
||||||
|
conn.create_application(
|
||||||
|
ApplicationName="myapp",
|
||||||
|
)
|
||||||
|
conn.create_environment(
|
||||||
|
ApplicationName="myapp",
|
||||||
|
EnvironmentName="myenv",
|
||||||
|
)
|
||||||
|
|
||||||
|
envs = conn.describe_environments()
|
||||||
|
envs = envs['Environments']
|
||||||
|
len(envs).should.equal(1)
|
||||||
|
envs[0]['ApplicationName'].should.equal('myapp')
|
||||||
|
envs[0]['EnvironmentName'].should.equal('myenv')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_eb
|
||||||
|
def test_list_available_solution_stacks():
|
||||||
|
conn = boto3.client('elasticbeanstalk', region_name='us-east-1')
|
||||||
|
stacks = conn.list_available_solution_stacks()
|
||||||
|
len(stacks['SolutionStacks']).should.be.greater_than(0)
|
||||||
|
len(stacks['SolutionStacks']).should.be.equal(len(stacks['SolutionStackDetails']))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user