moto/tests/test_mediastoredata/test_mediastoredata.py
Jordi Alhambra 759974d9cd
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>
2021-06-28 13:23:23 +01:00

86 lines
2.8 KiB
Python

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)