Skip to content

Commit d59a98a

Browse files
committed
fixed review comments from APIv4 team
1 parent 546d3fb commit d59a98a

File tree

5 files changed

+18
-63
lines changed

5 files changed

+18
-63
lines changed

linode_api4/groups/monitor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
from linode_api4.groups import Group
99
from linode_api4.objects import (
1010
AlertChannel,
11-
AlertChannelEnvelope,
1211
AlertDefinition,
1312
MonitorDashboard,
1413
MonitorMetricsDefinition,
1514
MonitorService,
1615
MonitorServiceToken,
17-
RuleCriteria,
18-
TriggerConditions,
1916
)
2017

2118

linode_api4/objects/monitor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ class AlertChannel(Base):
364364
"""
365365

366366
api_endpoint = "/monitor/alert-channels/"
367-
id_attribute = "id"
368367

369368
properties = {
370369
"id": Property(identifier=True),

test/fixtures/monitor/services/dbaas/alert-definitions/12345.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/integration/models/monitor/test_monitor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import time
1+
from time import time
22

33
import pytest
44

55
from linode_api4 import ApiError, LinodeClient
66
from linode_api4.objects import (
7+
AlertChannel,
78
AlertDefinition,
89
MonitorDashboard,
910
MonitorMetricsDefinition,
@@ -200,10 +201,10 @@ def test_integration_create_get_update_delete_alert_definition(
200201
finally:
201202
if created:
202203
# Best-effort cleanup; allow transient errors.
203-
alert_update_interval = 60 # max time alert should take to update
204+
alert_update_interval = 120 # max time alert should take to update
204205
try:
205-
time.sleep(alert_update_interval)
206-
delete_alert = client.load(AlertDefinition,created.id,service_type)
206+
time.sleep(alert_update_interval)
207+
delete_alert = client.load(AlertDefinition, created.id, service_type)
207208
delete_alert.delete()
208209
except Exception:
209210

test/unit/groups/monitor_api_test.py

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from linode_api4 import PaginatedList
12
from linode_api4.objects import (
23
AggregateFunction,
34
AlertDefinition,
@@ -55,38 +56,30 @@ def test_fetch_metrics(self):
5556
assert metrics.stats.seriesFetched == "2"
5657
assert not metrics.isPartial
5758

59+
5860
class MonitorAlertDefinitionsTest(ClientBaseCase):
5961
def test_get_alert_definition(self):
6062
service_type = "dbaas"
61-
alert_id = 12345
62-
url = f"/monitor/services/{service_type}/alert-definitions/{alert_id}"
63+
url = f"/monitor/services/{service_type}/alert-definitions"
6364
with self.mock_get(url) as mock_get:
6465
alert = self.client.monitor.get_alert_definitions(
65-
service_type=service_type, alert_id=alert_id
66+
service_type=service_type
6667
)
6768

68-
# assert call
6969
assert mock_get.call_url == url
7070

71-
# assert object
72-
assert isinstance(alert, AlertDefinition)
73-
assert alert.id == 12345
71+
# assert collection and element types
72+
assert isinstance(alert, PaginatedList)
73+
assert isinstance(alert[0], AlertDefinition)
7474

7575
# fetch the raw JSON from the client and assert its fields
7676
raw = self.client.get(url)
77-
assert raw["label"] == "Test Alert for DBAAS"
78-
assert raw["service_type"] == "dbaas"
79-
assert raw["status"] == "active"
80-
assert raw["created"] == "2024-01-01T00:00:00"
81-
82-
def test_alert_definitions_requires_service_type_when_id_given(self):
83-
# alert_id without service_type should raise ValueError
84-
try:
85-
self.client.monitor.get_alert_definitions(alert_id=12345)
86-
raised = False
87-
except ValueError:
88-
raised = True
89-
assert raised
77+
# raw is a paginated response; check first item's fields
78+
first = raw["data"][0]
79+
assert first["label"] == "Test Alert for DBAAS"
80+
assert first["service_type"] == "dbaas"
81+
assert first["status"] == "active"
82+
assert first["created"] == "2024-01-01T00:00:00"
9083

9184
def test_create_alert_definition(self):
9285
service_type = "dbaas"
@@ -143,14 +136,3 @@ def test_update_alert_definition(self):
143136

144137
resp = self.client.put(url, data={})
145138
assert resp["label"] == "Updated Label"
146-
147-
def test_delete_alert_definition(self):
148-
service_type = "dbaas"
149-
alert_id = 12345
150-
url = f"/monitor/services/{service_type}/alert-definitions/{alert_id}"
151-
152-
with self.mock_delete() as mock_delete:
153-
self.client.monitor.delete_alert_definition(service_type, alert_id)
154-
155-
assert mock_delete.call_url == url
156-
assert mock_delete.called

0 commit comments

Comments
 (0)