Media store data Service (#3955)

* 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 ClientError part2

* Mediastoredata not working

Base url

tests and renaming

typo

List Items not returning proper JSON and wrongly hitting get_object response

MediaStore2

Tests

* More implementation

* Fix tests and format

* Comments fix

* Comments 2

* MediastoreData - alternative logic to figure out appropriate host

Co-authored-by: av <arcovoltaico@gmail.com>
Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
Jordi Alhambra 2021-06-28 13:23:23 +01:00 committed by GitHub
commit 759974d9cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 328 additions and 5 deletions

View file

@ -177,6 +177,18 @@ def test_describe_origin_endpoint_succeeds():
)
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(
"originEndpoint with id={} not found".format(str(channel_id))
)
@mock_mediapackage
def test_describe_unknown_origin_endpoint_throws_error():
client = boto3.client("mediapackage", region_name=region)
@ -207,6 +219,18 @@ def test_delete_origin_endpoint_succeeds():
)
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(
"originEndpoint with id={} not found".format(str(channel_id))
)
@mock_mediapackage
def test_delete_unknown_origin_endpoint_throws_error():
client = boto3.client("mediapackage", region_name=region)
@ -234,6 +258,22 @@ def test_update_origin_endpoint_succeeds():
update_response["ManifestName"].should.equal("updated-manifest-name")
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(
"originEndpoint with id={} not found".format(str(channel_id))
)
@mock_mediapackage
def test_update_unknown_origin_endpoint_throws_error():
client = boto3.client("mediapackage", region_name=region)

View file

@ -220,6 +220,14 @@ def test_list_tags_for_resource_return_none_if_no_tags():
response.get("Tags").should.equal(None)
@mock_mediastore
def test_list_tags_for_resource_return_none_if_no_tags():
client = boto3.client("mediastore", region_name=region)
with pytest.raises(ClientError) as ex:
client.list_tags_for_resource(Resource="not_existing")
ex.value.response["Error"]["Code"].should.equal("ContainerNotFoundException")
@mock_mediastore
def test_delete_container():
client = boto3.client("mediastore", region_name=region)

View file

View file

@ -0,0 +1,85 @@
from __future__ import unicode_literals
import boto3
import pytest
import sure # noqa
from botocore.exceptions import ClientError
from moto import mock_mediastoredata
region = "eu-west-1"
@mock_mediastoredata
def test_put_object():
client = boto3.client("mediastore-data", region_name=region)
response = client.put_object(Body="011001", Path="foo")
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
response["StorageClass"].should.equal("TEMPORAL")
items = client.list_items()["Items"]
object_exists = any(d["Name"] == "foo" for d in items)
object_exists.should.equal(True)
@mock_mediastoredata
def test_get_object_throws_not_found_error():
client = boto3.client("mediastore-data", region_name=region)
with pytest.raises(ClientError) as ex:
client.get_object(Path="foo")
ex.value.response["Error"]["Code"].should.equal("ObjectNotFoundException")
@mock_mediastoredata
def test_get_object():
client = boto3.client("mediastore-data", region_name=region)
client.put_object(Body="011001", Path="foo")
response = client.get_object(Path="foo")
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
response["ResponseMetadata"]["HTTPHeaders"]["path"].should.equal("foo")
data = response["Body"].read()
data.should.equal(b"011001")
@mock_mediastoredata
def test_delete_object_error():
client = boto3.client("mediastore-data", region_name=region)
with pytest.raises(ClientError) as ex:
client.delete_object(Path="foo")
ex.value.response["Error"]["Code"].should.equal("ObjectNotFoundException")
@mock_mediastoredata
def test_delete_object_succeeds():
client = boto3.client("mediastore-data", region_name=region)
object_path = "foo"
client.put_object(Body="011001", Path=object_path)
response = client.delete_object(Path=object_path)
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
items = client.list_items()["Items"]
len(items).should.equal(0)
@mock_mediastoredata
def test_list_items():
client = boto3.client("mediastore-data", region_name=region)
items = client.list_items()["Items"]
len(items).should.equal(0)
object_path = "foo"
client.put_object(Body="011001", Path=object_path)
items = client.list_items()["Items"]
len(items).should.equal(1)
object_exists = any(d["Name"] == object_path for d in items)
object_exists.should.equal(True)
@mock_mediastoredata
def test_list_items():
client = boto3.client("mediastore-data", region_name=region)
items = client.list_items()["Items"]
len(items).should.equal(0)
object_path = "foo"
client.put_object(Body="011001", Path=object_path)
items = client.list_items()["Items"]
len(items).should.equal(1)
object_exists = any(d["Name"] == object_path for d in items)
object_exists.should.equal(True)

View file

@ -0,0 +1,18 @@
from __future__ import unicode_literals
import sure # noqa
import moto.server as server
from moto import mock_mediastoredata
"""
Test the different server responses
"""
@mock_mediastoredata
def test_mediastore_lists_containers():
backend = server.create_backend_app("mediastore-data")
test_client = backend.test_client()
response = test_client.get("/").data
response.should.contain(b'"Items": []')