async def test_games_fully_seated(self, guild: Guild, channel: Channel): started_game = GameFactory.create(guild=guild, channel=channel) pending_game = GameFactory.create(guild=guild, channel=channel) for _ in range(started_game.seats): UserFactory.create(game=started_game) UserFactory.create(game=pending_game) games = GamesService() await games.select(started_game.id) assert await games.fully_seated() await games.select(pending_game.id) assert not await games.fully_seated()
async def test_games_select_by_message_xid(self, guild: Guild, channel: Channel): game = GameFactory.create(guild=guild, channel=channel) games = GamesService() assert await games.select_by_message_xid(game.message_xid) assert not await games.select_by_message_xid(404)
async def test_lfg_with_friend_when_game_wrong_format( self, guild: Guild, channel: Channel): user1 = UserFactory.create(xid=101) user2 = UserFactory.create(xid=102) user3 = UserFactory.create(xid=103) bad_game = GameFactory.create( seats=4, channel=channel, guild=guild, format=GameFormat.TWO_HEADED_GIANT.value, ) games = GamesService() new = await games.upsert( guild_xid=guild.xid, channel_xid=channel.xid, author_xid=user1.xid, friends=[user2.xid, user3.xid], seats=4, format=GameFormat.COMMANDER.value, ) assert new DatabaseSession.expire_all() game = DatabaseSession.query(Game).filter(Game.id != bad_game.id).one() assert game.guild_xid == guild.xid assert game.channel_xid == channel.xid rows = DatabaseSession.query( User.xid).filter(User.game_id == game.id).all() assert set(row[0] for row in rows) == {101, 102, 103}
async def test_games_record_plays(self, guild: Guild, channel: Channel): game = GameFactory.create( guild=guild, channel=channel, seats=2, status=GameStatus.STARTED.value, ) user1 = UserFactory.create(xid=101, game=game) user2 = UserFactory.create(xid=102, game=game) games = GamesService() await games.select(game.id) await games.record_plays() DatabaseSession.expire_all() found = DatabaseSession.query(Play).filter( Play.user_xid == user1.xid).one() assert found.user_xid == user1.xid and found.game_id == game.id found = DatabaseSession.query(Play).filter( Play.user_xid == user2.xid).one() assert found.user_xid == user2.xid and found.game_id == game.id found = DatabaseSession.query(Play).filter( Play.user_xid == 103).one_or_none() assert not found