|
1 | 1 | import mock |
2 | 2 | import pytest |
| 3 | +from aiohttp import ClientSession |
3 | 4 |
|
4 | 5 | import topgg |
5 | 6 |
|
6 | 7 |
|
7 | 8 | MOCK_TOKEN = ".eyJfdCI6IiIsImlkIjoiMzY0ODA2MDI5ODc2NTU1Nzc2In0=." |
8 | 9 |
|
9 | 10 |
|
| 11 | +@pytest.fixture |
| 12 | +def session() -> ClientSession: |
| 13 | + return mock.Mock(ClientSession) |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +def client(session: ClientSession) -> topgg.DBLClient: |
| 18 | + return topgg.DBLClient(MOCK_TOKEN, session=session) |
| 19 | + |
| 20 | + |
10 | 21 | @pytest.mark.asyncio |
11 | | -async def test_DBLClient_post_guild_count_with_no_args(): |
12 | | - client = topgg.DBLClient(MOCK_TOKEN) |
13 | | - with pytest.raises(TypeError, match="stats or guild_count must be provided."): |
| 22 | +async def test_DBLClient_post_guild_count_with_no_args(client: topgg.DBLClient): |
| 23 | + with pytest.raises(ValueError, match="Got an invalid server count. Got None."): |
14 | 24 | await client.post_guild_count() |
15 | 25 |
|
16 | 26 |
|
17 | 27 | @pytest.mark.asyncio |
18 | | -async def test_DBLClient_get_weekend_status(monkeypatch): |
19 | | - client = topgg.DBLClient(MOCK_TOKEN) |
| 28 | +async def test_DBLClient_get_weekend_status(monkeypatch, client: topgg.DBLClient): |
20 | 29 | monkeypatch.setattr("topgg.DBLClient._DBLClient__request", mock.AsyncMock()) |
21 | 30 | await client.get_weekend_status() |
22 | 31 | client._DBLClient__request.assert_called_once() |
23 | 32 |
|
24 | 33 |
|
25 | 34 | @pytest.mark.asyncio |
26 | | -async def test_DBLClient_post_guild_count(monkeypatch): |
27 | | - client = topgg.DBLClient(MOCK_TOKEN) |
| 35 | +async def test_DBLClient_post_guild_count(monkeypatch, client: topgg.DBLClient): |
28 | 36 | monkeypatch.setattr("topgg.DBLClient._DBLClient__request", mock.AsyncMock()) |
29 | 37 | await client.post_guild_count(guild_count=123) |
30 | 38 | client._DBLClient__request.assert_called_once() |
31 | 39 |
|
32 | 40 |
|
33 | 41 | @pytest.mark.asyncio |
34 | | -async def test_DBLClient_get_guild_count(monkeypatch): |
35 | | - client = topgg.DBLClient(MOCK_TOKEN) |
36 | | - monkeypatch.setattr("topgg.DBLClient._DBLClient__request", mock.AsyncMock(return_value={})) |
| 42 | +async def test_DBLClient_get_guild_count(monkeypatch, client: topgg.DBLClient): |
| 43 | + monkeypatch.setattr( |
| 44 | + "topgg.DBLClient._DBLClient__request", mock.AsyncMock(return_value={}) |
| 45 | + ) |
37 | 46 | await client.get_guild_count() |
38 | 47 | client._DBLClient__request.assert_called_once() |
39 | 48 |
|
40 | 49 |
|
41 | 50 | @pytest.mark.asyncio |
42 | | -async def test_DBLClient_get_bot_votes(monkeypatch): |
43 | | - client = topgg.DBLClient(MOCK_TOKEN) |
44 | | - monkeypatch.setattr("topgg.DBLClient._DBLClient__request", mock.AsyncMock(return_value=[])) |
| 51 | +async def test_DBLClient_get_bot_votes(monkeypatch, client: topgg.DBLClient): |
| 52 | + monkeypatch.setattr( |
| 53 | + "topgg.DBLClient._DBLClient__request", mock.AsyncMock(return_value=[]) |
| 54 | + ) |
45 | 55 | await client.get_bot_votes() |
46 | 56 | client._DBLClient__request.assert_called_once() |
47 | 57 |
|
48 | 58 |
|
49 | 59 | @pytest.mark.asyncio |
50 | | -async def test_DBLClient_get_user_vote(monkeypatch): |
51 | | - client = topgg.DBLClient(MOCK_TOKEN) |
52 | | - monkeypatch.setattr("topgg.DBLClient._DBLClient__request", mock.AsyncMock(return_value={"voted": 1})) |
| 60 | +async def test_DBLClient_get_user_vote(monkeypatch, client: topgg.DBLClient): |
| 61 | + monkeypatch.setattr( |
| 62 | + "topgg.DBLClient._DBLClient__request", mock.AsyncMock(return_value={"voted": 1}) |
| 63 | + ) |
53 | 64 | await client.get_user_vote(1234) |
54 | 65 | client._DBLClient__request.assert_called_once() |
0 commit comments