Skip to content

Commit 54d4efc

Browse files
committed
fixing test case to not hardcode usernames
1 parent d33a714 commit 54d4efc

3 files changed

Lines changed: 39 additions & 17 deletions

File tree

‎test/integration/models/monitor/test_monitor.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,24 @@ def test_integration_create_get_update_delete_alert_channel(test_linode_client):
332332
created_channel = None
333333

334334
try:
335+
# Get valid users to use for the email alert channel
336+
users = list(client.account.users())
337+
if len(users) == 0:
338+
pytest.skip("No account users available for creating alert channels")
339+
340+
# Use the first user, or first two if available
341+
usernames = [users[0].username]
342+
if len(users) > 1:
343+
usernames.append(users[1].username)
344+
335345
# Create an alert channel with email details
336346
created_channel = client.monitor.channel_create(
337347
label=label,
338348
channel_type="email",
339349
details=ChannelDetails(
340350
email=EmailDetails(
341351
recipient_type="user",
342-
usernames=["mawasthy_tenant02_admin"],
352+
usernames=usernames,
343353
)
344354
),
345355
)

‎test/unit/groups/monitor_api_test.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_create_update_delete_alert_channel(self):
200200
"channel_type": "email",
201201
"details": {
202202
"email": {
203-
"usernames": ["test_user"],
203+
"usernames": ["test_user1", "test_user2"],
204204
"recipient_type": "user",
205205
}
206206
},
@@ -211,8 +211,8 @@ def test_create_update_delete_alert_channel(self):
211211
},
212212
"created": "2024-01-01T00:00:00",
213213
"updated": "2024-01-01T00:00:00",
214-
"created_by": "test_user",
215-
"updated_by": "test_user",
214+
"created_by": "test_user1",
215+
"updated_by": "test_user1",
216216
}
217217

218218
with self.mock_post(create_response) as mock_post:
@@ -222,7 +222,7 @@ def test_create_update_delete_alert_channel(self):
222222
details=ChannelDetails(
223223
email=EmailDetails(
224224
recipient_type="user",
225-
usernames=["test_user"],
225+
usernames=["test_user1", "test_user2"],
226226
)
227227
),
228228
)

‎test/unit/objects/monitor_test.py‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from test.unit.base import ClientBaseCase
33

44
from linode_api4.objects import AlertChannel, MonitorDashboard, MonitorService
5+
from linode_api4.objects.monitor import ChannelDetails, EmailDetails
56

67

78
class MonitorTest(ClientBaseCase):
@@ -175,39 +176,50 @@ def test_create_update_delete_channel(self):
175176
Test CRUD operations for AlertChannel: create, update, and delete.
176177
Verifies the full lifecycle of an alert channel object.
177178
"""
179+
create_url = "/monitor/alert-channels"
178180
channel_id = 999
179-
url = f"/monitor/alert-channels/{channel_id}"
181+
channel_url = f"{create_url}/{channel_id}"
180182

181-
# Create the channel
183+
# CREATE: Create the channel via channel_create()
182184
create_response = {
183185
"id": channel_id,
184186
"label": "CRUD Test Channel",
185187
"type": "user",
186188
"channel_type": "email",
187189
"details": {
188190
"email": {
189-
"usernames": ["crud_user"],
191+
"usernames": ["crud_user1", "crud_user2"],
190192
"recipient_type": "user",
191193
}
192194
},
193195
"alerts": {
194-
"url": f"{url}/alerts",
196+
"url": f"{channel_url}/alerts",
195197
"type": "alerts-definitions",
196198
"alert_count": 0,
197199
},
198200
"created": "2024-01-01T00:00:00",
199201
"updated": "2024-01-01T00:00:00",
200-
"created_by": "crud_user",
201-
"updated_by": "crud_user",
202+
"created_by": "crud_user1",
203+
"updated_by": "crud_user1",
202204
}
203205

204-
with self.mock_get(create_response) as m_get:
205-
channel = self.client.load(AlertChannel, channel_id)
206+
with self.mock_post(create_response) as m_post:
207+
channel = self.client.monitor.channel_create(
208+
label="CRUD Test Channel",
209+
channel_type="email",
210+
details=ChannelDetails(
211+
email=EmailDetails(
212+
recipient_type="user",
213+
usernames=["crud_user1", "crud_user2"],
214+
)
215+
),
216+
)
217+
self.assertEqual(m_post.call_url, create_url)
206218
self.assertIsInstance(channel, AlertChannel)
207219
self.assertEqual(channel.id, channel_id)
208220
self.assertEqual(channel.label, "CRUD Test Channel")
209221

210-
# Update the channel
222+
# UPDATE: Update the channel label
211223
updated_response = create_response.copy()
212224
updated_response["label"] = "CRUD Test Channel Updated"
213225
updated_response["updated"] = "2024-01-02T00:00:00"
@@ -216,13 +228,13 @@ def test_create_update_delete_channel(self):
216228
channel.label = "CRUD Test Channel Updated"
217229
result = channel.save()
218230

219-
self.assertEqual(m_put.call_url, url)
231+
self.assertEqual(m_put.call_url, channel_url)
220232
self.assertTrue(result)
221233
self.assertEqual(channel.label, "CRUD Test Channel Updated")
222234

223-
# Delete the channel
235+
# DELETE: Delete the channel
224236
with self.mock_delete() as m_delete:
225237
result = channel.delete()
226238

227-
self.assertEqual(m_delete.call_url, url)
239+
self.assertEqual(m_delete.call_url, channel_url)
228240
self.assertTrue(result)

0 commit comments

Comments
 (0)