async def choose_game(self, member): mutual_guilds = [x.id for x in self.bot.guilds if x.get_member(member.id) is not None] games = list(Game.select().where( (Game.guild_id.in_(mutual_guilds)) & ( Game.active == True) )) if len(games) == 1: return games[0]
async def poll(self): for game in Game.select().where(Game.active == True): if not game.started: continue if len(game.players) > 1: if game.ended: game.end() if game.cycle_ended: game.next_cycle()
async def get_games(user=Depends(manager)): with db_session: def parseGame(game): game_dict = game.to_dict() players = game.players.count() game_dict["joined_players"] = players return game_dict games = Game.select()[:] result = {'data': [parseGame(g) for g in games if not g.started]} return result
def test_get_games(): headers = { 'Authorization': 'Bearer ' + pytest.users[2]["token"], 'Content-Type': 'text/plain' } response = client.get("/games/", headers=headers, json={}) with db_session: def parseGame(game): game_dict = game.to_dict() players = game.players.count() game_dict["joined_players"] = players return game_dict creation_date = str( Game.get(id=pytest.info['game']).creation_date).replace(" ", "T") games = Game.select()[:] result = {'data': [parseGame(g) for g in games if not g.started]} for g in result["data"]: g["creation_date"] = str(g["creation_date"]).replace(" ", "T") assert response.status_code == 200 assert response.json() == result