Skip to content

Commit 0efa19e

Browse files
committed
Update tests
1 parent cbd8278 commit 0efa19e

10 files changed

+87
-44
lines changed

tests/async/conftest.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ async def create_client() -> AsyncClient:
1616

1717

1818
@pytest.fixture(name="auth_client")
19-
async def create_logged_in_client(
20-
request: pytest.FixtureRequest,
21-
) -> AsyncClient:
19+
async def create_logged_in_client(mock_http) -> AsyncClient:
2220
async with Client(is_async=True) as client:
23-
if "mock_http" in request.fixturenames:
24-
mock_http = request.getfixturevalue("mock_http")
25-
mock_http(client._state.http, "login")
26-
mock_http(client._state.http, "get_codingamer_from_id")
27-
mock_http(client._state.http, "get_codingamer_from_handle")
21+
mock_http(client._state.http, "login")
22+
mock_http(client._state.http, "get_codingamer_from_id")
23+
mock_http(client._state.http, "get_codingamer_from_handle")
2824

2925
await client.login(
3026
remember_me_cookie=os.environ.get("TEST_LOGIN_REMEMBER_ME_COOKIE"),
@@ -34,12 +30,10 @@ async def create_logged_in_client(
3430

3531
@pytest.fixture(name="private_clash")
3632
async def create_private_clash(
37-
request: pytest.FixtureRequest, auth_client: AsyncClient
33+
auth_client: AsyncClient, mock_http
3834
) -> ClashOfCode:
39-
if "mock_http" in request.fixturenames:
40-
mock_http = request.getfixturevalue("mock_http")
41-
mock_http(auth_client._state.http, "create_private_clash_of_code")
42-
mock_http(auth_client._state.http, "get_clash_of_code_from_handle")
35+
mock_http(auth_client._state.http, "create_private_clash_of_code")
36+
mock_http(auth_client._state.http, "get_clash_of_code_from_handle")
4337

4438
clash_of_code = await auth_client.create_private_clash_of_code(
4539
["Python3"], ["SHORTEST", "FASTEST"]

tests/async/test_codingamer.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,35 @@
1010

1111

1212
@pytest.fixture(name="codingamer")
13-
async def get_codingamer(auth_client) -> CodinGamer:
13+
async def get_codingamer(auth_client, mock_http) -> CodinGamer:
14+
mock_http(auth_client._state.http, "get_codingamer_from_handle")
1415
return await auth_client.get_codingamer(
1516
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
1617
)
1718

1819

19-
async def test_codingamer_avatar_and_cover_urls(client: AsyncClient):
20-
codingamer = await client.get_codingamer("Takos")
20+
async def test_codingamer_avatar_and_cover_urls(client: AsyncClient, mock_http):
21+
mock_http(client._state.http, "get_codingamer_from_handle")
22+
codingamer = await client.get_codingamer(
23+
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
24+
)
2125
assert isinstance(codingamer.avatar_url, str)
2226
assert isinstance(codingamer.cover_url, str)
2327
assert isinstance(codingamer.profile_url, str)
2428

2529

26-
async def test_codingamer_eq(client: AsyncClient, codingamer: CodinGamer):
30+
async def test_codingamer_eq(
31+
client: AsyncClient, codingamer: CodinGamer, mock_http
32+
):
33+
mock_http(client._state.http, "get_codingamer_from_handle")
2734
other_codingamer = await client.get_codingamer(
2835
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
2936
)
3037
assert codingamer == other_codingamer
3138

3239

33-
async def test_codingamer_get_followers(codingamer: CodinGamer):
40+
async def test_codingamer_get_followers(codingamer: CodinGamer, mock_http):
41+
mock_http(codingamer._state.http, "get_codingamer_followers")
3442
async for follower in codingamer.get_followers():
3543
assert isinstance(follower, CodinGamer)
3644

@@ -43,13 +51,15 @@ async def test_codingamer_get_followers_error(client: AsyncClient):
4351
next(await codingamer.get_followers())
4452

4553

46-
async def test_codingamer_get_followers_ids(codingamer: CodinGamer):
54+
async def test_codingamer_get_followers_ids(codingamer: CodinGamer, mock_http):
55+
mock_http(codingamer._state.http, "get_codingamer_follower_ids")
4756
followers_ids = await codingamer.get_followers_ids()
4857
assert isinstance(followers_ids, list)
4958
assert all(isinstance(follower_id, int) for follower_id in followers_ids)
5059

5160

52-
async def test_codingamer_get_followed(codingamer: CodinGamer):
61+
async def test_codingamer_get_followed(codingamer: CodinGamer, mock_http):
62+
mock_http(codingamer._state.http, "get_codingamer_following")
5363
async for followed in codingamer.get_followed():
5464
assert isinstance(followed, CodinGamer)
5565

@@ -62,12 +72,16 @@ async def test_codingamer_get_followed_error(client: AsyncClient):
6272
next(await codingamer.get_followed())
6373

6474

65-
async def test_codingamer_get_followed_ids(codingamer: CodinGamer):
75+
async def test_codingamer_get_followed_ids(codingamer: CodinGamer, mock_http):
76+
mock_http(codingamer._state.http, "get_codingamer_following_ids")
6677
followed_ids = await codingamer.get_followed_ids()
6778
assert isinstance(followed_ids, list)
6879
assert all(isinstance(followed_id, int) for followed_id in followed_ids)
6980

7081

71-
async def test_codingamer_get_clash_of_code_rank(codingamer: CodinGamer):
82+
async def test_codingamer_get_clash_of_code_rank(
83+
codingamer: CodinGamer, mock_http
84+
):
85+
mock_http(codingamer._state.http, "get_codingamer_clash_of_code_rank")
7286
rank = await codingamer.get_clash_of_code_rank()
7387
assert isinstance(rank, int)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"rank": 1234, "totalPlayers": 123456}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[1234567]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"userId": 1234567,
4+
"pseudo": "Pseudo123",
5+
"countryId": "US",
6+
"publicHandle": "0123456789abcdef0123456789abcdef7654321",
7+
"rank": 12345,
8+
"isFollowing": true,
9+
"isFollower": true,
10+
"points": 1234,
11+
"level": 9
12+
}
13+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"userId": 1234567,
4+
"pseudo": "Pseudo123",
5+
"countryId": "US",
6+
"publicHandle": "0123456789abcdef0123456789abcdef7654321",
7+
"rank": 12345,
8+
"isFollowing": true,
9+
"isFollower": true,
10+
"points": 1234,
11+
"level": 9
12+
}
13+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[1234567]

