11import pytest
22
3+ from linode_api4 .errors import ApiError
34from linode_api4 .objects .object_storage import (
5+ ObjectStorageGlobalQuota ,
46 ObjectStorageQuota ,
57 ObjectStorageQuotaUsage ,
68)
@@ -25,6 +27,8 @@ def test_list_and_get_obj_storage_quotas(test_linode_client):
2527 assert found_quota .description == get_quota .description
2628 assert found_quota .quota_limit == get_quota .quota_limit
2729 assert found_quota .resource_metric == get_quota .resource_metric
30+ assert found_quota .quota_type == get_quota .quota_type
31+ assert found_quota .has_usage == get_quota .has_usage
2832
2933
3034def test_get_obj_storage_quota_usage (test_linode_client ):
@@ -33,7 +37,21 @@ def test_get_obj_storage_quota_usage(test_linode_client):
3337 if len (quotas ) < 1 :
3438 pytest .skip ("No available quota for testing. Skipping now..." )
3539
36- quota_id = quotas [0 ].quota_id
40+ quota_with_usage = next (
41+ (quota for quota in quotas if quota .has_usage ), None
42+ )
43+
44+ if quota_with_usage is None :
45+ quota_id = quotas [0 ].quota_id
46+ quota = test_linode_client .load (ObjectStorageQuota , quota_id )
47+
48+ # quota without usage should return an API error on usage retrieval
49+ with pytest .raises (ApiError ):
50+ quota .usage ()
51+
52+ return
53+
54+ quota_id = quota_with_usage .quota_id
3755 quota = test_linode_client .load (ObjectStorageQuota , quota_id )
3856
3957 quota_usage = quota .usage ()
@@ -43,3 +61,56 @@ def test_get_obj_storage_quota_usage(test_linode_client):
4361
4462 if quota_usage .usage is not None :
4563 assert quota_usage .usage >= 0
64+
65+
66+ def test_list_and_get_obj_storage_global_quotas (test_linode_client ):
67+ quotas = test_linode_client .object_storage .global_quotas ()
68+
69+ if len (quotas ) < 1 :
70+ pytest .skip ("No available global quota for testing. Skipping now..." )
71+
72+ found_quota = quotas [0 ]
73+
74+ get_quota = test_linode_client .load (
75+ ObjectStorageGlobalQuota , found_quota .quota_id
76+ )
77+
78+ assert found_quota .quota_id == get_quota .quota_id
79+ assert found_quota .quota_type == get_quota .quota_type
80+ assert found_quota .quota_name == get_quota .quota_name
81+ assert found_quota .description == get_quota .description
82+ assert found_quota .resource_metric == get_quota .resource_metric
83+ assert found_quota .quota_limit == get_quota .quota_limit
84+ assert found_quota .has_usage == get_quota .has_usage
85+
86+
87+ def test_get_obj_storage_global_quota_usage (test_linode_client ):
88+ quotas = test_linode_client .object_storage .global_quotas ()
89+
90+ if len (quotas ) < 1 :
91+ pytest .skip ("No available global quota for testing. Skipping now..." )
92+
93+ quota_with_usage = next (
94+ (quota for quota in quotas if quota .has_usage ), None
95+ )
96+
97+ if quota_with_usage is None :
98+ quota_id = quotas [0 ].quota_id
99+ quota = test_linode_client .load (ObjectStorageGlobalQuota , quota_id )
100+
101+ # quota without usage should return an API error on usage retrieval
102+ with pytest .raises (ApiError ):
103+ quota .usage ()
104+
105+ return
106+
107+ quota_id = quota_with_usage .quota_id
108+ quota = test_linode_client .load (ObjectStorageGlobalQuota , quota_id )
109+
110+ quota_usage = quota .usage ()
111+
112+ assert isinstance (quota_usage , ObjectStorageQuotaUsage )
113+ assert quota_usage .quota_limit >= 0
114+
115+ if quota_usage .usage is not None :
116+ assert quota_usage .usage >= 0
0 commit comments