2019-09-03 12:54:46 +00:00
|
|
|
import boto3
|
2023-07-20 09:36:51 +00:00
|
|
|
import pytest
|
2019-09-03 14:10:32 +00:00
|
|
|
from botocore.exceptions import ClientError
|
|
|
|
|
2020-03-30 13:08:22 +00:00
|
|
|
from moto import mock_elasticbeanstalk
|
2019-09-03 12:54:46 +00:00
|
|
|
|
|
|
|
|
2020-03-30 13:08:22 +00:00
|
|
|
@mock_elasticbeanstalk
|
2019-09-03 14:10:32 +00:00
|
|
|
def test_create_application():
|
2019-09-03 12:54:46 +00:00
|
|
|
# Create Elastic Beanstalk Application
|
2020-03-30 12:42:00 +00:00
|
|
|
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
|
|
|
app = conn.create_application(ApplicationName="myapp")
|
2023-07-20 09:36:51 +00:00
|
|
|
assert app["Application"]["ApplicationName"] == "myapp"
|
|
|
|
assert "myapp" in app["Application"]["ApplicationArn"]
|
2019-09-03 14:10:32 +00:00
|
|
|
|
|
|
|
|
2020-03-30 13:08:22 +00:00
|
|
|
@mock_elasticbeanstalk
|
2019-09-03 14:10:32 +00:00
|
|
|
def test_create_application_dup():
|
2020-03-30 12:42:00 +00:00
|
|
|
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
|
|
|
conn.create_application(ApplicationName="myapp")
|
2023-07-20 09:36:51 +00:00
|
|
|
with pytest.raises(ClientError):
|
|
|
|
conn.create_application(ApplicationName="myapp")
|
2019-09-03 12:54:46 +00:00
|
|
|
|
2019-09-03 14:10:32 +00:00
|
|
|
|
2020-03-30 13:08:22 +00:00
|
|
|
@mock_elasticbeanstalk
|
2019-09-03 14:10:32 +00:00
|
|
|
def test_describe_applications():
|
|
|
|
# Create Elastic Beanstalk Application
|
2020-03-30 12:42:00 +00:00
|
|
|
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
|
|
|
conn.create_application(ApplicationName="myapp")
|
2019-09-03 12:54:46 +00:00
|
|
|
|
2019-09-03 14:10:32 +00:00
|
|
|
apps = conn.describe_applications()
|
2023-07-20 09:36:51 +00:00
|
|
|
assert len(apps["Applications"]) == 1
|
|
|
|
assert apps["Applications"][0]["ApplicationName"] == "myapp"
|
|
|
|
assert "myapp" in apps["Applications"][0]["ApplicationArn"]
|
2019-09-04 13:33:15 +00:00
|
|
|
|
|
|
|
|
2023-09-11 08:57:27 +00:00
|
|
|
@mock_elasticbeanstalk
|
|
|
|
def test_delete_application():
|
|
|
|
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
|
|
|
|
|
|
|
application_name = "myapp"
|
|
|
|
|
|
|
|
conn.create_application(ApplicationName=application_name)
|
|
|
|
|
|
|
|
resp = conn.delete_application(ApplicationName=application_name)
|
|
|
|
|
|
|
|
assert resp["ResponseMetadata"]["HTTPStatusCode"] == 200
|
|
|
|
|
|
|
|
|
|
|
|
@mock_elasticbeanstalk
|
|
|
|
def test_delete_unknown_application():
|
|
|
|
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
|
|
|
|
|
|
|
application_name = "myapp"
|
|
|
|
unknown_application_name = "myapp1"
|
|
|
|
|
|
|
|
conn.create_application(ApplicationName=application_name)
|
|
|
|
with pytest.raises(ClientError) as exc:
|
|
|
|
conn.delete_application(ApplicationName=unknown_application_name)
|
|
|
|
err = exc.value.response["Error"]
|
|
|
|
assert err["Code"] == "ApplicationNotFound"
|
|
|
|
assert (
|
|
|
|
err["Message"]
|
|
|
|
== f"Elastic Beanstalk application {unknown_application_name} not found."
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-03-30 13:08:22 +00:00
|
|
|
@mock_elasticbeanstalk
|
2019-09-04 13:33:15 +00:00
|
|
|
def test_create_environment():
|
|
|
|
# Create Elastic Beanstalk Environment
|
2020-03-30 12:42:00 +00:00
|
|
|
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
2022-03-11 21:28:45 +00:00
|
|
|
conn.create_application(ApplicationName="myapp")
|
2020-03-30 12:42:00 +00:00
|
|
|
env = conn.create_environment(ApplicationName="myapp", EnvironmentName="myenv")
|
2023-07-20 09:36:51 +00:00
|
|
|
assert env["EnvironmentName"] == "myenv"
|
|
|
|
assert "myapp/myenv" in env["EnvironmentArn"]
|
2019-09-04 13:33:15 +00:00
|
|
|
|
|
|
|
|
2020-03-30 13:08:22 +00:00
|
|
|
@mock_elasticbeanstalk
|
2019-09-04 13:33:15 +00:00
|
|
|
def test_describe_environments():
|
|
|
|
# List Elastic Beanstalk Envs
|
2020-03-30 12:42:00 +00:00
|
|
|
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
|
|
|
conn.create_application(ApplicationName="myapp")
|
|
|
|
conn.create_environment(ApplicationName="myapp", EnvironmentName="myenv")
|
2019-09-04 13:33:15 +00:00
|
|
|
|
|
|
|
envs = conn.describe_environments()
|
2020-03-30 12:42:00 +00:00
|
|
|
envs = envs["Environments"]
|
2023-07-20 09:36:51 +00:00
|
|
|
assert len(envs) == 1
|
|
|
|
assert envs[0]["ApplicationName"] == "myapp"
|
|
|
|
assert envs[0]["EnvironmentName"] == "myenv"
|
|
|
|
assert "myapp/myenv" in envs[0]["EnvironmentArn"]
|
2019-09-04 13:33:15 +00:00
|
|
|
|
|
|
|
|
2019-09-04 14:56:06 +00:00
|
|
|
def tags_dict_to_list(tag_dict):
|
|
|
|
tag_list = []
|
|
|
|
for key, value in tag_dict.items():
|
2020-03-30 12:42:00 +00:00
|
|
|
tag_list.append({"Key": key, "Value": value})
|
2019-09-04 14:56:06 +00:00
|
|
|
return tag_list
|
|
|
|
|
|
|
|
|
|
|
|
def tags_list_to_dict(tag_list):
|
|
|
|
tag_dict = {}
|
|
|
|
for tag in tag_list:
|
2020-03-30 12:42:00 +00:00
|
|
|
tag_dict[tag["Key"]] = tag["Value"]
|
2019-09-04 14:56:06 +00:00
|
|
|
return tag_dict
|
|
|
|
|
|
|
|
|
2020-03-30 13:08:22 +00:00
|
|
|
@mock_elasticbeanstalk
|
2019-09-04 14:56:06 +00:00
|
|
|
def test_create_environment_tags():
|
2020-03-30 12:42:00 +00:00
|
|
|
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
|
|
|
conn.create_application(ApplicationName="myapp")
|
|
|
|
env_tags = {"initial key": "initial value"}
|
2019-09-04 14:56:06 +00:00
|
|
|
env = conn.create_environment(
|
|
|
|
ApplicationName="myapp",
|
|
|
|
EnvironmentName="myenv",
|
|
|
|
Tags=tags_dict_to_list(env_tags),
|
|
|
|
)
|
|
|
|
|
2020-03-30 12:42:00 +00:00
|
|
|
tags = conn.list_tags_for_resource(ResourceArn=env["EnvironmentArn"])
|
2023-07-20 09:36:51 +00:00
|
|
|
assert tags["ResourceArn"] == env["EnvironmentArn"]
|
|
|
|
assert tags_list_to_dict(tags["ResourceTags"]) == env_tags
|
2019-09-04 14:56:06 +00:00
|
|
|
|
|
|
|
|
2020-03-30 13:08:22 +00:00
|
|
|
@mock_elasticbeanstalk
|
2019-09-04 14:56:06 +00:00
|
|
|
def test_update_tags():
|
2020-03-30 12:42:00 +00:00
|
|
|
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
|
|
|
conn.create_application(ApplicationName="myapp")
|
2019-09-04 14:56:06 +00:00
|
|
|
env_tags = {
|
2020-03-30 12:42:00 +00:00
|
|
|
"initial key": "initial value",
|
|
|
|
"to remove": "delete me",
|
|
|
|
"to update": "original",
|
2019-09-04 14:56:06 +00:00
|
|
|
}
|
|
|
|
env = conn.create_environment(
|
|
|
|
ApplicationName="myapp",
|
|
|
|
EnvironmentName="myenv",
|
|
|
|
Tags=tags_dict_to_list(env_tags),
|
|
|
|
)
|
|
|
|
|
|
|
|
extra_env_tags = {
|
2020-03-30 12:42:00 +00:00
|
|
|
"to update": "new",
|
|
|
|
"extra key": "extra value",
|
2019-09-04 14:56:06 +00:00
|
|
|
}
|
|
|
|
conn.update_tags_for_resource(
|
2020-03-30 12:42:00 +00:00
|
|
|
ResourceArn=env["EnvironmentArn"],
|
2019-09-04 14:56:06 +00:00
|
|
|
TagsToAdd=tags_dict_to_list(extra_env_tags),
|
2020-03-30 12:42:00 +00:00
|
|
|
TagsToRemove=["to remove"],
|
2019-09-04 14:56:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
total_env_tags = env_tags.copy()
|
|
|
|
total_env_tags.update(extra_env_tags)
|
2020-03-30 12:42:00 +00:00
|
|
|
del total_env_tags["to remove"]
|
2019-09-04 14:56:06 +00:00
|
|
|
|
2020-03-30 12:42:00 +00:00
|
|
|
tags = conn.list_tags_for_resource(ResourceArn=env["EnvironmentArn"])
|
2023-07-20 09:36:51 +00:00
|
|
|
assert tags["ResourceArn"] == env["EnvironmentArn"]
|
|
|
|
assert tags_list_to_dict(tags["ResourceTags"]) == total_env_tags
|
2019-09-04 14:56:06 +00:00
|
|
|
|
|
|
|
|
2020-03-30 13:08:22 +00:00
|
|
|
@mock_elasticbeanstalk
|
2019-09-04 13:33:15 +00:00
|
|
|
def test_list_available_solution_stacks():
|
2020-03-30 12:42:00 +00:00
|
|
|
conn = boto3.client("elasticbeanstalk", region_name="us-east-1")
|
2019-09-04 13:33:15 +00:00
|
|
|
stacks = conn.list_available_solution_stacks()
|
2023-07-20 09:36:51 +00:00
|
|
|
assert len(stacks["SolutionStacks"]) > 0
|
|
|
|
assert len(stacks["SolutionStacks"]) == len(stacks["SolutionStackDetails"])
|