|
1 | 1 | from unittest import mock
|
2 | 2 | from unittest.mock import AsyncMock, patch
|
3 | 3 | import contextlib
|
| 4 | +import discord |
4 | 5 |
|
5 | 6 | from django.db import connections
|
6 | 7 |
|
7 | 8 | import pytest
|
8 | 9 | from asgiref.sync import sync_to_async
|
9 |
| -from core.bot.main import ping, poll_database, qlen, source, version, wiki |
| 10 | +from core.bot.main import ping, poll_database, qlen, source, version, wiki, close |
10 | 11 | from core.models import DiscordMessage
|
11 | 12 | from django.utils import timezone
|
12 | 13 |
|
@@ -100,6 +101,40 @@ async def test_wiki_command():
|
100 | 101 | suppress_embeds=True,
|
101 | 102 | )
|
102 | 103 |
|
| 104 | +@pytest.mark.asyncio |
| 105 | +async def test_close_command_working(): |
| 106 | + # Mock context |
| 107 | + ctx = AsyncMock() |
| 108 | + ctx.channel = AsyncMock() |
| 109 | + ctx.message.author = AsyncMock() |
| 110 | + ctx.channel.type = discord.ChannelType.public_thread |
| 111 | + |
| 112 | + # Call the command |
| 113 | + await close(ctx) |
| 114 | + |
| 115 | + # Assert that the command sent the expected message |
| 116 | + ctx.channel.send.assert_called_once_with( |
| 117 | + f"# This was marked as done by {ctx.message.author.mention}", |
| 118 | + suppress_embeds=True, |
| 119 | + ) |
| 120 | + |
| 121 | +@pytest.mark.asyncio |
| 122 | +async def test_close_command_notworking(): |
| 123 | + # Mock context |
| 124 | + ctx = AsyncMock() |
| 125 | + ctx.channel = AsyncMock() |
| 126 | + ctx.message.author = AsyncMock() |
| 127 | + |
| 128 | + # Call the command |
| 129 | + await close(ctx) |
| 130 | + |
| 131 | + # Assert that the command sent the expected message |
| 132 | + ctx.channel.send.assert_called_once_with( |
| 133 | + "The !close command is intended to be used inside a thread/post", |
| 134 | + suppress_embeds=True, |
| 135 | + delete_after=5 |
| 136 | + ) |
| 137 | + |
103 | 138 |
|
104 | 139 | @pytest.mark.asyncio
|
105 | 140 | async def test_version_command():
|
|
0 commit comments