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 os
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
import pytest
|
||||
|
||||
from moto import mock_glacier
|
||||
@ -14,14 +13,14 @@ def test_upload_archive():
|
||||
res = client.upload_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.should.have.key("x-amz-archive-id")
|
||||
headers.should.have.key("x-amz-sha256-tree-hash")
|
||||
assert "x-amz-archive-id" in headers
|
||||
assert "x-amz-sha256-tree-hash" in headers
|
||||
|
||||
res.should.have.key("checksum")
|
||||
res.should.have.key("archiveId")
|
||||
assert "checksum" in res
|
||||
assert "archiveId" in res
|
||||
|
||||
|
||||
@mock_glacier
|
||||
@ -35,8 +34,8 @@ def test_upload_zip_archive():
|
||||
|
||||
res = client.upload_archive(vaultName="asdf", body=content)
|
||||
|
||||
res["ResponseMetadata"]["HTTPStatusCode"].should.equal(201)
|
||||
res.should.have.key("checksum")
|
||||
assert res["ResponseMetadata"]["HTTPStatusCode"] == 201
|
||||
assert "checksum" in res
|
||||
|
||||
|
||||
@mock_glacier
|
||||
@ -47,7 +46,7 @@ def test_delete_archive():
|
||||
archive = client.upload_archive(vaultName="asdf", body=b"body of archive")
|
||||
|
||||
delete = client.delete_archive(vaultName="asdf", archiveId=archive["archiveId"])
|
||||
delete["ResponseMetadata"]["HTTPStatusCode"].should.equal(204)
|
||||
assert delete["ResponseMetadata"]["HTTPStatusCode"] == 204
|
||||
|
||||
with pytest.raises(Exception):
|
||||
# Not ideal - but this will throw an error if the archvie does not exist
|
||||
|
@ -1,5 +1,4 @@
|
||||
import boto3
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
import time
|
||||
|
||||
from moto import mock_glacier
|
||||
@ -17,19 +16,17 @@ def test_initiate_job():
|
||||
vaultName="myname",
|
||||
jobParameters={"ArchiveId": archive["archiveId"], "Type": "archive-retrieval"},
|
||||
)
|
||||
job["ResponseMetadata"]["HTTPStatusCode"].should.equal(202)
|
||||
assert job["ResponseMetadata"]["HTTPStatusCode"] == 202
|
||||
|
||||
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
|
||||
headers.should.have.key("location").match(
|
||||
"//vaults/myname/jobs/" + headers["x-amz-job-id"]
|
||||
)
|
||||
assert headers["location"] == "//vaults/myname/jobs/" + headers["x-amz-job-id"]
|
||||
|
||||
# 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
|
||||
job.should.have.key("jobId")
|
||||
job.should.have.key("location")
|
||||
assert "jobId" in job
|
||||
assert "location" in job
|
||||
|
||||
|
||||
@mock_glacier
|
||||
@ -46,18 +43,18 @@ def test_describe_job_boto3():
|
||||
job_id = job["jobId"]
|
||||
|
||||
describe = client.describe_job(vaultName="myname", jobId=job_id)
|
||||
describe.should.have.key("JobId").equal(job_id)
|
||||
describe.should.have.key("Action").equal("ArchiveRetrieval")
|
||||
describe.should.have.key("ArchiveId").equal(archive["archiveId"])
|
||||
describe.should.have.key("VaultARN").equal(
|
||||
f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/myname"
|
||||
assert describe["JobId"] == job_id
|
||||
assert describe["Action"] == "ArchiveRetrieval"
|
||||
assert describe["ArchiveId"] == archive["archiveId"]
|
||||
assert (
|
||||
describe["VaultARN"] == f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/myname"
|
||||
)
|
||||
describe.should.have.key("CreationDate")
|
||||
describe.should.have.key("Completed").equal(False)
|
||||
describe.should.have.key("StatusCode").equal("InProgress")
|
||||
describe.should.have.key("ArchiveSizeInBytes").equal(0)
|
||||
describe.should.have.key("InventorySizeInBytes").equal(0)
|
||||
describe.should.have.key("Tier").equal("Standard")
|
||||
assert "CreationDate" in describe
|
||||
assert describe["Completed"] is False
|
||||
assert describe["StatusCode"] == "InProgress"
|
||||
assert describe["ArchiveSizeInBytes"] == 0
|
||||
assert describe["InventorySizeInBytes"] == 0
|
||||
assert describe["Tier"] == "Standard"
|
||||
|
||||
|
||||
@mock_glacier
|
||||
@ -81,26 +78,26 @@ def test_list_jobs():
|
||||
|
||||
# Verify the created jobs are in this list
|
||||
found_jobs = [j["JobId"] for j in jobs]
|
||||
found_jobs.should.contain(job1["jobId"])
|
||||
found_jobs.should.contain(job2["jobId"])
|
||||
assert job1["jobId"] in found_jobs
|
||||
assert job2["jobId"] in found_jobs
|
||||
|
||||
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.should.have.key("ArchiveId").equal(archive2["archiveId"])
|
||||
assert found_job2["ArchiveId"] == archive2["archiveId"]
|
||||
|
||||
# Verify all jobs follow the correct format
|
||||
for job in jobs:
|
||||
job.should.have.key("JobId")
|
||||
job.should.have.key("Action")
|
||||
job.should.have.key("ArchiveId")
|
||||
job.should.have.key("VaultARN")
|
||||
job.should.have.key("CreationDate")
|
||||
job.should.have.key("ArchiveSizeInBytes")
|
||||
job.should.have.key("Completed")
|
||||
job.should.have.key("StatusCode")
|
||||
job.should.have.key("InventorySizeInBytes")
|
||||
job.should.have.key("Tier")
|
||||
assert "JobId" in job
|
||||
assert "Action" in job
|
||||
assert "ArchiveId" in job
|
||||
assert "VaultARN" in job
|
||||
assert "CreationDate" in job
|
||||
assert "ArchiveSizeInBytes" in job
|
||||
assert "Completed" in job
|
||||
assert "StatusCode" in job
|
||||
assert "InventorySizeInBytes" in job
|
||||
assert "Tier" in job
|
||||
|
||||
|
||||
@mock_glacier
|
||||
@ -124,9 +121,9 @@ def test_get_job_output_boto3():
|
||||
except Exception:
|
||||
time.sleep(1)
|
||||
|
||||
output.should.have.key("status").equal(200)
|
||||
output.should.have.key("contentType").equal("application/octet-stream")
|
||||
output.should.have.key("body")
|
||||
assert output["status"] == 200
|
||||
assert output["contentType"] == "application/octet-stream"
|
||||
assert "body" in output
|
||||
|
||||
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 sure # noqa # pylint: disable=unused-import
|
||||
import pytest
|
||||
|
||||
from moto import mock_glacier
|
||||
@ -14,13 +13,13 @@ def test_describe_vault():
|
||||
client.create_vault(vaultName="myvault")
|
||||
|
||||
describe = client.describe_vault(vaultName="myvault")
|
||||
describe.should.have.key("NumberOfArchives").equal(0)
|
||||
describe.should.have.key("SizeInBytes").equal(0)
|
||||
describe.should.have.key("LastInventoryDate")
|
||||
describe.should.have.key("CreationDate")
|
||||
describe.should.have.key("VaultName").equal("myvault")
|
||||
describe.should.have.key("VaultARN").equal(
|
||||
f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/myvault"
|
||||
assert describe["NumberOfArchives"] == 0
|
||||
assert describe["SizeInBytes"] == 0
|
||||
assert "LastInventoryDate" in describe
|
||||
assert "CreationDate" in describe
|
||||
assert describe["VaultName"] == "myvault"
|
||||
assert (
|
||||
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
|
||||
vaults = client.list_vaults()["VaultList"]
|
||||
found_vaults = [v["VaultName"] for v in vaults]
|
||||
found_vaults.shouldnt.contain(vault1_name)
|
||||
found_vaults.shouldnt.contain(vault2_name)
|
||||
assert vault1_name not in found_vaults
|
||||
assert vault2_name not in found_vaults
|
||||
|
||||
client.create_vault(vaultName=vault1_name)
|
||||
client.create_vault(vaultName=vault2_name)
|
||||
@ -55,19 +54,20 @@ def test_list_vaults():
|
||||
# Verify we can find the created vaults
|
||||
vaults = client.list_vaults()["VaultList"]
|
||||
found_vaults = [v["VaultName"] for v in vaults]
|
||||
found_vaults.should.contain(vault1_name)
|
||||
found_vaults.should.contain(vault2_name)
|
||||
assert vault1_name in found_vaults
|
||||
assert vault2_name in found_vaults
|
||||
|
||||
# Verify all the vaults are in the correct format
|
||||
for vault in vaults:
|
||||
vault.should.have.key("NumberOfArchives").equal(0)
|
||||
vault.should.have.key("SizeInBytes").equal(0)
|
||||
vault.should.have.key("LastInventoryDate")
|
||||
vault.should.have.key("CreationDate")
|
||||
vault.should.have.key("VaultName")
|
||||
assert vault["NumberOfArchives"] == 0
|
||||
assert vault["SizeInBytes"] == 0
|
||||
assert "LastInventoryDate" in vault
|
||||
assert "CreationDate" in vault
|
||||
assert "VaultName" in vault
|
||||
vault_name = vault["VaultName"]
|
||||
vault.should.have.key("VaultARN").equal(
|
||||
f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/{vault_name}"
|
||||
assert (
|
||||
vault["VaultARN"]
|
||||
== f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/{vault_name}"
|
||||
)
|
||||
|
||||
# Verify a deleted vault is no longer returned
|
||||
@ -75,8 +75,8 @@ def test_list_vaults():
|
||||
|
||||
vaults = client.list_vaults()["VaultList"]
|
||||
found_vaults = [v["VaultName"] for v in vaults]
|
||||
found_vaults.shouldnt.contain(vault1_name)
|
||||
found_vaults.should.contain(vault2_name)
|
||||
assert vault1_name not in found_vaults
|
||||
assert vault2_name in found_vaults
|
||||
|
||||
|
||||
@mock_glacier
|
||||
@ -84,4 +84,4 @@ def test_vault_name_with_special_characters():
|
||||
vault_name = "Vault.name-with_Special.characters"
|
||||
glacier = boto3.resource("glacier", region_name="us-west-2")
|
||||
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 sure # noqa # pylint: disable=unused-import
|
||||
|
||||
import moto.server as server
|
||||
from moto import mock_glacier
|
||||
@ -16,4 +15,4 @@ def test_list_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