tests/mock/responses/get_codingamer_from_handle.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"pseudo": "Pseudo123",
77
"countryId": "US",
88
"publicHandle": "0123456789abcdef0123456789abcdef7654321",
9+
"avatar":12345678901234,
10+
"cover":12345678901234,
911
"formValues": {},
1012
"enable": false,
1113
"rank": 12345,

tests/sync/conftest.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ def create_client() -> SyncClient:
1616

1717

1818
@pytest.fixture(name="auth_client")
19-
def create_logged_in_client(request: pytest.FixtureRequest) -> SyncClient:
19+
def create_logged_in_client(mock_http) -> SyncClient:
2020
with Client() as client:
21-
if "mock_http" in request.fixturenames:
22-
mock_http = request.getfixturevalue("mock_http")
23-
mock_http(client._state.http, "login")
24-
mock_http(client._state.http, "get_codingamer_from_id")
25-
mock_http(client._state.http, "get_codingamer_from_handle")
21+
mock_http(client._state.http, "login")
22+
mock_http(client._state.http, "get_codingamer_from_id")
23+
mock_http(client._state.http, "get_codingamer_from_handle")
2624

2725
client.login(
2826
remember_me_cookie=os.environ.get("TEST_LOGIN_REMEMBER_ME_COOKIE"),
@@ -31,13 +29,9 @@ def create_logged_in_client(request: pytest.FixtureRequest) -> SyncClient:
3129

3230

3331
@pytest.fixture(name="private_clash")
34-
def create_private_clash(
35-
request: pytest.FixtureRequest, auth_client: SyncClient
36-
) -> ClashOfCode:
37-
if "mock_http" in request.fixturenames:
38-
mock_http = request.getfixturevalue("mock_http")
39-
mock_http(auth_client._state.http, "create_private_clash_of_code")
40-
mock_http(auth_client._state.http, "get_clash_of_code_from_handle")
32+
def create_private_clash(auth_client: SyncClient, mock_http) -> ClashOfCode:
33+
mock_http(auth_client._state.http, "create_private_clash_of_code")
34+
mock_http(auth_client._state.http, "get_clash_of_code_from_handle")
4135

4236
clash_of_code = auth_client.create_private_clash_of_code(
4337
["Python3"], ["SHORTEST", "FASTEST"]

tests/sync/test_codingamer.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,33 @@
88

99

1010
@pytest.fixture(name="codingamer")
11-
def get_codingamer(auth_client) -> CodinGamer:
11+
def get_codingamer(auth_client, mock_http) -> CodinGamer:
12+
mock_http(auth_client._state.http, "get_codingamer_from_handle")
1213
return auth_client.get_codingamer(
1314
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
1415
)
1516

1617

17-
def test_codingamer_avatar_and_cover_urls(client: Client):
18-
codingamer = client.get_codingamer("Takos")
18+
def test_codingamer_avatar_and_cover_urls(client: Client, mock_http):
19+
mock_http(client._state.http, "get_codingamer_from_handle")
20+
codingamer = client.get_codingamer(
21+
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
22+
)
1923
assert isinstance(codingamer.avatar_url, str)
2024
assert isinstance(codingamer.cover_url, str)
2125
assert isinstance(codingamer.profile_url, str)
2226

2327

24-
def test_codingamer_eq(client: Client, codingamer: CodinGamer):
28+
def test_codingamer_eq(client: Client, codingamer: CodinGamer, mock_http):
29+
mock_http(client._state.http, "get_codingamer_from_handle")
2530
other_codingamer = client.get_codingamer(
2631
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
2732
)
2833
assert codingamer == other_codingamer
2934

3035

31-
def test_codingamer_get_followers(codingamer: CodinGamer):
36+
def test_codingamer_get_followers(codingamer: CodinGamer, mock_http):
37+
mock_http(codingamer._state.http, "get_codingamer_followers")
3238
for follower in codingamer.get_followers():
3339
assert isinstance(follower, CodinGamer)
3440

@@ -41,13 +47,15 @@ def test_codingamer_get_followers_error(client: Client):
4147
next(codingamer.get_followers())
4248

4349

44-
def test_codingamer_get_followers_ids(codingamer: CodinGamer):
50+
def test_codingamer_get_followers_ids(codingamer: CodinGamer, mock_http):
51+
mock_http(codingamer._state.http, "get_codingamer_follower_ids")
4552
followers_ids = codingamer.get_followers_ids()
4653
assert isinstance(followers_ids, list)
4754
assert all(isinstance(follower_id, int) for follower_id in followers_ids)
4855

4956

50-
def test_codingamer_get_followed(codingamer: CodinGamer):
57+
def test_codingamer_get_followed(codingamer: CodinGamer, mock_http):
58+
mock_http(codingamer._state.http, "get_codingamer_following")
5159
for followed in codingamer.get_followed():
5260
assert isinstance(followed, CodinGamer)
5361

@@ -60,12 +68,14 @@ def test_codingamer_get_followed_error(client: Client):
6068
next(codingamer.get_followed())
6169

6270

63-
def test_codingamer_get_followed_ids(codingamer: CodinGamer):
71+
def test_codingamer_get_followed_ids(codingamer: CodinGamer, mock_http):
72+
mock_http(codingamer._state.http, "get_codingamer_following_ids")
6473
followed_ids = codingamer.get_followed_ids()
6574
assert isinstance(followed_ids, list)
6675
assert all(isinstance(followed_id, int) for followed_id in followed_ids)
6776

6877

69-
def test_codingamer_get_clash_of_code_rank(codingamer: CodinGamer):
78+
def test_codingamer_get_clash_of_code_rank(codingamer: CodinGamer, mock_http):
79+
mock_http(codingamer._state.http, "get_codingamer_clash_of_code_rank")
7080
rank = codingamer.get_clash_of_code_rank()
7181
assert isinstance(rank, int)

0 commit comments

Comments
 (0)