diff options
| author | salmonik <raisersoft@proton.me> | 2026-07-08 02:13:35 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-07-08 02:13:35 +0200 |
| commit | cd8ed8bc5793985df2c1692072a932ceee517b95 (patch) | |
| tree | 42d18a4140259b5c68b4dd05b7fcb398f78b8d7f /tests/conftest.py | |
| parent | Merge pull request 'Voice related fixes, alongside simplifying assistant' (#5... (diff) | |
| download | senator-sperma-cd8ed8bc5793985df2c1692072a932ceee517b95.tar.gz senator-sperma-cd8ed8bc5793985df2c1692072a932ceee517b95.zip | |
OPEN THE RUST GATES
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to '')
| -rw-r--r-- | tests/conftest.py | 228 |
1 files changed, 0 insertions, 228 deletions
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 @@ | |||
| 1 | import asyncio | ||
| 2 | import os | ||
| 3 | import sys | ||
| 4 | import tempfile | ||
| 5 | from unittest.mock import AsyncMock, MagicMock | ||
| 6 | import pytest | ||
| 7 | |||
| 8 | import discord | ||
| 9 | from discord.ext import commands | ||
| 10 | |||
| 11 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) | ||
| 12 | |||
| 13 | |||
| 14 | @pytest.fixture(autouse=True, scope="function") | ||
| 15 | def setup_test_env(monkeypatch): | ||
| 16 | test_db = os.path.join(tempfile.gettempdir(), "test_senator.db") | ||
| 17 | if os.path.exists(test_db): | ||
| 18 | os.remove(test_db) | ||
| 19 | monkeypatch.setenv("SENATOR_DB_PATH", test_db) | ||
| 20 | reload_database() | ||
| 21 | yield | ||
| 22 | if os.path.exists(test_db): | ||
| 23 | os.remove(test_db) | ||
| 24 | |||
| 25 | |||
| 26 | def reload_database(): | ||
| 27 | import cogs.utils.database as db_module | ||
| 28 | db_module._initialized = False | ||
| 29 | |||
| 30 | |||
| 31 | class MockUser: | ||
| 32 | def __init__(self, id=12345, name="testuser", discriminator="0001"): | ||
| 33 | self.id = id | ||
| 34 | self.name = name | ||
| 35 | self.discriminator = discriminator | ||
| 36 | self.mention = f"@{name}" | ||
| 37 | self.display_name = name | ||
| 38 | self.avatar = None | ||
| 39 | self.bot = False | ||
| 40 | self.guild = None | ||
| 41 | self._state = MagicMock() | ||
| 42 | |||
| 43 | def __str__(self): | ||
| 44 | return f"{self.name}#{self.discriminator}" | ||
| 45 | |||
| 46 | |||
| 47 | class MockChannel: | ||
| 48 | def __init__(self, id=11111, name="test-channel", type=discord.ChannelType.text): | ||
| 49 | self.id = id | ||
| 50 | self.name = name | ||
| 51 | self.type = type | ||
| 52 | self.mention = f"#{name}" | ||
| 53 | self.guild = None | ||
| 54 | self.category = None | ||
| 55 | self._state = MagicMock() | ||
| 56 | |||
| 57 | def send(self, *args, **kwargs): | ||
| 58 | return MagicMock() | ||
| 59 | |||
| 60 | |||
| 61 | class MockTextChannel(MockChannel): | ||
| 62 | def __init__(self, id=11111, name="test-channel"): | ||
| 63 | super().__init__(id, name, discord.ChannelType.text) | ||
| 64 | |||
| 65 | |||
| 66 | class MockVoiceChannel(MockChannel): | ||
| 67 | def __init__(self, id=11112, name="test-voice"): | ||
| 68 | super().__init__(id, name, discord.ChannelType.voice) | ||
| 69 | self.voice_states = {} | ||
| 70 | |||
| 71 | |||
| 72 | class MockGuild: | ||
| 73 | def __init__(self, id=99999, name="Test Server"): | ||
| 74 | self.id = id | ||
| 75 | self.name = name | ||
| 76 | self.channels = [] | ||
| 77 | self.roles = [] | ||
| 78 | self.emojis = [] | ||
| 79 | self.me = MockUser(id=111111, name="Sen Bot") | ||
| 80 | self._state = MagicMock() | ||
| 81 | self._default_role = None | ||
| 82 | |||
| 83 | def get_channel(self, channel_id): | ||
| 84 | for ch in self.channels: | ||
| 85 | if ch.id == channel_id: | ||
| 86 | return ch | ||
| 87 | return None | ||
| 88 | |||
| 89 | def get_role(self, role_id): | ||
| 90 | for role in self.roles: | ||
| 91 | if role.id == role_id: | ||
| 92 | return role | ||
| 93 | return None | ||
| 94 | |||
| 95 | def get_member(self, member_id): | ||
| 96 | return None | ||
| 97 | |||
| 98 | |||
| 99 | class MockMessage: | ||
| 100 | def __init__(self, id=22222, content="test message", author=None, channel=None, guild=None): | ||
| 101 | self.id = id | ||
| 102 | self.content = content | ||
| 103 | self.author = author or MockUser() | ||
| 104 | self.channel = channel or MockChannel() | ||
| 105 | self.guild = guild | ||
| 106 | self.attachments = [] | ||
| 107 | self.embeds = [] | ||
| 108 | self.jump_url = "https://discord.com/channels/..." | ||
| 109 | self.created_at = None | ||
| 110 | |||
| 111 | async def reply(self, *args, **kwargs): | ||
| 112 | return MagicMock() | ||
| 113 | # Stub for reply - kept async to match Discord interface signature | ||
| 114 | |||
| 115 | |||
| 116 | class MockInteraction: | ||
| 117 | def __init__(self, user=None, channel=None, guild=None): | ||
| 118 | self.user = user or MockUser() | ||
| 119 | self.channel = channel or MockChannel() | ||
| 120 | self.guild = guild or MockGuild() | ||
| 121 | self.message = None | ||
| 122 | self.response = AsyncMock() | ||
| 123 | self.followup = AsyncMock() | ||
| 124 | self.client = None | ||
| 125 | self.id = 33333 | ||
| 126 | self.token = "test_token" | ||
| 127 | self._state = MagicMock() | ||
| 128 | |||
| 129 | async def defer(self, *args, **kwargs): | ||
| 130 | pass | ||
| 131 | |||
| 132 | async def respond(self, *args, **kwargs): | ||
| 133 | pass | ||
| 134 | |||
| 135 | async def delete_original_response(self, *args, **kwargs): | ||
| 136 | pass | ||
| 137 | |||
| 138 | async def send(self, *args, **kwargs): | ||
| 139 | return MagicMock() | ||
| 140 | |||
| 141 | |||
| 142 | # Stub for Discord interaction - test implementation only | ||
| 143 | class MockApplicationContext: | ||
| 144 | def __init__(self, bot=None, interaction=None, user=None, channel=None, guild=None): | ||
| 145 | self.bot = bot | ||
| 146 | self.interaction = interaction or MockInteraction(user=user, channel=channel, guild=guild) | ||
| 147 | self.user = user or MockUser() | ||
| 148 | self.channel = channel or MockChannel() | ||
| 149 | self.guild = guild or MockGuild() | ||
| 150 | self.message = None | ||
| 151 | self.response = AsyncMock() | ||
| 152 | self.followup = AsyncMock() | ||
| 153 | self.client = self.bot | ||
| 154 | self.id = 33333 | ||
| 155 | self.token = "test_token" | ||
| 156 | self._state = self.interaction._state | ||
| 157 | self.author = self.user | ||
| 158 | |||
| 159 | async def defer(self, *args, **kwargs): | ||
| 160 | pass | ||
| 161 | # Stub for defer - tests don't verify interaction state | ||
| 162 | |||
| 163 | async def respond(self, *args, **kwargs): | ||
| 164 | pass | ||
| 165 | # Stub for respond - tests mock the response | ||
| 166 | |||
| 167 | async def delete_original_response(self, *args, **kwargs): | ||
| 168 | pass | ||
| 169 | # Stub for delete_original_response - not used in tests | ||
| 170 | |||
| 171 | async def send(self, *args, **kwargs): | ||
| 172 | return MagicMock() | ||
| 173 | # Stub for send - not used in tests | ||
| 174 | |||
| 175 | async def reply(self, *args, **kwargs): | ||
| 176 | return MagicMock() | ||
| 177 | # Stub for reply - not used in tests | ||
| 178 | |||
| 179 | async def send_followup(self, *args, **kwargs): | ||
| 180 | return MagicMock() | ||
| 181 | # Stub for send_followup - not used in tests | ||
| 182 | |||
| 183 | |||
| 184 | @pytest.fixture | ||
| 185 | def mock_guild(): | ||
| 186 | return MockGuild() | ||
| 187 | |||
| 188 | |||
| 189 | @pytest.fixture | ||
| 190 | def mock_channel(mock_guild): | ||
| 191 | channel = MockTextChannel() | ||
| 192 | channel.guild = mock_guild | ||
| 193 | return channel | ||
| 194 | |||
| 195 | |||
| 196 | @pytest.fixture | ||
| 197 | def mock_voice_channel(mock_guild): | ||
| 198 | channel = MockVoiceChannel() | ||
| 199 | channel.guild = mock_guild | ||
| 200 | return channel | ||
| 201 | |||
| 202 | |||
| 203 | @pytest.fixture | ||
| 204 | def mock_user(): | ||
| 205 | return MockUser() | ||
| 206 | |||
| 207 | |||
| 208 | @pytest.fixture | ||
| 209 | def mock_member(mock_guild): | ||
| 210 | member = MockUser() | ||
| 211 | member.guild = mock_guild | ||
| 212 | return member | ||
| 213 | |||
| 214 | |||
| 215 | @pytest.fixture | ||
| 216 | def mock_message(mock_channel, mock_user, mock_guild): | ||
| 217 | return MockMessage(channel=mock_channel, author=mock_user, guild=mock_guild) | ||
| 218 | |||
| 219 | |||
| 220 | @pytest.fixture | ||
| 221 | def mock_interaction(mock_channel, mock_user, mock_guild): | ||
| 222 | return MockInteraction(user=mock_user, channel=mock_channel, guild=mock_guild) | ||
| 223 | |||
| 224 | |||
| 225 | @pytest.fixture | ||
| 226 | def bot(): | ||
| 227 | intents = discord.Intents.all() | ||
| 228 | return commands.Bot(intents=intents, command_prefix="!", loop=asyncio.new_event_loop()) | ||
