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,20 @@ 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 ((quota for quota in quotas if quota .has_usage ), None )
41+
42+ if quota_with_usage is None :
43+ quota_id = quotas [0 ].quota_id
44+ quota = test_linode_client .load (ObjectStorageQuota , quota_id )
45+
46+ with pytest .raises (ApiError ) as exc :
47+ quota .usage ()
48+
49+ assert exc .value .status == 404
50+ assert "Usage not supported" in str (exc .value )
51+ return
52+
53+ quota_id = quota_with_usage .quota_id
3754 quota = test_linode_client .load (ObjectStorageQuota , quota_id )
3855
3956 quota_usage = quota .usage ()
@@ -43,3 +60,65 @@ def test_get_obj_storage_quota_usage(test_linode_client):
4360
4461 if quota_usage .usage is not None :
4562 assert quota_usage .usage >= 0
63+
64+
65+ def test_list_and_get_obj_storage_global_quotas (test_linode_client ):
66+ try :
67+ quotas = test_linode_client .object_storage .global_quotas ()
68+ except ApiError as err :
69+ if err .status == 404 :
70+ pytest .skip ("Object Storage is not enabled on this account." )
71+ raise
72+
73+ if len (quotas ) < 1 :
74+ pytest .skip ("No available global quota for testing. Skipping now..." )
75+
76+ found_quota = quotas [0 ]
77+
78+ get_quota = test_linode_client .load (
79+ ObjectStorageGlobalQuota , found_quota .quota_id
80+ )
81+
82+ assert found_quota .quota_id == get_quota .quota_id
83+ assert found_quota .quota_type == get_quota .quota_type
84+ assert found_quota .quota_name == get_quota .quota_name
85+ assert found_quota .description == get_quota .description
86+ assert found_quota .resource_metric == get_quota .resource_metric
87+ assert found_quota .quota_limit == get_quota .quota_limit
88+ assert found_quota .has_usage == get_quota .has_usage
89+
90+
91+ def test_get_obj_storage_global_quota_usage (test_linode_client ):
92+ try :
93+ quotas = test_linode_client .object_storage .global_quotas ()
94+ except ApiError as err :
95+ if err .status == 404 :
96+ pytest .skip ("Object Storage is not enabled on this account." )
97+ raise
98+
99+ if len (quotas ) < 1 :
100+ pytest .skip ("No available global quota for testing. Skipping now..." )
101+
102+ quota_with_usage = next ((quota for quota in quotas if quota .has_usage ), None )
103+
104+ if quota_with_usage is None :
105+ quota_id = quotas [0 ].quota_id
106+ quota = test_linode_client .load (ObjectStorageGlobalQuota , quota_id )
107+
108+ with pytest .raises (ApiError ) as exc :
109+ quota .usage ()
110+
111+ assert exc .value .status == 404
112+ assert "Usage not supported" in str (exc .value )
113+ return
114+
115+ quota_id = quota_with_usage .quota_id
116+ quota = test_linode_client .load (ObjectStorageGlobalQuota , quota_id )
117+
118+ quota_usage = quota .usage ()
119+
120+ assert isinstance (quota_usage , ObjectStorageQuotaUsage )
121+ assert quota_usage .quota_limit >= 0
122+
123+ if quota_usage .usage is not None :
124+ assert quota_usage .usage >= 0
0 commit comments