moto/tests/test_opsworks/test_apps.py

76 lines
2.4 KiB
Python
Raw Normal View History

2018-12-21 11:28:56 +00:00
import boto3
from freezegun import freeze_time
2021-10-18 19:44:29 +00:00
import sure # noqa # pylint: disable=unused-import
2018-12-21 11:28:56 +00:00
import re
from moto import mock_opsworks
@freeze_time("2015-01-01")
@mock_opsworks
def test_create_app_response():
client = boto3.client("opsworks", region_name="us-east-1")
2018-12-21 11:28:56 +00:00
stack_id = client.create_stack(
Name="test_stack_1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
2018-12-21 11:28:56 +00:00
response = client.create_app(StackId=stack_id, Type="other", Name="TestApp")
2018-12-21 11:28:56 +00:00
response.should.contain("AppId")
second_stack_id = client.create_stack(
Name="test_stack_2",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
2018-12-21 11:28:56 +00:00
response = client.create_app(StackId=second_stack_id, Type="other", Name="TestApp")
2018-12-21 11:28:56 +00:00
response.should.contain("AppId")
# ClientError
client.create_app.when.called_with(
StackId=stack_id, Type="other", Name="TestApp"
).should.throw(Exception, re.compile(r'already an app named "TestApp"'))
2018-12-21 11:28:56 +00:00
# ClientError
client.create_app.when.called_with(
StackId="nothere", Type="other", Name="TestApp"
).should.throw(Exception, "nothere")
2018-12-21 11:28:56 +00:00
@freeze_time("2015-01-01")
@mock_opsworks
def test_describe_apps():
client = boto3.client("opsworks", region_name="us-east-1")
2018-12-21 11:28:56 +00:00
stack_id = client.create_stack(
Name="test_stack_1",
Region="us-east-1",
ServiceRoleArn="service_arn",
DefaultInstanceProfileArn="profile_arn",
)["StackId"]
app_id = client.create_app(StackId=stack_id, Type="other", Name="TestApp")["AppId"]
2018-12-21 11:28:56 +00:00
rv1 = client.describe_apps(StackId=stack_id)
rv2 = client.describe_apps(AppIds=[app_id])
rv1["Apps"].should.equal(rv2["Apps"])
2018-12-21 11:28:56 +00:00
rv1["Apps"][0]["Name"].should.equal("TestApp")
2018-12-21 11:28:56 +00:00
# ClientError
client.describe_apps.when.called_with(
StackId=stack_id, AppIds=[app_id]
).should.throw(Exception, "Please provide one or more app IDs or a stack ID")
2018-12-21 11:28:56 +00:00
# ClientError
client.describe_apps.when.called_with(StackId="nothere").should.throw(
2018-12-21 11:28:56 +00:00
Exception, "Unable to find stack with ID nothere"
)
# ClientError
client.describe_apps.when.called_with(AppIds=["nothere"]).should.throw(
2018-12-21 11:28:56 +00:00
Exception, "nothere"
)