Media package client error (#3983)

* 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

Co-authored-by: av <arcovoltaico@gmail.com>
Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
Jordi Alhambra 2021-06-07 13:47:49 +01:00 committed by GitHub
parent 9836985473
commit ae5653b31d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 5 deletions

View File

@ -1 +1,13 @@
from __future__ import unicode_literals
from moto.core.exceptions import JsonRESTError
class MediaPackageClientError(JsonRESTError):
code = 400
# AWS service exceptions are caught with the underlying botocore exception, ClientError
class ClientError(MediaPackageClientError):
def __init__(self, error, message):
super(ClientError, self).__init__(error, message)

View File

@ -1,8 +1,12 @@
from __future__ import unicode_literals
from boto3 import Session
from moto.core import BaseBackend, BaseModel
from collections import OrderedDict
from boto3 import Session
from moto.core import BaseBackend, BaseModel
from .exceptions import ClientError
class Channel(BaseModel):
def __init__(self, *args, **kwargs):
@ -97,8 +101,12 @@ class MediaPackageBackend(BaseBackend):
return response_channels
def describe_channel(self, id):
channel = self._channels[id]
return channel.to_dict()
try:
channel = self._channels[id]
return channel.to_dict()
except KeyError:
error = "NotFoundException"
raise ClientError(error, "channel with id={} not found".format(id))
def delete_channel(self, id):
channel = self._channels[id]

View File

@ -1,7 +1,10 @@
from __future__ import unicode_literals
import boto3
import pytest
import sure # noqa
from botocore.exceptions import ClientError # Boto3 will always throw this exception
from moto import mock_mediapackage
region = "eu-west-1"
@ -11,7 +14,7 @@ def _create_channel_config(**kwargs):
id = kwargs.get("id", "channel-id")
description = kwargs.get("description", "Awesome channel!")
tags = kwargs.get("tags", {"Customer": "moto"})
channel_config = dict(Description=description, Id=id, Tags=tags,)
channel_config = dict(Description=description, Id=id, Tags=tags)
return channel_config
@ -81,6 +84,17 @@ def test_describe_channel_succeeds():
describe_response["Tags"]["Customer"].should.equal("moto")
@mock_mediapackage
def test_describe_unknown_channel_throws_error():
client = boto3.client("mediapackage", region_name=region)
channel_id = "unknown-channel"
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("channel with id={} not found".format(str(channel_id)))
@mock_mediapackage
def test_delete_channel_successfully_deletes():
client = boto3.client("mediapackage", region_name=region)