From cd8ed8bc5793985df2c1692072a932ceee517b95 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 8 Jul 2026 02:13:35 +0200 Subject: OPEN THE RUST GATES Signed-off-by: salmonik --- tests/conftest.py | 228 ------------------------------------------------------ 1 file changed, 228 deletions(-) delete mode 100644 tests/conftest.py (limited to 'tests/conftest.py') diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 6b7c3bc..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,228 +0,0 @@ -import asyncio -import os -import sys -import tempfile -from unittest.mock import AsyncMock, MagicMock -import pytest - -import discord -from discord.ext import commands - -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) - - -@pytest.fixture(autouse=True, scope="function") -def setup_test_env(monkeypatch): - test_db = os.path.join(tempfile.gettempdir(), "test_senator.db") - if os.path.exists(test_db): - os.remove(test_db) - monkeypatch.setenv("SENATOR_DB_PATH", test_db) - reload_database() - yield - if os.path.exists(test_db): - os.remove(test_db) - - -def reload_database(): - import cogs.utils.database as db_module - db_module._initialized = False - - -class MockUser: - def __init__(self, id=12345, name="testuser", discriminator="0001"): - self.id = id - self.name = name - self.discriminator = discriminator - self.mention = f"@{name}" - self.display_name = name - self.avatar = None - self.bot = False - self.guild = None - self._state = MagicMock() - - def __str__(self): - return f"{self.name}#{self.discriminator}" - - -class MockChannel: - def __init__(self, id=11111, name="test-channel", type=discord.ChannelType.text): - self.id = id - self.name = name - self.type = type - self.mention = f"#{name}" - self.guild = None - self.category = None - self._state = MagicMock() - - def send(self, *args, **kwargs): - return MagicMock() - - -class MockTextChannel(MockChannel): - def __init__(self, id=11111, name="test-channel"): - super().__init__(id, name, discord.ChannelType.text) - - -class MockVoiceChannel(MockChannel): - def __init__(self, id=11112, name="test-voice"): - super().__init__(id, name, discord.ChannelType.voice) - self.voice_states = {} - - -class MockGuild: - def __init__(self, id=99999, name="Test Server"): - self.id = id - self.name = name - self.channels = [] - self.roles = [] - self.emojis = [] - self.me = MockUser(id=111111, name="Sen Bot") - self._state = MagicMock() - self._default_role = None - - def get_channel(self, channel_id): - for ch in self.channels: - if ch.id == channel_id: - return ch - return None - - def get_role(self, role_id): - for role in self.roles: - if role.id == role_id: - return role - return None - - def get_member(self, member_id): - return None - - -class MockMessage: - def __init__(self, id=22222, content="test message", author=None, channel=None, guild=None): - self.id = id - self.content = content - self.author = author or MockUser() - self.channel = channel or MockChannel() - self.guild = guild - self.attachments = [] - self.embeds = [] - self.jump_url = "https://discord.com/channels/..." - self.created_at = None - - async def reply(self, *args, **kwargs): - return MagicMock() - # Stub for reply - kept async to match Discord interface signature - - -class MockInteraction: - def __init__(self, user=None, channel=None, guild=None): - self.user = user or MockUser() - self.channel = channel or MockChannel() - self.guild = guild or MockGuild() - self.message = None - self.response = AsyncMock() - self.followup = AsyncMock() - self.client = None - self.id = 33333 - self.token = "test_token" - self._state = MagicMock() - - async def defer(self, *args, **kwargs): - pass - - async def respond(self, *args, **kwargs): - pass - - async def delete_original_response(self, *args, **kwargs): - pass - - async def send(self, *args, **kwargs): - return MagicMock() - - -# Stub for Discord interaction - test implementation only -class MockApplicationContext: - def __init__(self, bot=None, interaction=None, user=None, channel=None, guild=None): - self.bot = bot - self.interaction = interaction or MockInteraction(user=user, channel=channel, guild=guild) - self.user = user or MockUser() - self.channel = channel or MockChannel() - self.guild = guild or MockGuild() - self.message = None - self.response = AsyncMock() - self.followup = AsyncMock() - self.client = self.bot - self.id = 33333 - self.token = "test_token" - self._state = self.interaction._state - self.author = self.user - - async def defer(self, *args, **kwargs): - pass - # Stub for defer - tests don't verify interaction state - - async def respond(self, *args, **kwargs): - pass - # Stub for respond - tests mock the response - - async def delete_original_response(self, *args, **kwargs): - pass - # Stub for delete_original_response - not used in tests - - async def send(self, *args, **kwargs): - return MagicMock() - # Stub for send - not used in tests - - async def reply(self, *args, **kwargs): - return MagicMock() - # Stub for reply - not used in tests - - async def send_followup(self, *args, **kwargs): - return MagicMock() - # Stub for send_followup - not used in tests - - -@pytest.fixture -def mock_guild(): - return MockGuild() - - -@pytest.fixture -def mock_channel(mock_guild): - channel = MockTextChannel() - channel.guild = mock_guild - return channel - - -@pytest.fixture -def mock_voice_channel(mock_guild): - channel = MockVoiceChannel() - channel.guild = mock_guild - return channel - - -@pytest.fixture -def mock_user(): - return MockUser() - - -@pytest.fixture -def mock_member(mock_guild): - member = MockUser() - member.guild = mock_guild - return member - - -@pytest.fixture -def mock_message(mock_channel, mock_user, mock_guild): - return MockMessage(channel=mock_channel, author=mock_user, guild=mock_guild) - - -@pytest.fixture -def mock_interaction(mock_channel, mock_user, mock_guild): - return MockInteraction(user=mock_user, channel=mock_channel, guild=mock_guild) - - -@pytest.fixture -def bot(): - intents = discord.Intents.all() - return commands.Bot(intents=intents, command_prefix="!", loop=asyncio.new_event_loop()) -- cgit v1.2.3