aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cogs/test_web.py
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-04-19 15:44:33 +0200
committersalmonik <raisersoft@proton.me>2026-04-19 15:44:33 +0200
commitb343381fea3eab26e334a1b3bba202d715f9ea2e (patch)
tree792210018d1e11ac3b160edfe29cf878eb4e3f56 /tests/cogs/test_web.py
parentchore: add pycord dependency, update main (diff)
downloadsenator-sperma-b343381fea3eab26e334a1b3bba202d715f9ea2e.tar.gz
senator-sperma-b343381fea3eab26e334a1b3bba202d715f9ea2e.zip
test: improve test assertions and edge cases
Diffstat (limited to '')
-rw-r--r--tests/cogs/test_web.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/tests/cogs/test_web.py b/tests/cogs/test_web.py
index 53a44e5..e0d2208 100644
--- a/tests/cogs/test_web.py
+++ b/tests/cogs/test_web.py
@@ -13,7 +13,7 @@ def web_cog(bot):
13@pytest.mark.asyncio 13@pytest.mark.asyncio
14async def test_web_command_success(web_cog, mock_channel, mock_guild, bot): 14async def test_web_command_success(web_cog, mock_channel, mock_guild, bot):
15 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 15 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
16 16
17 mock_response = MagicMock() 17 mock_response = MagicMock()
18 mock_response.status_code = 200 18 mock_response.status_code = 200
19 mock_response.text = ''' 19 mock_response.text = '''
@@ -22,7 +22,7 @@ async def test_web_command_success(web_cog, mock_channel, mock_guild, bot):
22 <a class="result__a" href="https://example.com/2">Test Result 2</a> 22 <a class="result__a" href="https://example.com/2">Test Result 2</a>
23 </html> 23 </html>
24 ''' 24 '''
25 25
26 with patch('cogs.web.requests.get', return_value=mock_response) as mock_get: 26 with patch('cogs.web.requests.get', return_value=mock_response) as mock_get:
27 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 27 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
28 await web_cog.web.callback(web_cog, ctx, query="test query") 28 await web_cog.web.callback(web_cog, ctx, query="test query")
@@ -33,11 +33,11 @@ async def test_web_command_success(web_cog, mock_channel, mock_guild, bot):
33@pytest.mark.asyncio 33@pytest.mark.asyncio
34async def test_web_command_no_results(web_cog, mock_channel, mock_guild, bot): 34async def test_web_command_no_results(web_cog, mock_channel, mock_guild, bot):
35 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 35 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
36 36
37 mock_response = MagicMock() 37 mock_response = MagicMock()
38 mock_response.status_code = 200 38 mock_response.status_code = 200
39 mock_response.text = '<html><body></body></html>' 39 mock_response.text = '<html><body></body></html>'
40 40
41 with patch('cogs.web.requests.get', return_value=mock_response): 41 with patch('cogs.web.requests.get', return_value=mock_response):
42 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 42 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
43 await web_cog.web.callback(web_cog, ctx, query="test") 43 await web_cog.web.callback(web_cog, ctx, query="test")
@@ -47,11 +47,11 @@ async def test_web_command_no_results(web_cog, mock_channel, mock_guild, bot):
47@pytest.mark.asyncio 47@pytest.mark.asyncio
48async def test_web_command_http_error(web_cog, mock_channel, mock_guild, bot): 48async def test_web_command_http_error(web_cog, mock_channel, mock_guild, bot):
49 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 49 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
50 50
51 mock_response = MagicMock() 51 mock_response = MagicMock()
52 mock_response.status_code = 500 52 mock_response.status_code = 500
53 53
54 with patch('cogs.web.requests.get', return_value=mock_response): 54 with patch('cogs.web.requests.get', return_value=mock_response):
55 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 55 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
56 await web_cog.web.callback(web_cog, ctx, query="test") 56 await web_cog.web.callback(web_cog, ctx, query="test")
57 mock_respond.assert_called_once_with(content="Error: 500", ephemeral=True) \ No newline at end of file 57 mock_respond.assert_called_once_with(content="Error: 500", ephemeral=True)