@@ -26,6 +26,7 @@ def usage_alerts_client(config):
2626 }
2727 )
2828 from ns1 import NS1
29+
2930 client = NS1 (config = config )
3031 return client
3132
@@ -45,7 +46,7 @@ def test_create_usage_alert(usage_alerts_client):
4546 "notifier_list_ids" : ["n1" ],
4647 "zone_names" : [],
4748 "created_at" : 1597937213 ,
48- "updated_at" : 1597937213
49+ "updated_at" : 1597937213 ,
4950 }
5051
5152 # Patch the client reference
@@ -54,7 +55,7 @@ def test_create_usage_alert(usage_alerts_client):
5455 name = "Test Alert" ,
5556 subtype = "query_usage" ,
5657 alert_at_percent = 85 ,
57- notifier_list_ids = ["n1" ]
58+ notifier_list_ids = ["n1" ],
5859 )
5960
6061 # Verify _post was called with correct arguments
@@ -64,10 +65,11 @@ def test_create_usage_alert(usage_alerts_client):
6465 "subtype" : "query_usage" ,
6566 "data" : {"alert_at_percent" : 85 },
6667 "notifier_list_ids" : ["n1" ],
67- "zone_names" : []
68+ "zone_names" : [],
6869 }
6970 client ._post .assert_called_once_with (
70- "/alerting/v1/alerts" , json = expected_body )
71+ "/alerting/v1/alerts" , json = expected_body
72+ )
7173
7274 # Verify result
7375 assert alert ["id" ] == "a1b2c3"
@@ -91,7 +93,7 @@ def test_get_usage_alert(usage_alerts_client):
9193 "subtype" : "query_usage" ,
9294 "data" : {"alert_at_percent" : 85 },
9395 "notifier_list_ids" : ["n1" ],
94- "zone_names" : []
96+ "zone_names" : [],
9597 }
9698
9799 # Patch the client reference
@@ -121,24 +123,20 @@ def test_patch_usage_alert(usage_alerts_client):
121123 "subtype" : "query_usage" ,
122124 "data" : {"alert_at_percent" : 90 },
123125 "notifier_list_ids" : ["n1" ],
124- "zone_names" : []
126+ "zone_names" : [],
125127 }
126128
127129 # Patch the client reference
128130 with mock .patch .object (client .alerting ().usage , "_c" , client ):
129131 alert = client .alerting ().usage .patch (
130- alert_id ,
131- name = "Updated Alert" ,
132- alert_at_percent = 90
132+ alert_id , name = "Updated Alert" , alert_at_percent = 90
133133 )
134134
135135 # Verify _patch was called with correct arguments
136- expected_body = {
137- "name" : "Updated Alert" ,
138- "data" : {"alert_at_percent" : 90 }
139- }
136+ expected_body = {"name" : "Updated Alert" , "data" : {"alert_at_percent" : 90 }}
140137 client ._patch .assert_called_once_with (
141- f"/alerting/v1/alerts/{ alert_id } " , json = expected_body )
138+ f"/alerting/v1/alerts/{ alert_id } " , json = expected_body
139+ )
142140
143141 # Verify type/subtype are not in the arguments
144142 call_args = client ._patch .call_args [1 ]["json" ]
@@ -183,25 +181,20 @@ def test_list_usage_alerts(usage_alerts_client):
183181 "name" : "Alert 1" ,
184182 "type" : "account" ,
185183 "subtype" : "query_usage" ,
186- "data" : {"alert_at_percent" : 80 }
184+ "data" : {"alert_at_percent" : 80 },
187185 }
188- ]
186+ ],
189187 }
190188
191189 # Patch the client reference
192190 with mock .patch .object (client .alerting ().usage , "_c" , client ):
193- response = client .alerting ().usage .list (
194- limit = 1 ,
195- order_descending = True
196- )
191+ response = client .alerting ().usage .list (limit = 1 , order_descending = True )
197192
198193 # Verify _get was called with correct URL and params
199- expected_params = {
200- "limit" : 1 ,
201- "order_descending" : "true"
202- }
194+ expected_params = {"limit" : 1 , "order_descending" : "true" }
203195 client ._get .assert_called_once_with (
204- "/alerting/v1/alerts" , params = expected_params )
196+ "/alerting/v1/alerts" , params = expected_params
197+ )
205198
206199 # Verify result
207200 assert "results" in response
@@ -219,27 +212,20 @@ def test_validation_threshold_bounds(usage_alerts_client):
219212 # Test below minimum
220213 with pytest .raises (ValueError ) as excinfo :
221214 client .alerting ().usage .create (
222- name = "Test Alert" ,
223- subtype = "query_usage" ,
224- alert_at_percent = 0
215+ name = "Test Alert" , subtype = "query_usage" , alert_at_percent = 0
225216 )
226217 assert "alert_at_percent must be int in 1..100" in str (excinfo .value )
227218
228219 # Test above maximum
229220 with pytest .raises (ValueError ) as excinfo :
230221 client .alerting ().usage .create (
231- name = "Test Alert" ,
232- subtype = "query_usage" ,
233- alert_at_percent = 101
222+ name = "Test Alert" , subtype = "query_usage" , alert_at_percent = 101
234223 )
235224 assert "alert_at_percent must be int in 1..100" in str (excinfo .value )
236225
237226 # Test same validation in patch
238227 with pytest .raises (ValueError ) as excinfo :
239- client .alerting ().usage .patch (
240- "a1" ,
241- alert_at_percent = 101
242- )
228+ client .alerting ().usage .patch ("a1" , alert_at_percent = 101 )
243229 assert "alert_at_percent must be int in 1..100" in str (excinfo .value )
244230
245231
0 commit comments