1- import datetime
21import time
32import uuid
43
1817 QueryFutureChannelBansPayload ,
1918 SortParamRequest ,
2019)
21- from tests .base import retry_on_transient_error
20+ from tests .base import cleanup_channel_types , retry_on_transient_error
2221
2322
2423def test_get_app_settings (client : Stream ):
@@ -391,42 +390,10 @@ def test_query_future_channel_bans(client: Stream, random_users):
391390 pass
392391
393392
394- BUILTIN_CHANNEL_TYPES = frozenset (
395- {
396- "messaging" ,
397- "livestream" ,
398- "team" ,
399- "gaming" ,
400- "commerce" ,
401- }
402- )
403-
404- _STALE_THRESHOLD = datetime .timedelta (minutes = 2 )
405-
406-
407- def _cleanup_test_channel_types (client : Stream ):
408- """Delete stale non-builtin channel types to free slots for test runs.
409-
410- Only deletes types older than 2 minutes to avoid interfering with
411- parallel runners that just created theirs.
412- """
413- now = datetime .datetime .now (datetime .timezone .utc )
414- resp = client .chat .list_channel_types ()
415- for name , config in resp .data .channel_types .items ():
416- if name in BUILTIN_CHANNEL_TYPES :
417- continue
418- if config and (now - config .created_at ) > _STALE_THRESHOLD :
419- try :
420- client .chat .delete_channel_type (name = name )
421- except Exception :
422- pass
423- time .sleep (2 )
424-
425-
393+ @cleanup_channel_types
426394@retry_on_transient_error ()
427395def test_create_channel_type (client : Stream ):
428396 """Create a channel type with custom settings."""
429- _cleanup_test_channel_types (client )
430397 type_name = f"testtype{ uuid .uuid4 ().hex [:8 ]} "
431398
432399 try :
@@ -449,10 +416,10 @@ def test_create_channel_type(client: Stream):
449416 pass
450417
451418
419+ @cleanup_channel_types
452420@retry_on_transient_error ()
453421def test_update_channel_type_mark_messages_pending (client : Stream ):
454422 """Update a channel type with mark_messages_pending=True."""
455- _cleanup_test_channel_types (client )
456423 type_name = f"testtype{ uuid .uuid4 ().hex [:8 ]} "
457424
458425 try :
@@ -483,10 +450,10 @@ def test_update_channel_type_mark_messages_pending(client: Stream):
483450 pass
484451
485452
453+ @cleanup_channel_types
486454@retry_on_transient_error ()
487455def test_update_channel_type_push_notifications (client : Stream ):
488456 """Update a channel type with push_notifications=False."""
489- _cleanup_test_channel_types (client )
490457 type_name = f"testtype{ uuid .uuid4 ().hex [:8 ]} "
491458
492459 try :
@@ -517,10 +484,10 @@ def test_update_channel_type_push_notifications(client: Stream):
517484 pass
518485
519486
487+ @cleanup_channel_types
520488@retry_on_transient_error ()
521489def test_delete_channel_type (client : Stream ):
522490 """Create and delete a channel type with retry."""
523- _cleanup_test_channel_types (client )
524491 type_name = f"testdeltype{ uuid .uuid4 ().hex [:8 ]} "
525492
526493 client .chat .create_channel_type (
0 commit comments