diff options
Diffstat (limited to 'tests/cogs/test_vclogs.py')
| -rw-r--r-- | tests/cogs/test_vclogs.py | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/cogs/test_vclogs.py b/tests/cogs/test_vclogs.py new file mode 100644 index 0000000..14bc6d5 --- /dev/null +++ b/tests/cogs/test_vclogs.py | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | import pytest | ||
| 2 | from unittest.mock import AsyncMock, patch, MagicMock | ||
| 3 | import json | ||
| 4 | from tests.conftest import MockApplicationContext | ||
| 5 | |||
| 6 | |||
| 7 | def test_format_duration(): | ||
| 8 | from cogs.vclogs import format_duration | ||
| 9 | |||
| 10 | assert format_duration(30) == "30s" | ||
| 11 | assert format_duration(90) == "1m 30s" | ||
| 12 | assert format_duration(3661) == "1h 1m 1s" | ||
| 13 | |||
| 14 | |||
| 15 | def test_load_activity_data(): | ||
| 16 | with patch('builtins.open', MagicMock()): | ||
| 17 | with patch('os.path.exists', return_value=True): | ||
| 18 | with patch('json.load', return_value={"123": {"active": True}}): | ||
| 19 | from cogs.vclogs import load_activity_data | ||
| 20 | data = load_activity_data() | ||
| 21 | assert isinstance(data, dict) | ||
| 22 | |||
| 23 | |||
| 24 | def test_save_activity_data(): | ||
| 25 | with patch('builtins.open', MagicMock()) as mock_open: | ||
| 26 | with patch('json.dump'): | ||
| 27 | from cogs.vclogs import save_activity_data | ||
| 28 | save_activity_data({"123": {"active": True}}) | ||
| 29 | mock_open.assert_called_once() | ||
| 30 | |||
| 31 | |||
| 32 | @pytest.fixture | ||
| 33 | def vclogs_cog(bot): | ||
| 34 | with patch('cogs.vclogs.get_voice_manager'): | ||
| 35 | with patch('cogs.vclogs.get_volume', return_value=1.0): | ||
| 36 | with patch('cogs.vclogs.save_settings'): | ||
| 37 | from cogs.vclogs import VcLogs | ||
| 38 | cog = VcLogs(bot) | ||
| 39 | return cog | ||
| 40 | |||
| 41 | |||
| 42 | @pytest.mark.asyncio | ||
| 43 | async def test_handle_state_change_deaf_true(vclogs_cog): | ||
| 44 | mock_member = MagicMock() | ||
| 45 | mock_member.display_name = "TestUser" | ||
| 46 | mock_channel = MagicMock() | ||
| 47 | |||
| 48 | tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'deaf', True, None) | ||
| 49 | |||
| 50 | assert "jest bity przez ojca" in tts_text | ||
| 51 | |||
| 52 | |||
| 53 | @pytest.mark.asyncio | ||
| 54 | async def test_handle_state_change_deaf_false(vclogs_cog): | ||
| 55 | mock_member = MagicMock() | ||
| 56 | mock_member.display_name = "TestUser" | ||
| 57 | mock_channel = MagicMock() | ||
| 58 | |||
| 59 | tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'deaf', False, None) | ||
| 60 | |||
| 61 | assert "uciek od ojca" in tts_text | ||
| 62 | |||
| 63 | |||
| 64 | @pytest.mark.asyncio | ||
| 65 | async def test_handle_state_change_mute_true(vclogs_cog): | ||
| 66 | mock_member = MagicMock() | ||
| 67 | mock_member.display_name = "TestUser" | ||
| 68 | mock_channel = MagicMock() | ||
| 69 | |||
| 70 | tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'mute', True, None) | ||
| 71 | |||
| 72 | assert "idzie robić jajecznice" in tts_text | ||
| 73 | |||
| 74 | |||
| 75 | @pytest.mark.asyncio | ||
| 76 | async def test_handle_state_change_mute_false(vclogs_cog): | ||
| 77 | mock_member = MagicMock() | ||
| 78 | mock_member.display_name = "TestUser" | ||
| 79 | mock_channel = MagicMock() | ||
| 80 | |||
| 81 | tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'mute', False, None) | ||
| 82 | |||
| 83 | assert "zrobił jajecznice" in tts_text \ No newline at end of file | ||
