2021-05-27 07:44:20 +00:00
|
|
|
import boto3
|
2021-09-23 17:22:16 +00:00
|
|
|
import pytest
|
2018-12-21 11:28:56 +00:00
|
|
|
|
2023-11-09 23:17:46 +00:00
|
|
|
from botocore.exceptions import ClientError
|
2022-01-18 15:18:57 +00:00
|
|
|
from moto import mock_glacier
|
2022-08-13 09:49:43 +00:00
|
|
|
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
2021-09-23 17:22:16 +00:00
|
|
|
from uuid import uuid4
|
2018-12-21 11:28:56 +00:00
|
|
|
|
|
|
|
|
2021-09-23 17:22:16 +00:00
|
|
|
@mock_glacier
|
|
|
|
def test_describe_vault():
|
|
|
|
client = boto3.client("glacier", region_name="us-west-2")
|
|
|
|
|
|
|
|
client.create_vault(vaultName="myvault")
|
|
|
|
|
|
|
|
describe = client.describe_vault(vaultName="myvault")
|
2023-07-27 22:47:15 +00:00
|
|
|
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"
|
2021-09-23 17:22:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@mock_glacier
|
|
|
|
def test_delete_vault_boto3():
|
|
|
|
client = boto3.client("glacier", region_name="us-west-2")
|
|
|
|
|
|
|
|
client.create_vault(vaultName="myvault")
|
|
|
|
|
|
|
|
client.delete_vault(vaultName="myvault")
|
|
|
|
|
2023-11-09 23:17:46 +00:00
|
|
|
with pytest.raises(ClientError) as exc:
|
2021-09-23 17:22:16 +00:00
|
|
|
client.describe_vault(vaultName="myvault")
|
2023-11-09 23:17:46 +00:00
|
|
|
err = exc.value.response["Error"]
|
|
|
|
assert err["Code"] == "VaultNotFound"
|
2021-09-23 17:22:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_glacier
|
|
|
|
def test_list_vaults():
|
|
|
|
client = boto3.client("glacier", region_name="us-west-2")
|
|
|
|
|
|
|
|
vault1_name = str(uuid4())[0:6]
|
|
|
|
vault2_name = str(uuid4())[0:6]
|
|
|
|
|
|
|
|
# Verify we cannot find these vaults yet
|
|
|
|
vaults = client.list_vaults()["VaultList"]
|
|
|
|
found_vaults = [v["VaultName"] for v in vaults]
|
2023-07-27 22:47:15 +00:00
|
|
|
assert vault1_name not in found_vaults
|
|
|
|
assert vault2_name not in found_vaults
|
2021-09-23 17:22:16 +00:00
|
|
|
|
|
|
|
client.create_vault(vaultName=vault1_name)
|
|
|
|
client.create_vault(vaultName=vault2_name)
|
|
|
|
|
|
|
|
# Verify we can find the created vaults
|
|
|
|
vaults = client.list_vaults()["VaultList"]
|
|
|
|
found_vaults = [v["VaultName"] for v in vaults]
|
2023-07-27 22:47:15 +00:00
|
|
|
assert vault1_name in found_vaults
|
|
|
|
assert vault2_name in found_vaults
|
2021-09-23 17:22:16 +00:00
|
|
|
|
|
|
|
# Verify all the vaults are in the correct format
|
|
|
|
for vault in vaults:
|
2023-07-27 22:47:15 +00:00
|
|
|
assert vault["NumberOfArchives"] == 0
|
|
|
|
assert vault["SizeInBytes"] == 0
|
|
|
|
assert "LastInventoryDate" in vault
|
|
|
|
assert "CreationDate" in vault
|
|
|
|
assert "VaultName" in vault
|
2021-09-23 17:22:16 +00:00
|
|
|
vault_name = vault["VaultName"]
|
2023-07-27 22:47:15 +00:00
|
|
|
assert (
|
|
|
|
vault["VaultARN"]
|
|
|
|
== f"arn:aws:glacier:us-west-2:{ACCOUNT_ID}:vaults/{vault_name}"
|
2021-09-23 17:22:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Verify a deleted vault is no longer returned
|
|
|
|
client.delete_vault(vaultName=vault1_name)
|
|
|
|
|
|
|
|
vaults = client.list_vaults()["VaultList"]
|
|
|
|
found_vaults = [v["VaultName"] for v in vaults]
|
2023-07-27 22:47:15 +00:00
|
|
|
assert vault1_name not in found_vaults
|
|
|
|
assert vault2_name in found_vaults
|
2021-09-23 17:22:16 +00:00
|
|
|
|
|
|
|
|
2021-05-27 07:44:20 +00:00
|
|
|
@mock_glacier
|
|
|
|
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)
|
2023-07-27 22:47:15 +00:00
|
|
|
assert vault.name == vault_name
|