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/cogs/test_qr.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 'tests/cogs/test_qr.py')
| -rw-r--r-- | tests/cogs/test_qr.py | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/tests/cogs/test_qr.py b/tests/cogs/test_qr.py deleted file mode 100644 index b5cb31f..0000000 --- a/tests/cogs/test_qr.py +++ /dev/null | |||
| @@ -1,75 +0,0 @@ | |||
| 1 | import pytest | ||
| 2 | from unittest.mock import AsyncMock, patch, MagicMock, mock_open | ||
| 3 | import os | ||
| 4 | from cogs.qr import QR | ||
| 5 | from conftest import MockApplicationContext | ||
| 6 | |||
| 7 | |||
| 8 | @pytest.fixture | ||
| 9 | def qr_cog(bot): | ||
| 10 | cog = QR(bot) | ||
| 11 | return cog | ||
| 12 | |||
| 13 | |||
| 14 | @pytest.fixture | ||
| 15 | def mock_temp_file(): | ||
| 16 | with patch('tempfile.NamedTemporaryFile') as mock: | ||
| 17 | mock_file = MagicMock() | ||
| 18 | mock_file.name = "/tmp/test_qr.png" | ||
| 19 | mock.return_value = mock_file | ||
| 20 | yield mock_file | ||
| 21 | |||
| 22 | |||
| 23 | @pytest.mark.asyncio | ||
| 24 | async def test_qr_generate_success(qr_cog, mock_channel, mock_guild, bot, mock_temp_file): | ||
| 25 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 26 | |||
| 27 | with patch('cogs.qr.QR._generate_qr') as mock_generate: | ||
| 28 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | ||
| 29 | with patch('os.path.exists', return_value=True): | ||
| 30 | with patch('os.unlink'): | ||
| 31 | await qr_cog.qr.callback(qr_cog, ctx, text="https://example.com") | ||
| 32 | mock_generate.assert_called_once() | ||
| 33 | mock_respond.assert_called_once() | ||
| 34 | |||
| 35 | |||
| 36 | @pytest.mark.asyncio | ||
| 37 | async def test_qr_generate_empty_text(qr_cog, mock_channel, mock_guild, bot): | ||
| 38 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 39 | |||
| 40 | with patch('cogs.qr.QR._generate_qr'): | ||
| 41 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | ||
| 42 | with patch('os.path.exists', return_value=False): | ||
| 43 | await qr_cog.qr.callback(qr_cog, ctx, text="") | ||
| 44 | mock_respond.assert_called_once() | ||
| 45 | |||
| 46 | |||
| 47 | @pytest.mark.asyncio | ||
| 48 | async def test_qr_decode_not_available(qr_cog, mock_channel, mock_guild, bot): | ||
| 49 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 50 | |||
| 51 | mock_attachment = MagicMock() | ||
| 52 | mock_attachment.url = "https://example.com/qr.png" | ||
| 53 | |||
| 54 | with patch('cogs.qr._ensure_qr', return_value=False): | ||
| 55 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | ||
| 56 | await qr_cog.decode.callback(qr_cog, ctx, image=mock_attachment) | ||
| 57 | mock_respond.assert_called_once() | ||
| 58 | args = mock_respond.call_args | ||
| 59 | assert "nie jest dostępne" in str(args) or "not available" in str(args).lower() | ||
| 60 | |||
| 61 | |||
| 62 | @pytest.mark.asyncio | ||
| 63 | async def test_qr_decode_download_failure(qr_cog, mock_channel, mock_guild, bot): | ||
| 64 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 65 | |||
| 66 | mock_attachment = MagicMock() | ||
| 67 | mock_attachment.url = "https://example.com/qr.png" | ||
| 68 | |||
| 69 | with patch('cogs.qr._ensure_qr', return_value=True): | ||
| 70 | with patch.object(qr_cog, '_download_image', return_value=None): | ||
| 71 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | ||
| 72 | await qr_cog.decode.callback(qr_cog, ctx, image=mock_attachment) | ||
| 73 | mock_respond.assert_called_once() | ||
| 74 | args = mock_respond.call_args | ||
| 75 | assert "Nie udało się" in str(args) or "failed" in str(args).lower() | ||
