aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cogs/test_trigger_integration.py
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-04-29 14:22:03 +0200
committersalmonik <raisersoft@proton.me>2026-04-29 14:22:03 +0200
commitdba3388567818cb5c60be9d406d3e1cccc84b3ea (patch)
tree53a0903f7a4c381c7ad12e3e632ef8dd8ebba39f /tests/cogs/test_trigger_integration.py
parentmultitude of changes. (diff)
downloadsenator-sperma-dba3388567818cb5c60be9d406d3e1cccc84b3ea.tar.gz
senator-sperma-dba3388567818cb5c60be9d406d3e1cccc84b3ea.zip
Refactor database connections and add integration tests
- Use context managers for sqlite3 connections in cron, vclogs, and database utils - Add URL helper utility for yt-dlp with clean_url_for_ytdlp function - Add slow integration test markers and new integration test files - Fix test imports to use conftest directly instead of tests.conftest - Improve downloader error handling and use COPYPARTY_URL_UPLOAD env var - Update pytest.ini with slow test markers and warning filters - Document slow test usage in AGENTS.md
Diffstat (limited to 'tests/cogs/test_trigger_integration.py')
-rw-r--r--tests/cogs/test_trigger_integration.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/cogs/test_trigger_integration.py b/tests/cogs/test_trigger_integration.py
new file mode 100644
index 0000000..4828387
--- /dev/null
+++ b/tests/cogs/test_trigger_integration.py
@@ -0,0 +1,54 @@
1import pytest
2from unittest.mock import MagicMock, AsyncMock, patch
3from cogs.trigger import Trigger
4
5
6@pytest.fixture
7def trigger_cog(bot):
8 from cogs.utils.database import init_database
9 init_database()
10 from cogs.trigger import Trigger
11 cog = Trigger(bot)
12 return cog
13
14
15@pytest.mark.slow
16@pytest.mark.asyncio
17async def test_trigger_response_flow(trigger_cog):
18 """Test trigger creation and response in a simulated message flow."""
19 cog = trigger_cog
20
21 ctx = MagicMock()
22 ctx.author = MagicMock()
23 ctx.author.id = 123
24 ctx.guild = MagicMock()
25 ctx.guild.id = 456
26 ctx.respond = AsyncMock()
27
28 # Create a trigger using the create command
29 await cog.create.callback(cog, ctx, name="test_trigger")
30
31 # Add a keyword and response
32 await cog.add.callback(cog, ctx, name="test_trigger", trigger="hello", response="world")
33
34 # Verify trigger was created - check DB
35 from cogs.utils.database import get_connection
36 with get_connection() as conn:
37 c = conn.cursor()
38 c.execute("SELECT id FROM triggers WHERE name=?", ("test_trigger",))
39 result = c.fetchone()
40 assert result is not None
41
42 # Simulate a message that should trigger
43 message = MagicMock()
44 message.author = ctx.author
45 message.author.bot = False
46 message.guild = ctx.guild
47 message.content = "say hello to me"
48 message.channel.send = AsyncMock() # Make send awaitable
49
50 # Check if trigger matches using the static method
51 await Trigger.trigger(message)
52
53 # Verify message.channel.send was called with the response
54 message.channel.send.assert_called_once_with("world")