Skip to content

Commit a8fa1d7

Browse files
authored
improve test (#547)
1 parent ace528b commit a8fa1d7

File tree

1 file changed

+26
-39
lines changed

1 file changed

+26
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,45 @@
1+
import pytest
2+
13
from linode_api4.objects.object_storage import (
24
ObjectStorageQuota,
35
ObjectStorageQuotaUsage,
46
)
57

68

7-
def test_list_obj_storage_quotas(test_linode_client):
9+
def test_list_and_get_obj_storage_quotas(test_linode_client):
810
quotas = test_linode_client.object_storage.quotas()
911

10-
target_quota_id = "obj-buckets-us-sea-1.linodeobjects.com"
11-
12-
found_quota = None
13-
for quota in quotas:
14-
if quota.quota_id == target_quota_id:
15-
found_quota = quota
16-
break
17-
18-
assert (
19-
found_quota is not None
20-
), f"Quota with ID {target_quota_id} not found."
21-
22-
assert found_quota.quota_id == "obj-buckets-us-sea-1.linodeobjects.com"
23-
assert found_quota.quota_name == "max_buckets"
24-
assert found_quota.endpoint_type == "E1"
25-
assert found_quota.s3_endpoint == "us-sea-1.linodeobjects.com"
26-
assert (
27-
found_quota.description
28-
== "Maximum number of buckets this customer is allowed to have on this endpoint"
29-
)
30-
assert found_quota.quota_limit == 1000
31-
assert found_quota.resource_metric == "bucket"
12+
if len(quotas) < 1:
13+
pytest.skip("No available quota for testing. Skipping now...")
3214

15+
found_quota = quotas[0]
3316

34-
def test_get_obj_storage_quota(test_linode_client):
35-
quota_id = "obj-objects-us-ord-1.linodeobjects.com"
36-
quota = test_linode_client.load(ObjectStorageQuota, quota_id)
37-
38-
assert quota.quota_id == "obj-objects-us-ord-1.linodeobjects.com"
39-
assert quota.quota_name == "max_objects"
40-
assert quota.endpoint_type == "E1"
41-
assert quota.s3_endpoint == "us-ord-1.linodeobjects.com"
42-
assert (
43-
quota.description
44-
== "Maximum number of objects this customer is allowed to have on this endpoint"
17+
get_quota = test_linode_client.load(
18+
ObjectStorageQuota, found_quota.quota_id
4519
)
46-
assert quota.quota_limit == 100000000
47-
assert quota.resource_metric == "object"
20+
21+
assert found_quota.quota_id == get_quota.quota_id
22+
assert found_quota.quota_name == get_quota.quota_name
23+
assert found_quota.endpoint_type == get_quota.endpoint_type
24+
assert found_quota.s3_endpoint == get_quota.s3_endpoint
25+
assert found_quota.description == get_quota.description
26+
assert found_quota.quota_limit == get_quota.quota_limit
27+
assert found_quota.resource_metric == get_quota.resource_metric
4828

4929

5030
def test_get_obj_storage_quota_usage(test_linode_client):
51-
quota_id = "obj-objects-us-ord-1.linodeobjects.com"
31+
quotas = test_linode_client.object_storage.quotas()
32+
33+
if len(quotas) < 1:
34+
pytest.skip("No available quota for testing. Skipping now...")
35+
36+
quota_id = quotas[0].quota_id
5237
quota = test_linode_client.load(ObjectStorageQuota, quota_id)
5338

5439
quota_usage = quota.usage()
5540

5641
assert isinstance(quota_usage, ObjectStorageQuotaUsage)
57-
assert quota_usage.quota_limit == 100000000
58-
assert quota_usage.usage >= 0
42+
assert quota_usage.quota_limit >= 0
43+
44+
if quota_usage.usage is not None:
45+
assert quota_usage.usage >= 0

0 commit comments

Comments
 (0)