Esempio n. 1
0
async def test_link_regenerate_code(mocker):
    """Links the user, and since they already tried to link, regenerate the linking code."""
    mocker.patch(OS_MODULE + ".urandom",
                 mocker.Mock(return_value=CODE_URANDOM))
    mock_author = tosurnament_mock.UserMock()
    await mock_author.create_dm()
    mock_bot = tosurnament_mock.BotMock()
    mock_bot.session.add_stub(
        User(discord_id=tosurnament_mock.DEFAULT_USER_MOCK.id,
             verified=False,
             code="test"))
    cog = tosurnament_mock.mock_cog(auth.get_class(mock_bot))

    mock_ctx = tosurnament_mock.CtxMock(mock_bot, mock_author)
    await cog.link(cog, mock_ctx)
    assert mock_bot.session.add.call_count == 0
    user_matcher = tosurnament_mock.Matcher(
        User(
            verified=False,
            code=CODE_ASCII,
        ))
    mock_bot.session.update.assert_called_once_with(user_matcher)
    assert mock_ctx.message.delete.call_count == 1
    cog.send_reply.assert_called_once_with(
        mocker.ANY,
        "success",
        CODE_ASCII,
        channel=tosurnament_mock.DM_CHANNEL_MOCK)
Esempio n. 2
0
async def test_reschedule(mocker):
    """Reschedules a match, but the author is not a participant in the match."""
    cog, mock_bot, _, _ = init_reschedule_single_mocks(mocker)
    opponent_discord_id = 3249805
    mock_bot.session.add_stub(
        User(verified=True,
             osu_name_hash="team2",
             discord_id_snowflake=opponent_discord_id))
    match_id = "T1-1"
    author = tosurnament_mock.UserMock(user_tag="Team1#0001")
    await cog.reschedule(cog,
                         tosurnament_mock.CtxMock(mock_bot, author),
                         match_id,
                         date="3 days 18:30")
    mock_bot.session.add.assert_called_once_with(
        tosurnament_mock.Matcher(
            RescheduleMessage(
                tournament_id=1,
                bracket_id=1,
                match_id=match_id,
                ally_user_id=author.id,
                opponent_user_id=opponent_discord_id,
                previous_date=mocker.ANY,
                new_date=mocker.ANY,
            )))
Esempio n. 3
0
async def test_is_player_in_challonge(mocker):
    """Gets the team_info (if applicable) and the player name of the player if they are a running participant."""
    # TODO
    cog = tosurnament_mock.mock_cog(bracket_module.get_class(tosurnament_mock.BotMock()))
    member = tosurnament_mock.UserMock()
    teams_info = []
    participants = []
    cog.is_player_in_challonge(member, teams_info, participants)
Esempio n. 4
0
def test_is_player_in_challonge_not_a_participant(mocker):
    """ "Gets the team_info (if applicable) and the player name of the player if they are a running participant."""
    cog = tosurnament_mock.mock_cog(bracket_module.get_class(tosurnament_mock.BotMock()))
    member_name = "abvdsrjgfkh"
    member = tosurnament_mock.UserMock(user_name=member_name)
    team_info, player_name = cog.is_player_in_challonge(member, [], PARTICIPANT_LIST)
    assert not team_info
    assert not player_name
Esempio n. 5
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. 6
0
async def test_register_to_lobby(mocker):
    """Registers to a lobby."""
    cog, mock_bot, _, _ = init_reschedule_single_mocks(mocker)
    cog.add_team_to_lobby = mocker.Mock(return_value=True)
    cog.clear_team_from_other_lobbies = mocker.Mock()
    mock_user = tosurnament_mock.UserMock(222222)
    await cog.register_to_lobby(cog,
                                tosurnament_mock.CtxMock(mock_bot, mock_user),
                                lobby_id="L1-1")
    cog.send_reply.assert_called_once_with(mocker.ANY, "success", "L1-1")
Esempio n. 7
0
async def test_register_to_lobby_lobby_not_found(mocker):
    """Registers to a lobby."""
    cog, mock_bot, _, _ = init_reschedule_single_mocks(mocker)
    cog.add_team_to_lobby = mocker.Mock(return_value=False)
    mock_user = tosurnament_mock.UserMock(222222)
    with pytest.raises(exceptions.LobbyNotFound):
        await cog.register_to_lobby(cog,
                                    tosurnament_mock.CtxMock(
                                        mock_bot, mock_user),
                                    lobby_id="T1-1")
Esempio n. 8
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. 9
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. 10
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")
Esempio n. 11
0
async def test_link(mocker):
    """Links the user."""
    mocker.patch(OS_MODULE + ".urandom",
                 mocker.Mock(return_value=CODE_URANDOM))
    mock_author = tosurnament_mock.UserMock()
    mock_bot = tosurnament_mock.BotMock()
    cog = tosurnament_mock.mock_cog(auth.get_class(mock_bot))

    mock_ctx = tosurnament_mock.CtxMock(mock_bot, mock_author)
    await cog.link(cog, mock_ctx)
    mock_bot.session.add.assert_called_once_with(
        tosurnament_mock.Matcher(
            User(discord_id_snowflake=tosurnament_mock.DEFAULT_USER_MOCK.id,
                 verified=False,
                 code=CODE_ASCII)))
    assert mock_bot.session.update.call_count == 0
    assert mock_ctx.message.delete.call_count == 1
    cog.send_reply.assert_called_once_with(
        mocker.ANY,
        "success",
        CODE_ASCII,
        channel=tosurnament_mock.DM_CHANNEL_MOCK)