tests.mocks.mock_discord_channel

Here are the examples of the python api tests.mocks.mock_discord_channel taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

0 Source : test_lfg_cog.py
with MIT License
from lexicalunit

    async def test_lfg_when_game_has_no_message_xid(self, guild: Guild, channel: Channel):
        cog = LookingForGameCog(self.bot)
        discord_guild = mock_discord_guild(guild)
        discord_channel = mock_discord_channel(channel, guild=discord_guild)
        player1 = mock_discord_user(self.factories.user.create())
        player2 = mock_discord_user(self.factories.user.create())
        ctx1 = build_ctx(discord_guild, discord_channel, player1, 1)
        ctx2 = build_ctx(discord_guild, discord_channel, player2, 2)

        with mock_operations(lfg_interaction, users=[player1, player2]):
            # initial game post creation
            lfg_interaction.safe_send_channel.return_value = build_message(
                discord_guild,
                discord_channel,
                build_client_user(),
                1,
            )
            await cog.lfg.func(cog, ctx1)
            message_xid1 = DatabaseSession.query(Game.message_xid).scalar()

            # simulate the game having a missing message_xid
            DatabaseSession.execute(update(Game).values(message_xid=None))
            DatabaseSession.commit()

            # repost game post
            lfg_interaction.safe_send_channel.return_value = build_message(
                discord_guild,
                discord_channel,
                build_client_user(),
                2,
            )
            await cog.lfg.func(cog, ctx2)
            message_xid2 = DatabaseSession.query(Game.message_xid).scalar()

            assert message_xid1 != message_xid2

    # TODO: Refactor.
    @pytest.mark.skip(reason="needs refactoring")

0 Source : test_lfg_cog.py
with MIT License
from lexicalunit

    async def test_lfg_when_repost_game_fails(self, guild: Guild, channel: Channel):
        cog = LookingForGameCog(self.bot)
        discord_guild = mock_discord_guild(guild)
        discord_channel = mock_discord_channel(channel, guild=discord_guild)
        player1 = mock_discord_user(self.factories.user.create())
        player2 = mock_discord_user(self.factories.user.create())
        ctx1 = build_ctx(discord_guild, discord_channel, player1, 1)
        ctx2 = build_ctx(discord_guild, discord_channel, player2, 2)

        with mock_operations(lfg_interaction, users=[player1, player2]):
            # initial game post creation
            lfg_interaction.safe_send_channel.return_value = build_message(
                discord_guild,
                discord_channel,
                build_client_user(),
                1,
            )
            await cog.lfg.func(cog, ctx1)
            message_xid1 = DatabaseSession.query(Game.message_xid).scalar()

            # simulate the game having a missing message_xid
            DatabaseSession.execute(update(Game).values(message_xid=None))
            DatabaseSession.commit()

            # repost game post
            lfg_interaction.safe_send_channel.return_value = None
            await cog.lfg.func(cog, ctx2)
            message_xid2 = DatabaseSession.query(Game.message_xid).scalar()

            assert message_xid1 != message_xid2
            assert not message_xid2

    async def test_lfg_multiple_times(self):