aboutsummaryrefslogtreecommitdiffstats
path: root/tests/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py206
1 files changed, 206 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..e9f0f6f
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,206 @@
1import asyncio
2from unittest.mock import AsyncMock, MagicMock
3import pytest
4
5import discord
6from discord.ext import commands
7
8
9class MockUser:
10 def __init__(self, id=12345, name="testuser", discriminator="0001"):
11 self.id = id
12 self.name = name
13 self.discriminator = discriminator
14 self.mention = f"@{name}"
15 self.display_name = name
16 self.avatar = None
17 self.bot = False
18 self.guild = None
19 self._state = MagicMock()
20
21 def __str__(self):
22 return f"{self.name}#{self.discriminator}"
23
24
25class MockChannel:
26 def __init__(self, id=11111, name="test-channel", type=discord.ChannelType.text):
27 self.id = id
28 self.name = name
29 self.type = type
30 self.mention = f"#{name}"
31 self.guild = None
32 self.category = None
33 self._state = MagicMock()
34
35 def send(self, *args, **kwargs):
36 return MagicMock()
37
38
39class MockTextChannel(MockChannel):
40 def __init__(self, id=11111, name="test-channel"):
41 super().__init__(id, name, discord.ChannelType.text)
42
43
44class MockVoiceChannel(MockChannel):
45 def __init__(self, id=11112, name="test-voice"):
46 super().__init__(id, name, discord.ChannelType.voice)
47 self.voice_states = {}
48
49
50class MockGuild:
51 def __init__(self, id=99999, name="Test Server"):
52 self.id = id
53 self.name = name
54 self.channels = []
55 self.roles = []
56 self.emojis = []
57 self.me = MockUser(id=111111, name="Sen Bot")
58 self._state = MagicMock()
59 self._default_role = None
60
61 def get_channel(self, channel_id):
62 for ch in self.channels:
63 if ch.id == channel_id:
64 return ch
65 return None
66
67 def get_role(self, role_id):
68 for role in self.roles:
69 if role.id == role_id:
70 return role
71 return None
72
73 def get_member(self, member_id):
74 return None
75
76
77class MockMessage:
78 def __init__(self, id=22222, content="test message", author=None, channel=None, guild=None):
79 self.id = id
80 self.content = content
81 self.author = author or MockUser()
82 self.channel = channel or MockChannel()
83 self.guild = guild
84 self.attachments = []
85 self.embeds = []
86 self.jump_url = "https://discord.com/channels/..."
87 self.created_at = None
88
89 async def reply(self, *args, **kwargs):
90 return MagicMock()
91 # Stub for reply - kept async to match Discord interface signature
92
93
94class MockInteraction:
95 def __init__(self, user=None, channel=None, guild=None):
96 self.user = user or MockUser()
97 self.channel = channel or MockChannel()
98 self.guild = guild or MockGuild()
99 self.message = None
100 self.response = AsyncMock()
101 self.followup = AsyncMock()
102 self.client = None
103 self.id = 33333
104 self.token = "test_token"
105 self._state = MagicMock()
106
107 async def defer(self, *args, **kwargs):
108 pass
109
110 async def respond(self, *args, **kwargs):
111 pass
112
113 async def delete_original_response(self, *args, **kwargs):
114 pass
115
116 async def send(self, *args, **kwargs):
117 return MagicMock()
118
119
120# Stub for Discord interaction - test implementation only
121class MockApplicationContext:
122 def __init__(self, bot=None, interaction=None, user=None, channel=None, guild=None):
123 self.bot = bot
124 self.interaction = interaction or MockInteraction(user=user, channel=channel, guild=guild)
125 self.user = user or MockUser()
126 self.channel = channel or MockChannel()
127 self.guild = guild or MockGuild()
128 self.message = None
129 self.response = AsyncMock()
130 self.followup = AsyncMock()
131 self.client = self.bot
132 self.id = 33333
133 self.token = "test_token"
134 self._state = self.interaction._state
135 self.author = self.user
136
137 async def defer(self, *args, **kwargs):
138 pass
139 # Stub for defer - tests don't verify interaction state
140
141 async def respond(self, *args, **kwargs):
142 pass
143 # Stub for respond - tests mock the response
144
145 async def delete_original_response(self, *args, **kwargs):
146 pass
147 # Stub for delete_original_response - not used in tests
148
149 async def send(self, *args, **kwargs):
150 return MagicMock()
151 # Stub for send - not used in tests
152
153 async def reply(self, *args, **kwargs):
154 return MagicMock()
155 # Stub for reply - not used in tests
156
157 async def send_followup(self, *args, **kwargs):
158 return MagicMock()
159 # Stub for send_followup - not used in tests
160
161
162@pytest.fixture
163def mock_guild():
164 return MockGuild()
165
166
167@pytest.fixture
168def mock_channel(mock_guild):
169 channel = MockTextChannel()
170 channel.guild = mock_guild
171 return channel
172
173
174@pytest.fixture
175def mock_voice_channel(mock_guild):
176 channel = MockVoiceChannel()
177 channel.guild = mock_guild
178 return channel
179
180
181@pytest.fixture
182def mock_user():
183 return MockUser()
184
185
186@pytest.fixture
187def mock_member(mock_guild):
188 member = MockUser()
189 member.guild = mock_guild
190 return member
191
192
193@pytest.fixture
194def mock_message(mock_channel, mock_user, mock_guild):
195 return MockMessage(channel=mock_channel, author=mock_user, guild=mock_guild)
196
197
198@pytest.fixture
199def mock_interaction(mock_channel, mock_user, mock_guild):
200 return MockInteraction(user=mock_user, channel=mock_channel, guild=mock_guild)
201
202
203@pytest.fixture
204def bot():
205 intents = discord.Intents.all()
206 return commands.Bot(intents=intents, command_prefix="!", loop=asyncio.new_event_loop())