Skip to content

Commit 2ceb3bd

Browse files
committed
ACLP Logs Stream - ensure update reverts on failed assertions
1 parent a7378fa commit 2ceb3bd

1 file changed

Lines changed: 30 additions & 27 deletions

File tree

test/integration/models/monitor/test_monitor_logs.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,18 @@ def test_update_stream_label(test_linode_client: LinodeClient, test_stream_activ
338338
updated = test_linode_client.load(LogsStream, test_stream_active.id)
339339
assert updated.label == new_label
340340

341-
history = updated.history
342-
snapshot_original = next(h for h in history if h.version == version_before)
343-
snapshot_updated = next(h for h in history if h.version == updated.version)
344-
345-
assert snapshot_original.label == original_label
346-
assert snapshot_updated.label == new_label
347-
assert snapshot_updated.id == test_stream_active.id
341+
try:
342+
history = updated.history
343+
snapshot_original = next(h for h in history if h.version == version_before)
344+
snapshot_updated = next(h for h in history if h.version == updated.version)
348345

349-
# Revert to original label
350-
updated.label = original_label
351-
updated.save()
346+
assert snapshot_original.label == original_label
347+
assert snapshot_updated.label == new_label
348+
assert snapshot_updated.id == test_stream_active.id
349+
finally:
350+
# Revert to original label
351+
updated.label = original_label
352+
updated.save()
352353

353354

354355

@@ -373,12 +374,13 @@ def test_update_stream_status(test_linode_client: LinodeClient, test_stream_acti
373374
result = stream.save()
374375
assert result is True
375376

376-
updated = test_linode_client.load(LogsStream, test_stream_active.id)
377-
assert updated.status == new_status
378-
379-
#Revert to original status
380-
stream.status=original_status
381-
stream.save()
377+
try:
378+
updated = test_linode_client.load(LogsStream, test_stream_active.id)
379+
assert updated.status == new_status
380+
finally:
381+
# Revert to original status
382+
stream.status = original_status
383+
stream.save()
382384

383385

384386
@pytest.mark.skipif(
@@ -402,16 +404,17 @@ def test_update_stream_destinations(
402404
result = stream.update_destinations([test_secondary_destination.id])
403405
assert result is True
404406

405-
updated = test_linode_client.load(LogsStream, test_stream_active.id)
406-
assert len(updated.destinations) == 1
407-
assert updated.destinations[0].id == test_secondary_destination.id
408-
409-
history = updated.history
410-
snapshot_original = next(h for h in history if h.version == version_before)
411-
snapshot_updated = next(h for h in history if h.version == updated.version)
407+
try:
408+
updated = test_linode_client.load(LogsStream, test_stream_active.id)
409+
assert len(updated.destinations) == 1
410+
assert updated.destinations[0].id == test_secondary_destination.id
412411

413-
assert snapshot_original.destinations[0].id == original_destinations[0]
414-
assert snapshot_updated.destinations[0].id == test_secondary_destination.id
412+
history = updated.history
413+
snapshot_original = next(h for h in history if h.version == version_before)
414+
snapshot_updated = next(h for h in history if h.version == updated.version)
415415

416-
# Revert to original destination
417-
updated.update_destinations(original_destinations)
416+
assert snapshot_original.destinations[0].id == original_destinations[0]
417+
assert snapshot_updated.destinations[0].id == test_secondary_destination.id
418+
finally:
419+
# Revert to original destination
420+
stream.update_destinations(original_destinations)

0 commit comments

Comments
 (0)