@@ -80,6 +80,18 @@ def _delete_destination_with_bucket(client: LinodeClient, dest: LogsDestination,
8080 send_request_when_resource_available (timeout = 100 , func = bucket .delete )
8181
8282
83+ def _skip_if_streams_exist (client : LinodeClient ):
84+ """Skip the current test if any streams already exist on the account.
85+ Only one stream can be present per account at a time."""
86+ existing_streams = client .monitor .streams ()
87+ if len (existing_streams ) > 0 :
88+ stream_labels = [s .label for s in existing_streams ]
89+ pytest .skip (
90+ f"Skipping: existing stream(s) found on this account "
91+ f"(labels: { stream_labels } ). Only one stream can be present per account."
92+ )
93+
94+
8395def _empty_bucket (client : LinodeClient , bucket : ObjectStorageBucket ):
8496 """
8597 Helper function clearing objects in the test bucket so it can be deleted.
@@ -232,13 +244,7 @@ def test_fails_to_create_stream_invalid_destination(test_linode_client: LinodeCl
232244 """
233245 from linode_api4 .errors import ApiError
234246
235- existing_streams = test_linode_client .monitor .streams ()
236- if len (existing_streams ) > 0 :
237- stream_ids = [s .id for s in existing_streams ]
238- pytest .skip (
239- f"Skipping: existing stream(s) found on this account "
240- f"(ID: { stream_ids } ). Only one stream can be present per account. "
241- )
247+ _skip_if_streams_exist (test_linode_client )
242248
243249 with pytest .raises (ApiError ) as excinfo :
244250 test_linode_client .monitor .stream_create (
@@ -262,6 +268,8 @@ def create_secondary_destination(
262268
263269@pytest .fixture (scope = "session" )
264270def create_stream (test_linode_client : LinodeClient , test_destination : LogsDestination ):
271+ _skip_if_streams_exist (test_linode_client )
272+
265273 stream = test_linode_client .monitor .stream_create (
266274 label = get_test_label (),
267275 destinations = [test_destination .id ],
@@ -319,60 +327,45 @@ def test_get_stream_by_id(test_linode_client: LinodeClient, provisioned_stream:
319327
320328
321329@_SKIP_STREAM_TESTS
322- def test_update_stream_label (test_linode_client : LinodeClient , provisioned_stream : LogsStream ):
330+ def test_update_stream_label_and_status (test_linode_client : LinodeClient , provisioned_stream : LogsStream ):
323331 """
324- Test that a LogsStream label can be updated via save() and that the version
325- history reflects the change .
332+ Test that a LogsStream label and status can both be updated via save(), and that
333+ the version history reflects both the label and status changes across versions .
326334 """
327- new_label = provisioned_stream .label + "-upd"
328-
329335 stream = test_linode_client .load (LogsStream , provisioned_stream .id )
330336 original_label = stream .label
337+ original_status = stream .status
331338 version_before = stream .version
332339
340+ new_label = original_label + "-upd"
341+ new_status = (
342+ LogsStreamStatus .inactive
343+ if original_status == LogsStreamStatus .active
344+ else LogsStreamStatus .active
345+ )
346+
333347 stream .label = new_label
348+ stream .status = new_status
334349 result = stream .save ()
335350 assert result is True
336351
337352 try :
338353 updated = test_linode_client .load (LogsStream , provisioned_stream .id )
339354 assert updated .label == new_label
355+ assert updated .status == new_status
356+
340357 history = updated .history
341358 snapshot_original = next (h for h in history if h .version == version_before )
342359 snapshot_updated = next (h for h in history if h .version == updated .version )
343360
344361 assert snapshot_original .label == original_label
362+ assert snapshot_original .status == original_status
345363 assert snapshot_updated .label == new_label
364+ assert snapshot_updated .status == new_status
346365 assert snapshot_updated .id == provisioned_stream .id
347366 finally :
348- # Revert to original label
367+ # Revert to original label and status
349368 stream .label = original_label
350- stream .save ()
351-
352-
353- @_SKIP_STREAM_TESTS
354- def test_update_stream_status (test_linode_client : LinodeClient , provisioned_stream : LogsStream ):
355- """
356- Test that a LogsStream status can be toggled between active and inactive via save().
357- """
358- stream = test_linode_client .load (LogsStream , provisioned_stream .id )
359- original_status = stream .status
360-
361- new_status = (
362- LogsStreamStatus .inactive
363- if original_status == LogsStreamStatus .active
364- else LogsStreamStatus .active
365- )
366-
367- stream .status = new_status
368- result = stream .save ()
369- assert result is True
370-
371- try :
372- updated = test_linode_client .load (LogsStream , provisioned_stream .id )
373- assert updated .status == new_status
374- finally :
375- # Revert to original status
376369 stream .status = original_status
377370 stream .save ()
378371
0 commit comments