Here are the examples of the python api tests.mocks.build_client_user taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5 Examples
0
Source : test_events_cog.py
with MIT License
from lexicalunit
with MIT License
from lexicalunit
async def test_game(self, bot: SpellBot, ctx: InteractionContext):
assert ctx.guild
assert ctx.channel
assert isinstance(ctx.channel, discord.TextChannel)
assert isinstance(ctx.author, discord.User)
player1 = build_author(1)
player2 = build_author(2)
client_user = build_client_user()
game_post = build_message(ctx.guild, ctx.channel, client_user)
with mock_operations(lfg_interaction, users=[ctx.author, player1, player2]):
lfg_interaction.safe_send_channel.return_value = game_post
cog = EventsCog(bot)
await cog.game.func(
cog,
ctx,
f" < @{player1.id}> < @{player2.id}>",
GameFormat.LEGACY.value,
)
game = DatabaseSession.query(Game).one()
assert game.status == GameStatus.STARTED.value
users = DatabaseSession.query(User).all()
assert len(users) == 2
for user in users:
assert user.game_id == game.id
async def test_game_with_one_player(self, bot: SpellBot, ctx: InteractionContext):
0
Source : test_lfg_cog.py
with MIT License
from lexicalunit
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
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):
0
Source : test_lfg_cog.py
with MIT License
from lexicalunit
with MIT License
from lexicalunit
async def test_lfg_multiple_times(self):
guild = build_guild()
channel = build_channel(guild=guild)
author1 = build_author(1)
author2 = build_author(2)
ctx1 = build_ctx(guild, channel, author1, 1)
ctx2 = build_ctx(guild, channel, author2, 2)
client_user = build_client_user()
game_post = build_message(guild, channel, client_user, 3)
cog = LookingForGameCog(self.bot)
with mock_operations(lfg_interaction, users=[author1, author2]):
lfg_interaction.safe_send_channel.return_value = game_post
await cog.lfg.func(cog, ctx1, seats=2)
with mock_operations(lfg_interaction, users=[author1, author2]):
await cog.lfg.func(cog, ctx2, seats=2)
game = DatabaseSession.query(Game).one()
assert game.to_dict() == {
"channel_xid": channel.id,
"created_at": game.created_at,
"deleted_at": None,
"format": game.format,
"guild_xid": guild.id,
"id": game.id,
"jump_link": game.jump_link,
"message_xid": game_post.id,
"seats": 2,
"spectate_link": game.spectate_link,
"spelltable_link": game.spelltable_link,
"started_at": game.started_at,
"status": GameStatus.STARTED.value,
"updated_at": game.updated_at,
"voice_invite_link": None,
"voice_xid": None,
}
@pytest.mark.asyncio
0
Source : test_task.py
with MIT License
from lexicalunit
with MIT License
from lexicalunit
async def test_delete_happy_path(self):
long_ago = datetime.utcnow() - timedelta(minutes=self.settings.EXPIRE_TIME_M + 1)
guild = self.factories.guild.create()
channel = self.factories.channel.create(guild=guild)
self.factories.game.create(guild=guild, channel=channel, updated_at=long_ago)
async with TaskInteraction.create(self.bot) as interaction:
with mock_operations(task_interaction):
discord_guild = mock_discord_guild(guild)
discord_channel = build_channel(discord_guild)
client_user = build_client_user()
discord_message = build_message(
discord_guild,
discord_channel,
client_user,
)
task_interaction.safe_fetch_text_channel = AsyncMock(
return_value=discord_channel,
)
task_interaction.safe_get_partial_message = MagicMock(
return_value=discord_message,
)
await interaction.expire_inactive_games()
task_interaction.safe_update_embed.assert_called_once_with(
discord_message,
components=[],
content="Sorry, this game was expired due to inactivity.",
embed=None,
)
assert DatabaseSession.query(Game).filter(Game.deleted_at.is_(None)).count() == 0
async def test_delete_when_fetch_channel_fails(