moto/tests/test_glacier/test_glacier_archives.py

65 lines
2.0 KiB
Python
Raw Normal View History

import os
import boto3
import pytest
from botocore.exceptions import ClientError
2018-12-21 11:28:56 +00:00
2024-01-07 12:03:33 +00:00
from moto import mock_aws
2024-01-07 12:03:33 +00:00
@mock_aws
def test_upload_archive():
client = boto3.client("glacier", region_name="us-west-2")
client.create_vault(vaultName="asdf")
res = client.upload_archive(
vaultName="asdf", archiveDescription="my archive", body=b"body of archive"
)
assert res["ResponseMetadata"]["HTTPStatusCode"] == 201
headers = res["ResponseMetadata"]["HTTPHeaders"]
assert "x-amz-archive-id" in headers
assert "x-amz-sha256-tree-hash" in headers
assert "checksum" in res
assert "archiveId" in res
2024-01-07 12:03:33 +00:00
@mock_aws
def test_upload_zip_archive():
client = boto3.client("glacier", region_name="us-west-2")
client.create_vault(vaultName="asdf")
path = "test.gz"
with open(os.path.join(os.path.dirname(__file__), path), mode="rb") as archive:
content = archive.read()
res = client.upload_archive(vaultName="asdf", body=content)
assert res["ResponseMetadata"]["HTTPStatusCode"] == 201
assert "checksum" in res
2024-01-07 12:03:33 +00:00
@mock_aws
def test_delete_archive():
client = boto3.client("glacier", region_name="us-west-2")
client.create_vault(vaultName="asdf")
archive = client.upload_archive(vaultName="asdf", body=b"body of archive")
delete = client.delete_archive(vaultName="asdf", archiveId=archive["archiveId"])
assert delete["ResponseMetadata"]["HTTPStatusCode"] == 204
with pytest.raises(ClientError) as exc:
# Not ideal - but this will throw an error if the archive does not exist
# Which is a good indication that the deletion went through
client.initiate_job(
vaultName="myname",
jobParameters={
"ArchiveId": archive["archiveId"],
"Type": "archive-retrieval",
},
)
err = exc.value.response["Error"]
assert err["Code"] == "VaultNotFound"