コード例 #1
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    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}
コード例 #2
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_when_no_blockers(self, game: Game):
        UserFactory.create(game=game)
        user3 = UserFactory.create()

        games = GamesService()
        await games.select(game.id)
        assert not await games.blocked(user3.xid)
コード例 #3
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    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)
コード例 #4
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_games_player_xids(self, game: Game):
        user1 = UserFactory.create(game=game)
        user2 = UserFactory.create(game=game)

        games = GamesService()
        await games.select(game.id)
        assert set(await games.player_xids()) == {user1.xid, user2.xid}
コード例 #5
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_games_to_embed(self, game: Game):
        public_embed = game.to_embed().to_dict()
        private_embed = game.to_embed(True).to_dict()

        games = GamesService()
        await games.select(game.id)
        assert (await games.to_embed()).to_dict() == public_embed
        assert (await games.to_embed()).to_dict() == private_embed
コード例 #6
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_when_no_blockers(self, game: Game):
        UserFactory.create(game=game)
        user3 = UserFactory.create()

        games = GamesService()
        await games.select(game.id)
        assert await games.filter_blocked_list(user3.xid,
                                               [1, 2, 3]) == [1, 2, 3]
コード例 #7
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_games_set_message_xid(self, game: Game):
        games = GamesService()
        await games.select(game.id)
        await games.set_message_xid(12345)

        DatabaseSession.expire_all()
        found = DatabaseSession.query(Game).filter_by(
            message_xid=12345).one_or_none()
        assert found and found.id == game.id
コード例 #8
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_when_blocker_outside_game(self, game: Game):
        user1 = UserFactory.create(game=game)
        user2 = UserFactory.create()

        BlockFactory.create(user_xid=user2.xid, blocked_user_xid=user1.xid)

        games = GamesService()
        await games.select(game.id)
        assert await games.filter_blocked_list(user2.xid, [user1.xid]) == []
コード例 #9
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_when_blocker_in_game(self, game: Game):
        user1 = UserFactory.create(game=game)
        user2 = UserFactory.create()

        BlockFactory.create(user_xid=user1.xid, blocked_user_xid=user2.xid)

        games = GamesService()
        await games.select(game.id)
        assert await games.blocked(user2.xid)
コード例 #10
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_games_make_ready(self, game: Game):
        games = GamesService()
        await games.select(game.id)
        await games.make_ready("http://link")

        DatabaseSession.expire_all()
        found = DatabaseSession.query(Game).get(game.id)
        assert found and found.spelltable_link == "http://link"
        assert found.status == GameStatus.STARTED.value
コード例 #11
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_games_players_included(self, game: Game):
        user1 = UserFactory.create(game=game)
        user2 = UserFactory.create()
        PlayFactory.create(user_xid=user1.xid, game_id=game.id)

        games = GamesService()
        await games.select(game.id)
        assert await games.players_included(user1.xid)
        assert not await games.players_included(user2.xid)
コード例 #12
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_games_set_voice(self, game: Game):
        games = GamesService()
        await games.select(game.id)
        await games.set_voice(12345, "http://link")

        DatabaseSession.expire_all()
        found = DatabaseSession.query(Game).get(game.id)
        assert found and found.voice_xid == 12345
        assert found.voice_invite_link == "http://link"
コード例 #13
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_games_add_player(self, game: Game):
        user = UserFactory.create()

        games = GamesService()
        await games.select(game.id)
        await games.add_player(user.xid)

        DatabaseSession.expire_all()
        found = DatabaseSession.query(User).get(user.xid)
        assert found and found.game.id == game.id
コード例 #14
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    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()
コード例 #15
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_games_watch_notes(self, game: Game):
        user1 = UserFactory.create(game=game)
        user2 = UserFactory.create(game=game)
        user3 = UserFactory.create()
        watch = WatchFactory.create(guild_xid=game.guild.xid,
                                    user_xid=user1.xid)

        DatabaseSession.expire_all()
        games = GamesService()
        await games.select(game.id)
        assert await games.watch_notes([user1.xid, user2.xid, user3.xid]) == {
            user1.xid: watch.note,
        }
コード例 #16
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_lfg_alone_when_existing_game(self, game: Game, user: User):
        games = GamesService()
        new = await games.upsert(
            guild_xid=game.guild.xid,
            channel_xid=game.channel.xid,
            author_xid=user.xid,
            friends=[],
            seats=4,
            format=GameFormat.COMMANDER.value,
        )
        assert not new

        DatabaseSession.expire_all()
        found = DatabaseSession.query(User).one()
        assert found.game_id == game.id
コード例 #17
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_games_add_points(self, game: Game):
        user1 = UserFactory.create(game=game)
        user2 = UserFactory.create(game=game)
        PlayFactory.create(user_xid=user1.xid, game_id=game.id, points=5)
        PlayFactory.create(user_xid=user2.xid, game_id=game.id, points=None)

        games = GamesService()
        await games.select(game.id)
        await games.add_points(user1.xid, 5)

        DatabaseSession.expire_all()
        found = DatabaseSession.query(Play).filter(
            Play.user_xid == user1.xid).one()
        assert found.points == 5
        found = DatabaseSession.query(Play).filter(
            Play.user_xid == user2.xid).one()
        assert found.points is None
コード例 #18
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_lfg_with_friend_when_existing_game(self, game: Game):
        user1 = UserFactory.create(xid=101)
        user2 = UserFactory.create(xid=102)

        games = GamesService()
        new = await games.upsert(
            guild_xid=game.guild.xid,
            channel_xid=game.channel.xid,
            author_xid=user1.xid,
            friends=[user2.xid],
            seats=4,
            format=GameFormat.COMMANDER.value,
        )
        assert not new

        DatabaseSession.expire_all()
        rows = DatabaseSession.query(
            User.xid).filter(User.game_id == game.id).all()
        assert set(row[0] for row in rows) == {101, 102}
コード例 #19
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    async def test_lfg_alone_when_no_game(self, guild: Guild, channel: Channel,
                                          user: User):
        games = GamesService()
        new = await games.upsert(
            guild_xid=guild.xid,
            channel_xid=channel.xid,
            author_xid=user.xid,
            friends=[],
            seats=4,
            format=GameFormat.COMMANDER.value,
        )
        assert new

        DatabaseSession.expire_all()
        found_user = DatabaseSession.query(User).one()
        found_game = DatabaseSession.query(Game).one()
        assert found_game.guild_xid == guild.xid
        assert found_game.channel_xid == channel.xid
        assert found_user.game_id == found_game.id
コード例 #20
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
    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
コード例 #21
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
 async def test_games_to_dict(self, game: Game):
     games = GamesService()
     await games.select(game.id)
     assert await games.to_dict() == game.to_dict()
コード例 #22
0
ファイル: test_games.py プロジェクト: lexicalunit/spellbot
 async def test_games_select(self, game: Game):
     games = GamesService()
     assert await games.select(game.id)
     assert not await games.select(404)