Esempio n. 1
0
async def test_reaction_on_end_tournament_message(mocker):
    """Sends a message to react on in order to end the tournament."""
    mock_bot = tosurnament_mock.BotMock()
    cog = tosurnament_mock.mock_cog(guild_owner.get_class(mock_bot))

    mock_bot.session.add_stub(
        Tournament(id=1, guild_id=tosurnament_mock.GUILD_ID))
    mock_bot.session.add_stub(
        Bracket(tournament_id=1,
                schedules_spreadsheet_id=1,
                players_spreadsheet_id=1))
    mock_bot.session.add_stub(SchedulesSpreadsheet(id=1))
    mock_bot.session.add_stub(PlayersSpreadsheet(id=1))
    mock_bot.session.add_stub(Bracket(tournament_id=1))
    mock_bot.session.add_stub(
        Bracket(tournament_id=1,
                schedules_spreadsheet_id=42,
                players_spreadsheet_id=42))
    mock_bot.session.add_stub(SchedulesSpreadsheet(id=42))
    mock_bot.session.add_stub(PlayersSpreadsheet(id=42))
    mock_bot.session.add_stub(
        Bracket(tournament_id=1, schedules_spreadsheet_id=43))
    mock_bot.session.add_stub(RescheduleMessage(tournament_id=1))
    mock_bot.session.add_stub(RescheduleMessage(tournament_id=1))
    mock_bot.session.add_stub(StaffRescheduleMessage(tournament_id=1))
    mock_bot.session.add_stub(StaffRescheduleMessage(tournament_id=1))
    mock_bot.session.add_stub(EndTournamentMessage(message_id=MESSAGE_ID))

    mock_bot.session.add_stub(Tournament(id=2))
    mock_bot.session.add_stub(
        Bracket(tournament_id=2,
                schedules_spreadsheet_id=2,
                players_spreadsheet_id=2))
    mock_bot.session.add_stub(SchedulesSpreadsheet(id=2))
    mock_bot.session.add_stub(PlayersSpreadsheet(id=2))
    mock_bot.session.add_stub(RescheduleMessage(tournament_id=2))

    await cog.reaction_on_end_tournament_message(
        MESSAGE_ID,
        tosurnament_mock.EmojiMock("✅"),
        tosurnament_mock.GuildMock(tosurnament_mock.GUILD_ID),
        tosurnament_mock.ChannelMock(),
        tosurnament_mock.UserMock(user_id=tosurnament_mock.GuildMock.OWNER_ID),
    )
    cog.send_reply.assert_called_with(mocker.ANY, mocker.ANY, "success")

    assert len(mock_bot.session.tables[Tournament.__tablename__]) == 1
    assert len(mock_bot.session.tables[Bracket.__tablename__]) == 1
    assert len(
        mock_bot.session.tables[SchedulesSpreadsheet.__tablename__]) == 1
    assert len(mock_bot.session.tables[PlayersSpreadsheet.__tablename__]) == 1
    assert len(mock_bot.session.tables[RescheduleMessage.__tablename__]) == 1
    assert len(
        mock_bot.session.tables[StaffRescheduleMessage.__tablename__]) == 0
    assert len(
        mock_bot.session.tables[EndTournamentMessage.__tablename__]) == 0
Esempio n. 2
0
async def test_reaction_on_end_tournament_message_invalid_emoji():
    """Sends a message to react on in order to end the tournament."""
    mock_bot = tosurnament_mock.BotMock()
    cog = tosurnament_mock.mock_cog(guild_owner.get_class(mock_bot))

    await cog.reaction_on_end_tournament_message(
        MESSAGE_ID,
        tosurnament_mock.EmojiMock("=)"),
        tosurnament_mock.GuildMock(tosurnament_mock.GUILD_ID),
        tosurnament_mock.ChannelMock(),
        tosurnament_mock.UserMock(user_id=tosurnament_mock.GuildMock.OWNER_ID),
    )
    assert mock_bot.session.query.call_count == 0
Esempio n. 3
0
async def test_reaction_on_end_tournament_message_no_tournament():
    """Sends a message to react on in order to end the tournament."""
    mock_bot = tosurnament_mock.BotMock()
    cog = tosurnament_mock.mock_cog(guild_owner.get_class(mock_bot))

    mock_bot.session.add_stub(EndTournamentMessage(message_id=MESSAGE_ID))
    await cog.reaction_on_end_tournament_message(
        MESSAGE_ID,
        tosurnament_mock.EmojiMock("✅"),
        tosurnament_mock.GuildMock(tosurnament_mock.GUILD_ID),
        tosurnament_mock.ChannelMock(),
        tosurnament_mock.UserMock(user_id=tosurnament_mock.GuildMock.OWNER_ID),
    )
    assert mock_bot.session.delete.call_count == 1
Esempio n. 4
0
async def test_reaction_on_end_tournament_message_refuse(mocker):
    """Sends a message to react on in order to end the tournament."""
    mock_bot = tosurnament_mock.BotMock()
    cog = tosurnament_mock.mock_cog(guild_owner.get_class(mock_bot))

    mock_bot.session.add_stub(Tournament(guild_id=tosurnament_mock.GUILD_ID))
    mock_bot.session.add_stub(Bracket())
    mock_bot.session.add_stub(EndTournamentMessage(message_id=MESSAGE_ID))
    await cog.reaction_on_end_tournament_message(
        MESSAGE_ID,
        tosurnament_mock.EmojiMock("❎"),
        tosurnament_mock.GuildMock(tosurnament_mock.GUILD_ID),
        tosurnament_mock.ChannelMock(),
        tosurnament_mock.UserMock(user_id=tosurnament_mock.GuildMock.OWNER_ID),
    )
    cog.send_reply.assert_called_with(mocker.ANY, mocker.ANY, "refused")