Skip to content

Commit 0aef6e4

Browse files
committed
Update tests
1 parent 7c20ad2 commit 0aef6e4

12 files changed

+546
-17
lines changed

tests/async/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23

34
import pytest
45
from dotenv import load_dotenv
@@ -28,6 +29,28 @@ async def create_logged_in_client(mock_http) -> AsyncClient:
2829
yield client
2930

3031

32+
@pytest.fixture(name="auth_client_bis")
33+
async def create_logged_in_client_bis(mock_http) -> AsyncClient:
34+
async with Client(is_async=True) as client:
35+
mock_http(client._state.http, "login")
36+
mock_http(client._state.http, "get_codingamer_from_id")
37+
mock_http(
38+
client._state.http,
39+
"get_codingamer_from_handle",
40+
api_data_filename="get_codingamer_from_handle.bis",
41+
)
42+
43+
await client.login(
44+
remember_me_cookie=os.environ.get(
45+
"TEST_LOGIN_REMEMBER_ME_COOKIE_{0.major}{0.minor}".format(
46+
sys.version_info
47+
)
48+
),
49+
)
50+
51+
yield client
52+
53+
3154
@pytest.fixture(name="private_clash")
3255
async def create_private_clash(
3356
auth_client: AsyncClient, mock_http

tests/async/test_clash_of_code.py

Whitespace-only changes.

tests/async/test_client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,18 @@ async def test_client_create_private_clash_of_code_value_error(
211211

212212

213213
async def test_client_join_private_clash_of_code(
214-
auth_client: AsyncClient, private_clash: ClashOfCode, mock_http
214+
private_clash: ClashOfCode, auth_client_bis: AsyncClient, mock_http
215215
):
216-
mock_http(auth_client._state.http, "join_clash_of_code_by_handle")
217-
mock_http(auth_client._state.http, "get_clash_of_code_from_handle")
218-
clash_of_code = await auth_client.join_private_clash_of_code(private_clash)
216+
mock_http(auth_client_bis._state.http, "join_clash_of_code_by_handle")
217+
mock_http(auth_client_bis._state.http, "get_clash_of_code_from_handle")
218+
clash_of_code = await auth_client_bis.join_private_clash_of_code(
219+
private_clash
220+
)
219221
assert isinstance(clash_of_code, ClashOfCode)
220222
assert private_clash.public_handle == clash_of_code.public_handle
221-
assert auth_client.codingamer.id in [p.id for p in clash_of_code.players]
223+
assert auth_client_bis.codingamer.id in [
224+
p.id for p in clash_of_code.players
225+
]
222226

223227

224228
async def test_client_join_private_clash_of_code_logged_in_error(

tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,14 @@ def mock_http(
144144
http_client: "HTTPClient",
145145
method: str,
146146
api_data=not_set, # None is an acceptable api data
147+
api_data_filename: str = None,
147148
*args,
148149
**kwargs,
149150
):
150151
if api_data is not_set:
151-
with open(f"tests/mock/responses/{method}.json") as f:
152+
with open(
153+
f"tests/mock/responses/{api_data_filename or method}.json"
154+
) as f:
152155
api_data = json.load(f)
153156

154157
mocker.patch.object(
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"nbPlayersMin": 2,
3+
"nbPlayersMax": 100,
4+
"publicHandle": "1234567fedcba9876543210fedcba9876543210",
5+
"clashDurationTypeId": "SHORT",
6+
"mode": "FASTEST",
7+
"startTimestamp": 1708107395331,
8+
"msBeforeStart": -26220184000,
9+
"msBeforeEnd": -26219284000,
10+
"finished": true,
11+
"started": true,
12+
"type": "PUBLIC",
13+
"players": [
14+
{
15+
"codingamerId": 1234567,
16+
"codingamerNickname": "Player 1",
17+
"codingamerHandle": "0123456789abcdef0123456789abcdef7654321",
18+
"score": 100,
19+
"duration": 120,
20+
"status": "STANDARD",
21+
"testSessionStatus": "COMPLETED",
22+
"languageId": "Python3",
23+
"rank": 1,
24+
"position": 2,
25+
"solutionShared": true,
26+
"testSessionHandle": "12345678fedcba9876543210fedcba9876543210",
27+
"submissionId": 12345678
28+
},
29+
{
30+
"codingamerId": 7654321,
31+
"codingamerNickname": "Player 2",
32+
"codingamerHandle": "fedcba9876543210fedcba98765432101234567",
33+
"score": 100,
34+
"duration": 300,
35+
"status": "STANDARD",
36+
"testSessionStatus": "COMPLETED",
37+
"languageId": "Python3",
38+
"rank": 2,
39+
"position": 3,
40+
"solutionShared": true,
41+
"testSessionHandle": "23456789edcba9876543210fedcba9876543210f",
42+
"submissionId": 23456789
43+
},
44+
{
45+
"codingamerId": 3456789,
46+
"codingamerNickname": "Player 3",
47+
"codingamerHandle": "ef0123456789abcdef0123456789abcd9876543",
48+
"codingamerAvatarId": 12345678901234,
49+
"score": 0,
50+
"duration": 240,
51+
"status": "OWNER",
52+
"testSessionStatus": "COMPLETED",
53+
"languageId": "Python3",
54+
"rank": 3,
55+
"position": 1,
56+
"solutionShared": false,
57+
"testSessionHandle": "34567890dcba9876543210fedcba9876543210fe",
58+
"submissionId": 34567890
59+
}
60+
],
61+
"programmingLanguages": ["Python3"],
62+
"modes": [
63+
"FASTEST", "SHORTEST"
64+
]
65+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"nbPlayersMin": 2,
3+
"nbPlayersMax": 100,
4+
"publicHandle": "1234567fedcba9876543210fedcba9876543210",
5+
"clashDurationTypeId": "SHORT",
6+
"mode": "FASTEST",
7+
"startTimestamp": 1708107395331,
8+
"msBeforeStart": -26220184000,
9+
"msBeforeEnd": -26219284000,
10+
"finished": true,
11+
"started": true,
12+
"type": "PUBLIC",
13+
"players": [
14+
{
15+
"codingamerId": 1234567,
16+
"codingamerNickname": "Player 1",
17+
"codingamerHandle": "0123456789abcdef0123456789abcdef7654321",
18+
"score": 100,
19+
"duration": 120,
20+
"status": "STANDARD",
21+
"testSessionStatus": "COMPLETED",
22+
"languageId": "Python3",
23+
"rank": 1,
24+
"position": 2,
25+
"solutionShared": true,
26+
"testSessionHandle": "12345678fedcba9876543210fedcba9876543210",
27+
"submissionId": 12345678
28+
},
29+
{
30+
"codingamerId": 7654321,
31+
"codingamerNickname": "Player 2",
32+
"codingamerHandle": "fedcba9876543210fedcba98765432101234567",
33+
"score": 100,
34+
"duration": 300,
35+
"status": "STANDARD",
36+
"testSessionStatus": "COMPLETED",
37+
"languageId": "Python3",
38+
"rank": 2,
39+
"position": 3,
40+
"solutionShared": true,
41+
"testSessionHandle": "23456789edcba9876543210fedcba9876543210f",
42+
"submissionId": 23456789
43+
},
44+
{
45+
"codingamerId": 3456789,
46+
"codingamerNickname": "Player 3",
47+
"codingamerHandle": "ef0123456789abcdef0123456789abcd9876543",
48+
"codingamerAvatarId": 12345678901234,
49+
"score": 0,
50+
"duration": 240,
51+
"status": "OWNER",
52+
"testSessionStatus": "COMPLETED",
53+
"languageId": "Python3",
54+
"rank": 3,
55+
"position": 1,
56+
"solutionShared": false,
57+
"testSessionHandle": "34567890dcba9876543210fedcba9876543210fe",
58+
"submissionId": 34567890
59+
}
60+
],
61+
"programmingLanguages": ["Python3"],
62+
"modes": [
63+
"FASTEST", "SHORTEST"
64+
]
65+
}

tests/mock/responses/get_clash_of_code_from_handle.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"codingamerNickname": "Player 1",
1717
"codingamerHandle": "0123456789abcdef0123456789abcdef7654321",
1818
"score": 100,
19-
"duration": 123456,
19+
"duration": 120,
2020
"status": "STANDARD",
2121
"testSessionStatus": "COMPLETED",
2222
"languageId": "Python3",
@@ -27,11 +27,11 @@
2727
"submissionId": 12345678
2828
},
2929
{
30-
"codingamerId": 2345678,
30+
"codingamerId": 7654321,
3131
"codingamerNickname": "Player 2",
32-
"codingamerHandle": "f0123456789abcdef0123456789abcde8765432",
32+
"codingamerHandle": "fedcba9876543210fedcba98765432101234567",
3333
"score": 100,
34-
"duration": 234567,
34+
"duration": 300,
3535
"status": "STANDARD",
3636
"testSessionStatus": "COMPLETED",
3737
"languageId": "Python3",
@@ -47,7 +47,7 @@
4747
"codingamerHandle": "ef0123456789abcdef0123456789abcd9876543",
4848
"codingamerAvatarId": 12345678901234,
4949
"score": 0,
50-
"duration": 345678,
50+
"duration": 240,
5151
"status": "OWNER",
5252
"testSessionStatus": "COMPLETED",
5353
"languageId": "Python3",
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"nbPlayersMin": 2,
3+
"nbPlayersMax": 100,
4+
"publicHandle": "1234567fedcba9876543210fedcba9876543210",
5+
"clashDurationTypeId": "SHORT",
6+
"mode": "FASTEST",
7+
"startTimestamp": 1708107395331,
8+
"msBeforeStart": -26220184000,
9+
"msBeforeEnd": -26219284000,
10+
"finished": true,
11+
"started": true,
12+
"type": "PUBLIC",
13+
"players": [
14+
{
15+
"codingamerId": 1234567,
16+
"codingamerNickname": "Player 1",
17+
"codingamerHandle": "0123456789abcdef0123456789abcdef7654321",
18+
"score": 100,
19+
"duration": 120,
20+
"status": "STANDARD",
21+
"testSessionStatus": "COMPLETED",
22+
"languageId": "Python3",
23+
"rank": 1,
24+
"position": 2,
25+
"solutionShared": true,
26+
"testSessionHandle": "12345678fedcba9876543210fedcba9876543210",
27+
"submissionId": 12345678
28+
},
29+
{
30+
"codingamerId": 7654321,
31+
"codingamerNickname": "Player 2",
32+
"codingamerHandle": "fedcba9876543210fedcba98765432101234567",
33+
"score": 100,
34+
"duration": 300,
35+
"status": "STANDARD",
36+
"testSessionStatus": "COMPLETED",
37+
"languageId": "Python3",
38+
"rank": 2,
39+
"position": 3,
40+
"solutionShared": true,
41+
"testSessionHandle": "23456789edcba9876543210fedcba9876543210f",
42+
"submissionId": 23456789
43+
},
44+
{
45+
"codingamerId": 3456789,
46+
"codingamerNickname": "Player 3",
47+
"codingamerHandle": "ef0123456789abcdef0123456789abcd9876543",
48+
"codingamerAvatarId": 12345678901234,
49+
"score": 0,
50+
"duration": 240,
51+
"status": "OWNER",
52+
"testSessionStatus": "COMPLETED",
53+
"languageId": "Python3",
54+
"rank": 3,
55+
"position": 1,
56+
"solutionShared": false,
57+
"testSessionHandle": "34567890dcba9876543210fedcba9876543210fe",
58+
"submissionId": 34567890
59+
}
60+
],
61+
"programmingLanguages": ["Python3"],
62+
"modes": [
63+
"FASTEST", "SHORTEST"
64+
]
65+
}

0 commit comments

Comments
 (0)