2021-09-23 17:22:16 +00:00
|
|
|
import boto3
|
2022-01-27 10:40:42 +00:00
|
|
|
import os
|
2021-09-23 17:22:16 +00:00
|
|
|
import pytest
|
2018-12-21 11:28:56 +00:00
|
|
|
|
2022-01-18 15:18:57 +00:00
|
|
|
from moto import mock_glacier
|
2021-09-23 17:22:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_glacier
|
|
|
|
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"
|
|
|
|
)
|
2023-07-27 22:47:15 +00:00
|
|
|
assert res["ResponseMetadata"]["HTTPStatusCode"] == 201
|
2021-09-23 17:22:16 +00:00
|
|
|
headers = res["ResponseMetadata"]["HTTPHeaders"]
|
|
|
|
|
2023-07-27 22:47:15 +00:00
|
|
|
assert "x-amz-archive-id" in headers
|
|
|
|
assert "x-amz-sha256-tree-hash" in headers
|
2021-09-23 17:22:16 +00:00
|
|
|
|
2023-07-27 22:47:15 +00:00
|
|
|
assert "checksum" in res
|
|
|
|
assert "archiveId" in res
|
2021-09-23 17:22:16 +00:00
|
|
|
|
|
|
|
|
2022-01-27 10:40:42 +00:00
|
|
|
@mock_glacier
|
|
|
|
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)
|
|
|
|
|
2023-07-27 22:47:15 +00:00
|
|
|
assert res["ResponseMetadata"]["HTTPStatusCode"] == 201
|
|
|
|
assert "checksum" in res
|
2022-01-27 10:40:42 +00:00
|
|
|
|
|
|
|
|
2021-09-23 17:22:16 +00:00
|
|
|
@mock_glacier
|
|
|
|
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"])
|
2023-07-27 22:47:15 +00:00
|
|
|
assert delete["ResponseMetadata"]["HTTPStatusCode"] == 204
|
2021-09-23 17:22:16 +00:00
|
|
|
|
|
|
|
with pytest.raises(Exception):
|
|
|
|
# Not ideal - but this will throw an error if the archvie 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",
|
|
|
|
},
|
|
|
|
)
|