2021-06-28 12:23:23 +00:00
|
|
|
import boto3
|
|
|
|
import pytest
|
|
|
|
from botocore.exceptions import ClientError
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
from moto import mock_aws
|
2021-06-28 12:23:23 +00:00
|
|
|
|
|
|
|
region = "eu-west-1"
|
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2021-06-28 12:23:23 +00:00
|
|
|
def test_put_object():
|
|
|
|
client = boto3.client("mediastore-data", region_name=region)
|
|
|
|
response = client.put_object(Body="011001", Path="foo")
|
2023-08-13 20:17:54 +00:00
|
|
|
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
|
|
|
assert response["StorageClass"] == "TEMPORAL"
|
|
|
|
|
2021-06-28 12:23:23 +00:00
|
|
|
items = client.list_items()["Items"]
|
2023-08-13 20:17:54 +00:00
|
|
|
assert any(d["Name"] == "foo" for d in items)
|
2021-06-28 12:23:23 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2021-06-28 12:23:23 +00:00
|
|
|
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")
|
2023-08-13 20:17:54 +00:00
|
|
|
assert ex.value.response["Error"]["Code"] == "ObjectNotFoundException"
|
2021-06-28 12:23:23 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2021-06-28 12:23:23 +00:00
|
|
|
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")
|
2023-08-13 20:17:54 +00:00
|
|
|
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
|
|
|
assert response["ResponseMetadata"]["HTTPHeaders"]["path"] == "foo"
|
|
|
|
assert response["Body"].read() == b"011001"
|
2021-06-28 12:23:23 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2021-06-28 12:23:23 +00:00
|
|
|
def test_delete_object_error():
|
|
|
|
client = boto3.client("mediastore-data", region_name=region)
|
|
|
|
with pytest.raises(ClientError) as ex:
|
|
|
|
client.delete_object(Path="foo")
|
2023-08-13 20:17:54 +00:00
|
|
|
assert ex.value.response["Error"]["Code"] == "ObjectNotFoundException"
|
2021-06-28 12:23:23 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2021-06-28 12:23:23 +00:00
|
|
|
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)
|
2023-08-13 20:17:54 +00:00
|
|
|
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
|
|
|
|
|
|
|
assert len(client.list_items()["Items"]) == 0
|
2021-06-28 12:23:23 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2021-06-28 12:23:23 +00:00
|
|
|
def test_list_items():
|
|
|
|
client = boto3.client("mediastore-data", region_name=region)
|
2023-08-13 20:17:54 +00:00
|
|
|
assert len(client.list_items()["Items"]) == 0
|
|
|
|
|
2021-06-28 12:23:23 +00:00
|
|
|
object_path = "foo"
|
|
|
|
client.put_object(Body="011001", Path=object_path)
|
2023-08-13 20:17:54 +00:00
|
|
|
|
2021-06-28 12:23:23 +00:00
|
|
|
items = client.list_items()["Items"]
|
2023-08-13 20:17:54 +00:00
|
|
|
assert len(items) == 1
|
|
|
|
assert any(d["Name"] == object_path for d in items)
|