Techdebt: Replace sure with regular assertions in MediaPackage (#6652)

This commit is contained in:
Bert Blommers 2023-08-13 18:52:36 +00:00 committed by GitHub
parent 5f35156d3d
commit b9fcfde3cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 85 deletions

View File

@ -1,6 +1,5 @@
import boto3
import pytest
import sure # noqa # pylint: disable=unused-import
from botocore.exceptions import ClientError # Boto3 will always throw this exception
from moto import mock_mediapackage
@ -58,12 +57,12 @@ def test_create_channel_succeeds():
client = boto3.client("mediapackage", region_name=region)
channel_config = _create_channel_config()
response = client.create_channel(**channel_config)
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
response["Arn"].should.equal(f"arn:aws:mediapackage:channel:{response['Id']}")
response["Description"].should.equal("Awesome channel!")
response["Id"].should.equal("channel-id")
response["Tags"]["Customer"].should.equal("moto")
channel = client.create_channel(**channel_config)
assert channel["ResponseMetadata"]["HTTPStatusCode"] == 200
assert channel["Arn"] == f"arn:aws:mediapackage:channel:{channel['Id']}"
assert channel["Description"] == "Awesome channel!"
assert channel["Id"] == "channel-id"
assert channel["Tags"]["Customer"] == "moto"
@mock_mediapackage
@ -71,13 +70,11 @@ def test_describe_channel_succeeds():
client = boto3.client("mediapackage", region_name=region)
channel_config = _create_channel_config()
create_response = client.create_channel(**channel_config)
describe_response = client.describe_channel(Id=create_response["Id"])
describe_response["Arn"].should.equal(
f"arn:aws:mediapackage:channel:{describe_response['Id']}"
)
describe_response["Description"].should.equal(channel_config["Description"])
describe_response["Tags"]["Customer"].should.equal("moto")
channel_id = client.create_channel(**channel_config)["Id"]
channel = client.describe_channel(Id=channel_id)
assert channel["Arn"] == f"arn:aws:mediapackage:channel:{channel['Id']}"
assert channel["Description"] == channel_config["Description"]
assert channel["Tags"]["Customer"] == "moto"
@mock_mediapackage
@ -87,8 +84,8 @@ def test_describe_unknown_channel_throws_error():
with pytest.raises(ClientError) as err:
client.describe_channel(Id=channel_id)
err = err.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal(f"channel with id={channel_id} not found")
assert err["Code"] == "NotFoundException"
assert err["Message"] == f"channel with id={channel_id} not found"
@mock_mediapackage
@ -98,8 +95,8 @@ def test_delete_unknown_channel_throws_error():
with pytest.raises(ClientError) as err:
client.delete_channel(Id=channel_id)
err = err.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal(f"channel with id={channel_id} not found")
assert err["Code"] == "NotFoundException"
assert err["Message"] == f"channel with id={channel_id} not found"
@mock_mediapackage
@ -114,25 +111,22 @@ def test_delete_channel_successfully_deletes():
# After deletion
post_deletion_list_response = client.list_channels()
post_deletion_channels_list = post_deletion_list_response["Channels"]
len(post_deletion_channels_list).should.equal(len(channels_list) - 1)
assert len(post_deletion_channels_list) == len(channels_list) - 1
@mock_mediapackage
def test_list_channels_succeds():
channels_list = []
client = boto3.client("mediapackage", region_name=region)
channel_config = _create_channel_config()
len(channels_list).should.equal(0)
client.create_channel(**channel_config)
list_response = client.list_channels()
channels_list = list_response["Channels"]
len(channels_list).should.equal(1)
first_channel = channels_list[0]
first_channel["Arn"].should.equal(
f"arn:aws:mediapackage:channel:{first_channel['Id']}"
)
first_channel["Description"].should.equal(channel_config["Description"])
first_channel["Tags"]["Customer"].should.equal("moto")
channels_list = client.list_channels()["Channels"]
assert len(channels_list) == 1
channel = channels_list[0]
assert channel["Arn"] == f"arn:aws:mediapackage:channel:{channel['Id']}"
assert channel["Description"] == channel_config["Description"]
assert channel["Tags"]["Customer"] == "moto"
@mock_mediapackage
@ -140,15 +134,13 @@ def test_create_origin_endpoint_succeeds():
client = boto3.client("mediapackage", region_name=region)
origin_endpoint_config = _create_origin_endpoint_config()
response = client.create_origin_endpoint(**origin_endpoint_config)
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
response["Arn"].should.equal(
f"arn:aws:mediapackage:origin_endpoint:{response['Id']}"
)
response["ChannelId"].should.equal(origin_endpoint_config["ChannelId"])
response["Description"].should.equal(origin_endpoint_config["Description"])
response["HlsPackage"].should.equal(origin_endpoint_config["HlsPackage"])
response["Origination"].should.equal("ALLOW")
endpoint = client.create_origin_endpoint(**origin_endpoint_config)
assert endpoint["ResponseMetadata"]["HTTPStatusCode"] == 200
assert endpoint["Arn"] == f"arn:aws:mediapackage:origin_endpoint:{endpoint['Id']}"
assert endpoint["ChannelId"] == origin_endpoint_config["ChannelId"]
assert endpoint["Description"] == origin_endpoint_config["Description"]
assert endpoint["HlsPackage"] == origin_endpoint_config["HlsPackage"]
assert endpoint["Origination"] == "ALLOW"
@mock_mediapackage
@ -156,18 +148,17 @@ def test_describe_origin_endpoint_succeeds():
client = boto3.client("mediapackage", region_name=region)
origin_endpoint_config = _create_origin_endpoint_config()
create_response = client.create_origin_endpoint(**origin_endpoint_config)
describe_response = client.describe_origin_endpoint(Id=create_response["Id"])
describe_response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
describe_response["Arn"].should.equal(
f"arn:aws:mediapackage:origin_endpoint:{describe_response['Id']}"
)
describe_response["ChannelId"].should.equal(origin_endpoint_config["ChannelId"])
describe_response["Description"].should.equal(origin_endpoint_config["Description"])
describe_response["HlsPackage"].should.equal(origin_endpoint_config["HlsPackage"])
describe_response["Origination"].should.equal("ALLOW")
describe_response["Url"].should.equal(
f"https://origin-endpoint.mediapackage.{region}.amazonaws.com/{describe_response['Id']}"
endpoint_id = client.create_origin_endpoint(**origin_endpoint_config)["Id"]
endpoint = client.describe_origin_endpoint(Id=endpoint_id)
assert endpoint["ResponseMetadata"]["HTTPStatusCode"] == 200
assert endpoint["Arn"] == f"arn:aws:mediapackage:origin_endpoint:{endpoint['Id']}"
assert endpoint["ChannelId"] == origin_endpoint_config["ChannelId"]
assert endpoint["Description"] == origin_endpoint_config["Description"]
assert endpoint["HlsPackage"] == origin_endpoint_config["HlsPackage"]
assert endpoint["Origination"] == "ALLOW"
assert (
endpoint["Url"]
== f"https://origin-endpoint.mediapackage.{region}.amazonaws.com/{endpoint['Id']}"
)
@ -178,8 +169,8 @@ def test_describe_unknown_origin_endpoint_throws_error():
with pytest.raises(ClientError) as err:
client.describe_origin_endpoint(Id=channel_id)
err = err.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal(f"origin endpoint with id={channel_id} not found")
assert err["Code"] == "NotFoundException"
assert err["Message"] == f"origin endpoint with id={channel_id} not found"
@mock_mediapackage
@ -194,9 +185,7 @@ def test_delete_origin_endpoint_succeeds():
# After deletion
post_deletion_list_response = client.list_origin_endpoints()
post_deletion_origin_endpoints_list = post_deletion_list_response["OriginEndpoints"]
len(post_deletion_origin_endpoints_list).should.equal(
len(origin_endpoints_list) - 1
)
assert len(post_deletion_origin_endpoints_list) == len(origin_endpoints_list) - 1
@mock_mediapackage
@ -206,22 +195,23 @@ def test_delete_unknown_origin_endpoint_throws_error():
with pytest.raises(ClientError) as err:
client.delete_origin_endpoint(Id=channel_id)
err = err.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal(f"origin endpoint with id={channel_id} not found")
assert err["Code"] == "NotFoundException"
assert err["Message"] == f"origin endpoint with id={channel_id} not found"
@mock_mediapackage
def test_update_origin_endpoint_succeeds():
client = boto3.client("mediapackage", region_name=region)
origin_endpoint_config = _create_origin_endpoint_config()
create_response = client.create_origin_endpoint(**origin_endpoint_config)
update_response = client.update_origin_endpoint(
Id=create_response["Id"],
endpoint_id = client.create_origin_endpoint(**origin_endpoint_config)["Id"]
endpoint = client.update_origin_endpoint(
Id=endpoint_id,
Description="updated-channel-description",
ManifestName="updated-manifest-name",
)
update_response["Description"].should.equal("updated-channel-description")
update_response["ManifestName"].should.equal("updated-manifest-name")
assert endpoint["Description"] == "updated-channel-description"
assert endpoint["ManifestName"] == "updated-manifest-name"
@mock_mediapackage
@ -235,29 +225,22 @@ def test_update_unknown_origin_endpoint_throws_error():
ManifestName="updated-manifest-name",
)
err = err.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal(f"origin endpoint with id={channel_id} not found")
assert err["Code"] == "NotFoundException"
assert err["Message"] == f"origin endpoint with id={channel_id} not found"
@mock_mediapackage
def test_list_origin_endpoint_succeeds():
origin_endpoints_list = []
client = boto3.client("mediapackage", region_name=region)
origin_endpoint_config = _create_origin_endpoint_config()
len(origin_endpoints_list).should.equal(0)
client.create_origin_endpoint(**origin_endpoint_config)
list_response = client.list_origin_endpoints()
origin_endpoints_list = list_response["OriginEndpoints"]
len(origin_endpoints_list).should.equal(1)
first_origin_endpoint = origin_endpoints_list[0]
first_origin_endpoint["Arn"].should.equal(
f"arn:aws:mediapackage:origin_endpoint:{first_origin_endpoint['Id']}"
)
first_origin_endpoint["ChannelId"].should.equal(origin_endpoint_config["ChannelId"])
first_origin_endpoint["Description"].should.equal(
origin_endpoint_config["Description"]
)
first_origin_endpoint["HlsPackage"].should.equal(
origin_endpoint_config["HlsPackage"]
)
first_origin_endpoint["Origination"].should.equal("ALLOW")
origin_endpoints_list = client.list_origin_endpoints()["OriginEndpoints"]
assert len(origin_endpoints_list) == 1
endpoint = origin_endpoints_list[0]
assert endpoint["Arn"] == f"arn:aws:mediapackage:origin_endpoint:{endpoint['Id']}"
assert endpoint["ChannelId"] == origin_endpoint_config["ChannelId"]
assert endpoint["Description"] == origin_endpoint_config["Description"]
assert endpoint["HlsPackage"] == origin_endpoint_config["HlsPackage"]
assert endpoint["Origination"] == "ALLOW"

View File

@ -1,4 +1,4 @@
import sure # noqa # pylint: disable=unused-import
import json
import moto.server as server
from moto import mock_mediapackage
@ -15,7 +15,7 @@ def test_mediapackage_list_channels():
res = test_client.get("/channels")
result = res.data.decode("utf-8")
result.should.contain('"channels": []')
assert json.loads(result) == {"channels": []}
@mock_mediapackage
@ -25,4 +25,4 @@ def test_mediapackage_list_origin_endpoints():
res = test_client.get("/origin_endpoints")
result = res.data.decode("utf-8")
result.should.contain('"originEndpoints": []')
assert json.loads(result) == {"originEndpoints": []}