async def test_queries_get_game_stats(mock_database): queries = ReplayDatabaseQueries(mock_database) await mock_database.add_mock_game((1, 1, 1), [(1, 1), (2, 2)]) stats = await queries.get_game_stats(1) assert stats == { 'featured_mod': 'faf', 'game_type': '0', 'recorder': 'user1', 'host': 'user1', 'launched_at': datetime.datetime(2001, 1, 1, 0, 0).timestamp(), 'game_end': datetime.datetime(2001, 1, 2, 0, 0).timestamp(), 'title': 'Name of the game', 'mapname': 'scmp_1_v1', 'num_players': 2 }
async def test_queries_get_mod_versions(mock_database): queries = ReplayDatabaseQueries(mock_database) mod = await queries.get_mod_versions("faf") assert mod == { '1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, '7': 1, '8': 1, '9': 1, '10': 1, }
async def test_queries_ignore_ai_players(mock_database): queries = ReplayDatabaseQueries(mock_database) await mock_database.add_mock_game((1, 1, 1), [(1, 1), (2, 2), (3, 3, 1)]) teams = await queries.get_teams_in_game(1) assert teams == {1: ["user1"], 2: ["user2"]}
async def test_queries_missing_teams(mock_database): queries = ReplayDatabaseQueries(mock_database) teams = await queries.get_teams_in_game(1) assert not teams
async def test_queries_ladder1v1_mod_query_error_is_swallowed(mock_database): queries = ReplayDatabaseQueries(mock_database) mod = await queries.get_mod_versions("ladder1v1") assert mod == {}
async def test_queries_null_game_end(mock_database): queries = ReplayDatabaseQueries(mock_database) stats = await queries.get_game_stats(test_db.SPECIAL_GAME_NO_END_TIME_ID) assert type(stats['game_end']) is float
async def test_queries_missing_game_map(mock_database): queries = ReplayDatabaseQueries(mock_database) stats = await queries.get_game_stats(test_db.SPECIAL_GAME_MISSING_MAP_ID) assert stats['mapname'] == "None"
async def test_queries_missing_game_players(mock_database): await mock_database.add_mock_game((1, 1, 1), []) queries = ReplayDatabaseQueries(mock_database) res = await queries.get_game_stats(1) assert res['num_players'] == 0
async def test_queries_missing_game_stats(mock_database): queries = ReplayDatabaseQueries(mock_database) with pytest.raises(BookkeepingError): await queries.get_game_stats(1)
def build(cls, database, config): queries = ReplayDatabaseQueries(database) saver = ReplaySaver.build(queries, config) analyzer = ReplayAnalyzer() return cls(queries, saver, analyzer)
def build(cls, database, **config): queries = ReplayDatabaseQueries(database) saver = ReplaySaver.build(queries, **config) return cls(queries, saver)
async def test_queries_null_game_end(mock_database): queries = ReplayDatabaseQueries(mock_database) stats = await queries.get_game_stats(101) # Game with no end time assert type(stats['game_end']) is float