Techdebt: Replace sure with regular assertions in Glacier (#6566)
This commit is contained in:
parent
a68a035038
commit
b52fd80cb1
@ -1,6 +1,5 @@
|
|||||||
import boto3
|
import boto3
|
||||||
import os
|
import os
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from moto import mock_glacier
|
from moto import mock_glacier
|
||||||
@ -14,14 +13,14 @@ def test_upload_archive():
|
|||||||
res = client.upload_archive(
|
res = client.upload_archive(
|
||||||
vaultName="asdf", archiveDescription="my archive", body=b"body of archive"
|
vaultName="asdf", archiveDescription="my archive", body=b"body of archive"
|
||||||
)
|
)
|
||||||
res["ResponseMetadata"]["HTTPStatusCode"].should.equal(201)
|
assert res["ResponseMetadata"]["HTTPStatusCode"] == 201
|
||||||
headers = res["ResponseMetadata"]["HTTPHeaders"]
|
headers = res["ResponseMetadata"]["HTTPHeaders"]
|
||||||
|
|
||||||
headers.should.have.key("x-amz-archive-id")
|
assert "x-amz-archive-id" in headers
|
||||||
headers.should.have.key("x-amz-sha256-tree-hash")
|
assert "x-amz-sha256-tree-hash" in headers
|
||||||
|
|
||||||
res.should.have.key("checksum")
|
assert "checksum" in res
|
||||||
res.should.have.key("archiveId")
|
assert "archiveId" in res
|
||||||
|
|
||||||
|
|
||||||
@mock_glacier
|
@mock_glacier
|
||||||
@ -35,8 +34,8 @@ def test_upload_zip_archive():
|
|||||||
|
|
||||||
res = client.upload_archive(vaultName="asdf", body=content)
|
res = client.upload_archive(vaultName="asdf", body=content)
|
||||||
|
|
||||||
res["ResponseMetadata"]["HTTPStatusCode"].should.equal(201)
|
assert res["ResponseMetadata"]["HTTPStatusCode"] == 201
|
||||||
res.should.have.key("checksum")
|
assert "checksum" in res
|
||||||
|
|
||||||
|
|
||||||
@mock_glacier
|
@mock_glacier
|
||||||
@ -47,7 +46,7 @@ def test_delete_archive():
|
|||||||
archive = client.upload_archive(vaultName="asdf", body=b"body of archive")
|
archive = client.upload_archive(vaultName="asdf", body=b"body of archive")
|
||||||
|
|
||||||
delete = client.delete_archive(vaultName="asdf", archiveId=archive["archiveId"])
|
delete = client.delete_archive(vaultName="asdf", archiveId=archive["archiveId"])
|
||||||
delete["ResponseMetadata"]["HTTPStatusCode"].should.equal(204)
|
assert delete["ResponseMetadata"]["HTTPStatusCode"] == 204
|
||||||
|
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
# Not ideal - but this will throw an error if the archvie does not exist
|
# Not ideal - but this will throw an error if the archvie does not exist
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import boto3
|
import boto3
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from moto import mock_glacier
|
from moto import mock_glacier
|
||||||
@ -17,19 +16,17 @@ def test_initiate_job():
|
|||||||
vaultName="myname",
|
vaultName="myname",
|
||||||
jobParameters={"ArchiveId": archive["archiveId"], "Type": "archive-retrieval"},
|
jobParameters={"ArchiveId": archive["archiveId"], "Type": "archive-retrieval"},
|
||||||
)
|
)
|
||||||
job["ResponseMetadata"]["HTTPStatusCode"].should.equal(202)
|
assert job["ResponseMetadata"]["HTTPStatusCode"] == 202
|
||||||
|
|
||||||
headers = job["ResponseMetadata"]["HTTPHeaders"]
|
headers = job["ResponseMetadata"]["HTTPHeaders"]
|
||||||
headers.should.have.key("x-amz-job-id")
|
assert "x-amz-job-id" in headers
|
||||||
# Should be an exact match, but Flask adds 'http' to the start of the Location-header
|
# Should be an exact match, but Flask adds 'http' to the start of the Location-header
|
||||||
headers.should.have.key("location").match(
|
assert headers["location"] == "//vaults/myname/jobs/" + headers["x-amz-job-id"]
|
||||||
"//vaults/myname/jobs/" + headers["x-amz-job-id"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Don't think this is correct - the spec says no body is returned, only headers
|
# Don't think this is correct - the spec says no body is returned, only headers
|
||||||
# https://docs.aws.amazon.com/amazonglacier/latest/dev/api-initiate-job-post.html
|
# https://docs.aws.amazon.com/amazonglacier/latest/dev/api-initiate-job-post.html
|
||||||
job.should.have.key("jobId")
|
assert "jobId" in job
|
||||||
job.should.have.key("location")
|
assert "location" in job
|
||||||
|
|
||||||
|
|
||||||
@mock_glacier
|
@mock_glacier
|
||||||
@ -46,18 +43,18 @@ def test_describe_job_boto3():
|
|||||||
job_id = job["jobId"]
|
job_id = job["jobId"]
|
||||||
|
|
||||||
describe = client.describe_job(vaultName="myname", jobId=job_id)
|
describe = client.describe_job(vaultName="myname", jobId=job_id)
|
||||||
describe.should.have.key("JobId").equal(job_id)
|
assert describe["JobId"] == job_id
|
||||||
describe.should.have.key("Action").equal("ArchiveRetrieval")
|
assert describe["Action"] == "ArchiveRetrieval"
|
||||||
describe.should.have.key("ArchiveId").equal(archive["archiveId"])
|
assert describe["ArchiveId"] == archive["archiveId"]
|
||||||
describe.should.have.key("VaultARN").equal(
|
assert (
|
||||||
f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/myname"
|
describe["VaultARN"] == f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/myname"
|
||||||
)
|
)
|
||||||
describe.should.have.key("CreationDate")
|
assert "CreationDate" in describe
|
||||||
describe.should.have.key("Completed").equal(False)
|
assert describe["Completed"] is False
|
||||||
describe.should.have.key("StatusCode").equal("InProgress")
|
assert describe["StatusCode"] == "InProgress"
|
||||||
describe.should.have.key("ArchiveSizeInBytes").equal(0)
|
assert describe["ArchiveSizeInBytes"] == 0
|
||||||
describe.should.have.key("InventorySizeInBytes").equal(0)
|
assert describe["InventorySizeInBytes"] == 0
|
||||||
describe.should.have.key("Tier").equal("Standard")
|
assert describe["Tier"] == "Standard"
|
||||||
|
|
||||||
|
|
||||||
@mock_glacier
|
@mock_glacier
|
||||||
@ -81,26 +78,26 @@ def test_list_jobs():
|
|||||||
|
|
||||||
# Verify the created jobs are in this list
|
# Verify the created jobs are in this list
|
||||||
found_jobs = [j["JobId"] for j in jobs]
|
found_jobs = [j["JobId"] for j in jobs]
|
||||||
found_jobs.should.contain(job1["jobId"])
|
assert job1["jobId"] in found_jobs
|
||||||
found_jobs.should.contain(job2["jobId"])
|
assert job2["jobId"] in found_jobs
|
||||||
|
|
||||||
found_job1 = [j for j in jobs if j["JobId"] == job1["jobId"]][0]
|
found_job1 = [j for j in jobs if j["JobId"] == job1["jobId"]][0]
|
||||||
found_job1.should.have.key("ArchiveId").equal(archive1["archiveId"])
|
assert found_job1["ArchiveId"] == archive1["archiveId"]
|
||||||
found_job2 = [j for j in jobs if j["JobId"] == job2["jobId"]][0]
|
found_job2 = [j for j in jobs if j["JobId"] == job2["jobId"]][0]
|
||||||
found_job2.should.have.key("ArchiveId").equal(archive2["archiveId"])
|
assert found_job2["ArchiveId"] == archive2["archiveId"]
|
||||||
|
|
||||||
# Verify all jobs follow the correct format
|
# Verify all jobs follow the correct format
|
||||||
for job in jobs:
|
for job in jobs:
|
||||||
job.should.have.key("JobId")
|
assert "JobId" in job
|
||||||
job.should.have.key("Action")
|
assert "Action" in job
|
||||||
job.should.have.key("ArchiveId")
|
assert "ArchiveId" in job
|
||||||
job.should.have.key("VaultARN")
|
assert "VaultARN" in job
|
||||||
job.should.have.key("CreationDate")
|
assert "CreationDate" in job
|
||||||
job.should.have.key("ArchiveSizeInBytes")
|
assert "ArchiveSizeInBytes" in job
|
||||||
job.should.have.key("Completed")
|
assert "Completed" in job
|
||||||
job.should.have.key("StatusCode")
|
assert "StatusCode" in job
|
||||||
job.should.have.key("InventorySizeInBytes")
|
assert "InventorySizeInBytes" in job
|
||||||
job.should.have.key("Tier")
|
assert "Tier" in job
|
||||||
|
|
||||||
|
|
||||||
@mock_glacier
|
@mock_glacier
|
||||||
@ -124,9 +121,9 @@ def test_get_job_output_boto3():
|
|||||||
except Exception:
|
except Exception:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
output.should.have.key("status").equal(200)
|
assert output["status"] == 200
|
||||||
output.should.have.key("contentType").equal("application/octet-stream")
|
assert output["contentType"] == "application/octet-stream"
|
||||||
output.should.have.key("body")
|
assert "body" in output
|
||||||
|
|
||||||
body = output["body"].read().decode("utf-8")
|
body = output["body"].read().decode("utf-8")
|
||||||
body.should.equal("contents of archive")
|
assert body == "contents of archive"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import boto3
|
import boto3
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from moto import mock_glacier
|
from moto import mock_glacier
|
||||||
@ -14,13 +13,13 @@ def test_describe_vault():
|
|||||||
client.create_vault(vaultName="myvault")
|
client.create_vault(vaultName="myvault")
|
||||||
|
|
||||||
describe = client.describe_vault(vaultName="myvault")
|
describe = client.describe_vault(vaultName="myvault")
|
||||||
describe.should.have.key("NumberOfArchives").equal(0)
|
assert describe["NumberOfArchives"] == 0
|
||||||
describe.should.have.key("SizeInBytes").equal(0)
|
assert describe["SizeInBytes"] == 0
|
||||||
describe.should.have.key("LastInventoryDate")
|
assert "LastInventoryDate" in describe
|
||||||
describe.should.have.key("CreationDate")
|
assert "CreationDate" in describe
|
||||||
describe.should.have.key("VaultName").equal("myvault")
|
assert describe["VaultName"] == "myvault"
|
||||||
describe.should.have.key("VaultARN").equal(
|
assert (
|
||||||
f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/myvault"
|
describe["VaultARN"] == f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/myvault"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -46,8 +45,8 @@ def test_list_vaults():
|
|||||||
# Verify we cannot find these vaults yet
|
# Verify we cannot find these vaults yet
|
||||||
vaults = client.list_vaults()["VaultList"]
|
vaults = client.list_vaults()["VaultList"]
|
||||||
found_vaults = [v["VaultName"] for v in vaults]
|
found_vaults = [v["VaultName"] for v in vaults]
|
||||||
found_vaults.shouldnt.contain(vault1_name)
|
assert vault1_name not in found_vaults
|
||||||
found_vaults.shouldnt.contain(vault2_name)
|
assert vault2_name not in found_vaults
|
||||||
|
|
||||||
client.create_vault(vaultName=vault1_name)
|
client.create_vault(vaultName=vault1_name)
|
||||||
client.create_vault(vaultName=vault2_name)
|
client.create_vault(vaultName=vault2_name)
|
||||||
@ -55,19 +54,20 @@ def test_list_vaults():
|
|||||||
# Verify we can find the created vaults
|
# Verify we can find the created vaults
|
||||||
vaults = client.list_vaults()["VaultList"]
|
vaults = client.list_vaults()["VaultList"]
|
||||||
found_vaults = [v["VaultName"] for v in vaults]
|
found_vaults = [v["VaultName"] for v in vaults]
|
||||||
found_vaults.should.contain(vault1_name)
|
assert vault1_name in found_vaults
|
||||||
found_vaults.should.contain(vault2_name)
|
assert vault2_name in found_vaults
|
||||||
|
|
||||||
# Verify all the vaults are in the correct format
|
# Verify all the vaults are in the correct format
|
||||||
for vault in vaults:
|
for vault in vaults:
|
||||||
vault.should.have.key("NumberOfArchives").equal(0)
|
assert vault["NumberOfArchives"] == 0
|
||||||
vault.should.have.key("SizeInBytes").equal(0)
|
assert vault["SizeInBytes"] == 0
|
||||||
vault.should.have.key("LastInventoryDate")
|
assert "LastInventoryDate" in vault
|
||||||
vault.should.have.key("CreationDate")
|
assert "CreationDate" in vault
|
||||||
vault.should.have.key("VaultName")
|
assert "VaultName" in vault
|
||||||
vault_name = vault["VaultName"]
|
vault_name = vault["VaultName"]
|
||||||
vault.should.have.key("VaultARN").equal(
|
assert (
|
||||||
f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/{vault_name}"
|
vault["VaultARN"]
|
||||||
|
== f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/{vault_name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify a deleted vault is no longer returned
|
# Verify a deleted vault is no longer returned
|
||||||
@ -75,8 +75,8 @@ def test_list_vaults():
|
|||||||
|
|
||||||
vaults = client.list_vaults()["VaultList"]
|
vaults = client.list_vaults()["VaultList"]
|
||||||
found_vaults = [v["VaultName"] for v in vaults]
|
found_vaults = [v["VaultName"] for v in vaults]
|
||||||
found_vaults.shouldnt.contain(vault1_name)
|
assert vault1_name not in found_vaults
|
||||||
found_vaults.should.contain(vault2_name)
|
assert vault2_name in found_vaults
|
||||||
|
|
||||||
|
|
||||||
@mock_glacier
|
@mock_glacier
|
||||||
@ -84,4 +84,4 @@ def test_vault_name_with_special_characters():
|
|||||||
vault_name = "Vault.name-with_Special.characters"
|
vault_name = "Vault.name-with_Special.characters"
|
||||||
glacier = boto3.resource("glacier", region_name="us-west-2")
|
glacier = boto3.resource("glacier", region_name="us-west-2")
|
||||||
vault = glacier.create_vault(accountId="-", vaultName=vault_name)
|
vault = glacier.create_vault(accountId="-", vaultName=vault_name)
|
||||||
vault.name.should.equal(vault_name)
|
assert vault.name == vault_name
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import json
|
import json
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
|
|
||||||
import moto.server as server
|
import moto.server as server
|
||||||
from moto import mock_glacier
|
from moto import mock_glacier
|
||||||
@ -16,4 +15,4 @@ def test_list_vaults():
|
|||||||
|
|
||||||
res = test_client.get("/1234bcd/vaults")
|
res = test_client.get("/1234bcd/vaults")
|
||||||
|
|
||||||
json.loads(res.data.decode("utf-8")).should.equal({"Marker": None, "VaultList": []})
|
assert json.loads(res.data.decode("utf-8")) == {"Marker": None, "VaultList": []}
|
||||||
|
Loading…
Reference in New Issue
Block a user