|
7 | 7 | from unittest import mock |
8 | 8 |
|
9 | 9 | import pytest |
10 | | -from sqlalchemy import select |
| 10 | +from sqlalchemy import and_, select |
11 | 11 |
|
12 | | -from server.db.models import game_player_stats |
| 12 | +from server.db.models import game_join_log, game_player_stats |
13 | 13 | from server.games.game_results import GameOutcome |
14 | 14 | from server.protocol import Protocol |
15 | 15 | from server.timing import datetime_now |
@@ -391,6 +391,61 @@ async def test_game_with_foed_player(lobby_server): |
391 | 391 | await join_game(guest_proto, game_id) |
392 | 392 |
|
393 | 393 |
|
| 394 | +@fast_forward(60) |
| 395 | +async def test_game_join_log(lobby_server, database): |
| 396 | + _, _, host_proto = await connect_and_sign_in( |
| 397 | + ("test", "test_password"), lobby_server |
| 398 | + ) |
| 399 | + guest_id, _, guest_proto = await connect_and_sign_in( |
| 400 | + ("Rhiza", "puff_the_magic_dragon"), lobby_server |
| 401 | + ) |
| 402 | + await read_until_command(guest_proto, "game_info") |
| 403 | + await read_until_command(host_proto, "game_info") |
| 404 | + |
| 405 | + # Host game |
| 406 | + await host_proto.send_message({ |
| 407 | + "command": "game_host", |
| 408 | + "mod": "faf", |
| 409 | + "visibility": "public", |
| 410 | + }) |
| 411 | + game_id = await host_game(host_proto) |
| 412 | + |
| 413 | + # Join a player |
| 414 | + await join_game(guest_proto, game_id) |
| 415 | + |
| 416 | + async with database.acquire() as conn: |
| 417 | + result = await conn.execute( |
| 418 | + select(game_join_log).where( |
| 419 | + and_( |
| 420 | + game_join_log.c.game_id == game_id, |
| 421 | + game_join_log.c.player_id == guest_id |
| 422 | + ) |
| 423 | + ) |
| 424 | + ) |
| 425 | + row = result.one() |
| 426 | + assert row is not None |
| 427 | + |
| 428 | + # Leave and re-join |
| 429 | + await guest_proto.send_message({ |
| 430 | + "target": "game", |
| 431 | + "command": "GameState", |
| 432 | + "args": ["Ended"] |
| 433 | + }) |
| 434 | + await join_game(guest_proto, game_id) |
| 435 | + |
| 436 | + async with database.acquire() as conn: |
| 437 | + result = await conn.execute( |
| 438 | + select(game_join_log).where( |
| 439 | + and_( |
| 440 | + game_join_log.c.game_id == game_id, |
| 441 | + game_join_log.c.player_id == guest_id |
| 442 | + ) |
| 443 | + ) |
| 444 | + ) |
| 445 | + rows = result.fetchall() |
| 446 | + assert len(rows) == 2 |
| 447 | + |
| 448 | + |
394 | 449 | @fast_forward(60) |
395 | 450 | async def test_game_info_messages(lobby_server): |
396 | 451 | host_id, _, host_proto = await connect_and_sign_in( |
@@ -1126,9 +1181,9 @@ async def test_partial_game_ended_rates_game(lobby_server, tmp_user): |
1126 | 1181 | # Set player options |
1127 | 1182 | await send_player_options( |
1128 | 1183 | host_proto, |
1129 | | - [guest_id, "Army", i+2], |
1130 | | - [guest_id, "StartSpot", i+2], |
1131 | | - [guest_id, "Color", i+2], |
| 1184 | + [guest_id, "Army", i + 2], |
| 1185 | + [guest_id, "StartSpot", i + 2], |
| 1186 | + [guest_id, "Color", i + 2], |
1132 | 1187 | [guest_id, "Faction", 1], |
1133 | 1188 | [guest_id, "Team", 3 if i % 2 == 0 else 2] |
1134 | 1189 | ) |
|
0 commit comments