disagreement/tests/test_textchannel_purge.py
Slipstream 45a5ef1fb5
Improves asyncio loop handling and test initialization
Replaces deprecated get_event_loop() with proper running loop detection and fallback to new loop creation for better asyncio compatibility.

Fixes test suite by replacing manual Client instantiation with proper constructor calls, ensuring all internal caches and attributes are correctly initialized.

Updates cache access patterns to use new cache API methods consistently across the codebase.
2025-06-11 02:25:24 -06:00

47 lines
1.3 KiB
Python

import pytest
from types import SimpleNamespace
from unittest.mock import AsyncMock
from disagreement.client import Client
from disagreement.models import TextChannel
@pytest.mark.asyncio
async def test_textchannel_purge_calls_bulk_delete():
http = SimpleNamespace(
request=AsyncMock(return_value=[{"id": "1"}, {"id": "2"}]),
bulk_delete_messages=AsyncMock(),
)
client = Client(token="test")
client._http = http
channel = TextChannel({"id": "c", "type": 0}, client)
deleted = await channel.purge(2)
http.request.assert_called_once_with(
"GET", "/channels/c/messages", params={"limit": 2}
)
http.bulk_delete_messages.assert_awaited_once_with("c", ["1", "2"])
assert deleted == ["1", "2"]
@pytest.mark.asyncio
async def test_textchannel_purge_before_param():
http = SimpleNamespace(
request=AsyncMock(return_value=[]),
bulk_delete_messages=AsyncMock(),
)
client = Client(token="test")
client._http = http
channel = TextChannel({"id": "c", "type": 0}, client)
deleted = await channel.purge(1, before="b")
http.request.assert_called_once_with(
"GET", "/channels/c/messages", params={"limit": 1, "before": "b"}
)
http.bulk_delete_messages.assert_not_awaited()
assert deleted == []