Media package client error additional handling (#4011)
* Add delete container and list tags endpoints to MediaStore * Black reformat * Fixed Lint problems * Check if dictionary was deleted effectively * lint fix * MediaPackageClientError * Lint Fix * Test unknown channel describe * Concatenation Fix * MediaPackage - fix error message * MediaPackage Test Fix and TryError * Lint Co-authored-by: av <arcovoltaico@gmail.com> Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
parent
fe7430b368
commit
407d5c853d
@ -5,6 +5,7 @@ from collections import OrderedDict
|
||||
from boto3 import Session
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
|
||||
from .exceptions import ClientError
|
||||
|
||||
|
||||
@ -109,9 +110,14 @@ class MediaPackageBackend(BaseBackend):
|
||||
raise ClientError(error, "channel with id={} not found".format(id))
|
||||
|
||||
def delete_channel(self, id):
|
||||
channel = self._channels[id]
|
||||
del self._channels[id]
|
||||
return channel.to_dict()
|
||||
try:
|
||||
channel = self._channels[id]
|
||||
del self._channels[id]
|
||||
return channel.to_dict()
|
||||
|
||||
except KeyError:
|
||||
error = "NotFoundException"
|
||||
raise ClientError(error, "channel with id={} not found".format(id))
|
||||
|
||||
def create_origin_endpoint(
|
||||
self,
|
||||
@ -156,8 +162,12 @@ class MediaPackageBackend(BaseBackend):
|
||||
return origin_endpoint
|
||||
|
||||
def describe_origin_endpoint(self, id):
|
||||
origin_endpoint = self._origin_endpoints[id]
|
||||
return origin_endpoint.to_dict()
|
||||
try:
|
||||
origin_endpoint = self._origin_endpoints[id]
|
||||
return origin_endpoint.to_dict()
|
||||
except KeyError:
|
||||
error = "NotFoundException"
|
||||
raise ClientError(error, "origin endpoint with id={} not found".format(id))
|
||||
|
||||
def list_origin_endpoints(self):
|
||||
origin_endpoints = list(self._origin_endpoints.values())
|
||||
@ -165,9 +175,13 @@ class MediaPackageBackend(BaseBackend):
|
||||
return response_origin_endpoints
|
||||
|
||||
def delete_origin_endpoint(self, id):
|
||||
origin_endpoint = self._origin_endpoints[id]
|
||||
del self._origin_endpoints[id]
|
||||
return origin_endpoint.to_dict()
|
||||
try:
|
||||
origin_endpoint = self._origin_endpoints[id]
|
||||
del self._origin_endpoints[id]
|
||||
return origin_endpoint.to_dict()
|
||||
except KeyError:
|
||||
error = "NotFoundException"
|
||||
raise ClientError(error, "origin endpoint with id={} not found".format(id))
|
||||
|
||||
def update_origin_endpoint(
|
||||
self,
|
||||
@ -184,19 +198,24 @@ class MediaPackageBackend(BaseBackend):
|
||||
time_delay_seconds,
|
||||
whitelist,
|
||||
):
|
||||
origin_endpoint = self._origin_endpoints[id]
|
||||
origin_endpoint.authorization = authorization
|
||||
origin_endpoint.cmaf_package = cmaf_package
|
||||
origin_endpoint.dash_package = dash_package
|
||||
origin_endpoint.description = description
|
||||
origin_endpoint.hls_package = hls_package
|
||||
origin_endpoint.manifest_name = manifest_name
|
||||
origin_endpoint.mss_package = mss_package
|
||||
origin_endpoint.origination = origination
|
||||
origin_endpoint.startover_window_seconds = startover_window_seconds
|
||||
origin_endpoint.time_delay_seconds = time_delay_seconds
|
||||
origin_endpoint.whitelist = whitelist
|
||||
return origin_endpoint
|
||||
try:
|
||||
origin_endpoint = self._origin_endpoints[id]
|
||||
origin_endpoint.authorization = authorization
|
||||
origin_endpoint.cmaf_package = cmaf_package
|
||||
origin_endpoint.dash_package = dash_package
|
||||
origin_endpoint.description = description
|
||||
origin_endpoint.hls_package = hls_package
|
||||
origin_endpoint.manifest_name = manifest_name
|
||||
origin_endpoint.mss_package = mss_package
|
||||
origin_endpoint.origination = origination
|
||||
origin_endpoint.startover_window_seconds = startover_window_seconds
|
||||
origin_endpoint.time_delay_seconds = time_delay_seconds
|
||||
origin_endpoint.whitelist = whitelist
|
||||
return origin_endpoint
|
||||
|
||||
except KeyError:
|
||||
error = "NotFoundException"
|
||||
raise ClientError(error, "origin endpoint with id={} not found".format(id))
|
||||
|
||||
|
||||
mediapackage_backends = {}
|
||||
|
@ -95,6 +95,17 @@ def test_describe_unknown_channel_throws_error():
|
||||
err["Message"].should.equal("channel with id={} not found".format(str(channel_id)))
|
||||
|
||||
|
||||
@mock_mediapackage
|
||||
def test_delete_unknown_channel_throws_error():
|
||||
client = boto3.client("mediapackage", region_name=region)
|
||||
channel_id = "unknown-channel"
|
||||
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("channel with id={} not found".format(str(channel_id)))
|
||||
|
||||
|
||||
@mock_mediapackage
|
||||
def test_delete_channel_successfully_deletes():
|
||||
client = boto3.client("mediapackage", region_name=region)
|
||||
@ -166,6 +177,19 @@ def test_describe_origin_endpoint_succeeds():
|
||||
)
|
||||
|
||||
|
||||
@mock_mediapackage
|
||||
def test_describe_unknown_origin_endpoint_throws_error():
|
||||
client = boto3.client("mediapackage", region_name=region)
|
||||
channel_id = "unknown-channel"
|
||||
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(
|
||||
"origin endpoint with id={} not found".format(str(channel_id))
|
||||
)
|
||||
|
||||
|
||||
@mock_mediapackage
|
||||
def test_delete_origin_endpoint_succeeds():
|
||||
client = boto3.client("mediapackage", region_name=region)
|
||||
@ -183,6 +207,19 @@ def test_delete_origin_endpoint_succeeds():
|
||||
)
|
||||
|
||||
|
||||
@mock_mediapackage
|
||||
def test_delete_unknown_origin_endpoint_throws_error():
|
||||
client = boto3.client("mediapackage", region_name=region)
|
||||
channel_id = "unknown-channel"
|
||||
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(
|
||||
"origin endpoint with id={} not found".format(str(channel_id))
|
||||
)
|
||||
|
||||
|
||||
@mock_mediapackage
|
||||
def test_update_origin_endpoint_succeeds():
|
||||
client = boto3.client("mediapackage", region_name=region)
|
||||
@ -197,6 +234,23 @@ def test_update_origin_endpoint_succeeds():
|
||||
update_response["ManifestName"].should.equal("updated-manifest-name")
|
||||
|
||||
|
||||
@mock_mediapackage
|
||||
def test_update_unknown_origin_endpoint_throws_error():
|
||||
client = boto3.client("mediapackage", region_name=region)
|
||||
channel_id = "unknown-channel"
|
||||
with pytest.raises(ClientError) as err:
|
||||
client.update_origin_endpoint(
|
||||
Id=channel_id,
|
||||
Description="updated-channel-description",
|
||||
ManifestName="updated-manifest-name",
|
||||
)
|
||||
err = err.value.response["Error"]
|
||||
err["Code"].should.equal("NotFoundException")
|
||||
err["Message"].should.equal(
|
||||
"origin endpoint with id={} not found".format(str(channel_id))
|
||||
)
|
||||
|
||||
|
||||
@mock_mediapackage
|
||||
def test_list_origin_endpoint_succeeds():
|
||||
origin_endpoints_list = []
|
||||
|
Loading…
Reference in New Issue
Block a user