Exemplo n.º 1
0
def create_players_spreadsheet(tournament_id, bracket_id, players_spreadsheet):
    players_spreadsheet_data = requests_wrapper(
        "post",
        TOSURNAMENT_URL + "tournaments/" + str(tournament_id) + "/brackets/" +
        str(bracket_id) + "/players_spreadsheet",
        data=players_spreadsheet.get_table_dict(),
    )
    return PlayersSpreadsheet(**players_spreadsheet_data)
Exemplo n.º 2
0
async def test_set_players_spreadsheet_range_pp(mocker):
    """Sets the players spreasheet's range pp."""
    cog, mock_bot, players_spreadsheet = init_mocks()
    range_pp = "A"
    assert players_spreadsheet.range_pp != range_pp
    await cog.set_players_spreadsheet_range_pp(
        cog, tosurnament_mock.CtxMock(mock_bot), cell_range=range_pp)
    mock_bot.session.update.assert_called_once_with(
        tosurnament_mock.Matcher(PlayersSpreadsheet(range_pp=range_pp)))
Exemplo n.º 3
0
async def test_set_players_spreadsheet_sheet_name(mocker):
    """Sets the players spreasheet's sheet name."""
    cog, mock_bot, players_spreadsheet = init_mocks()
    sheet_name = "a sheet name"
    assert players_spreadsheet.sheet_name != sheet_name
    await cog.set_players_spreadsheet_sheet_name(
        cog, tosurnament_mock.CtxMock(mock_bot), sheet_name=sheet_name)
    mock_bot.session.update.assert_called_once_with(
        tosurnament_mock.Matcher(PlayersSpreadsheet(sheet_name=sheet_name)))
Exemplo n.º 4
0
def get_players_spreadsheet(tournament_id, bracket_id, players_spreadsheet_id):
    players_spreadsheet_data = requests_wrapper(
        "get",
        TOSURNAMENT_URL + "tournaments/" + str(tournament_id) + "/brackets/" +
        str(bracket_id) + "/players_spreadsheet/" +
        str(players_spreadsheet_id),
    )
    if players_spreadsheet_data is None:
        return None
    return PlayersSpreadsheet(**players_spreadsheet_data)
Exemplo n.º 5
0
async def test_set_players_spreadsheet_max_range_for_teams(mocker):
    """Sets the players spreasheet's max range for teams."""
    cog, mock_bot, players_spreadsheet = init_mocks()
    max_range_for_teams = 1
    assert players_spreadsheet.max_range_for_teams != max_range_for_teams
    await cog.set_players_spreadsheet_max_range_for_teams(
        cog, tosurnament_mock.CtxMock(mock_bot), length=max_range_for_teams)
    mock_bot.session.update.assert_called_once_with(
        tosurnament_mock.Matcher(
            PlayersSpreadsheet(max_range_for_teams=max_range_for_teams)))
Exemplo n.º 6
0
def init_mocks():
    mock_bot = tosurnament_mock.BotMock()
    mock_bot.session.add_stub(
        Tournament(id=1,
                   current_bracket_id=1,
                   guild_id=tosurnament_mock.DEFAULT_GUILD_MOCK.id))
    mock_bot.session.add_stub(
        Bracket(id=1, tournament_id=1, players_spreadsheet_id=1))
    players_spreadsheet = PlayersSpreadsheet(id=1)
    mock_bot.session.add_stub(players_spreadsheet)
    cog = tosurnament_mock.mock_cog(module_to_test.get_class(mock_bot))
    return cog, mock_bot, players_spreadsheet
Exemplo n.º 7
0
async def test_set_players_spreadsheet(mocker):
    """Sets bracket spreadsheets."""
    mock_bot = tosurnament_mock.BotMock()
    mock_bot.session.add_stub(
        Tournament(id=1,
                   current_bracket_id=1,
                   guild_id=tosurnament_mock.DEFAULT_GUILD_MOCK.id))
    mock_bot.session.add_stub(Bracket(id=1, tournament_id=1))
    cog = tosurnament_mock.mock_cog(module_to_test.get_class(mock_bot))
    mock_ctx = tosurnament_mock.CtxMock(mock_bot)

    spreadsheet_id = "abcd1234"
    sheet_name = "a sheet name"

    await cog.set_players_spreadsheet(cog,
                                      mock_ctx,
                                      spreadsheet_id,
                                      sheet_name=sheet_name)
    update_expected = [
        mocker.call(
            tosurnament_mock.Matcher(
                Bracket(tournament_id=1, players_spreadsheet_id=1))),
        mocker.call(
            tosurnament_mock.Matcher(
                PlayersSpreadsheet(spreadsheet_id=spreadsheet_id,
                                   sheet_name=sheet_name))),
    ]
    assert mock_bot.session.update.call_args_list == update_expected

    await cog.set_players_spreadsheet(cog,
                                      mock_ctx,
                                      spreadsheet_id,
                                      sheet_name="")
    update_expected = [
        mocker.call(
            tosurnament_mock.Matcher(
                PlayersSpreadsheet(spreadsheet_id=spreadsheet_id,
                                   sheet_name=sheet_name))),
    ]
    assert mock_bot.session.update.call_args_list[2:] == update_expected
Exemplo n.º 8
0
async def test_set_players_spreadsheet_values(mocker):
    """Sets players spreadsheet values."""
    mock_bot = tosurnament_mock.BotMock()
    mock_bot.session.add_stub(
        Tournament(id=1,
                   current_bracket_id=1,
                   guild_id=tosurnament_mock.DEFAULT_GUILD_MOCK.id))
    mock_bot.session.add_stub(
        Bracket(id=1, tournament_id=1, players_spreadsheet_id=1))
    cog = tosurnament_mock.mock_cog(module_to_test.get_class(mock_bot))
    mock_ctx = tosurnament_mock.CtxMock(mock_bot)

    sheet_name = "a sheet name"
    with pytest.raises(base.NoSpreadsheet):
        await cog.set_players_spreadsheet_values(mock_ctx,
                                                 {"sheet_name": sheet_name})

    players_spreadsheet = PlayersSpreadsheet(id=1)
    mock_bot.session.add_stub(players_spreadsheet)
    assert players_spreadsheet.sheet_name != sheet_name
    await cog.set_players_spreadsheet_values(mock_ctx,
                                             {"sheet_name": sheet_name})
    mock_bot.session.update.assert_called_once_with(
        tosurnament_mock.Matcher(PlayersSpreadsheet(sheet_name=sheet_name)))
Exemplo n.º 9
0
async def test_copy_bracket(mocker):
    """Copies a bracket settings to another one."""
    mock_bot = tosurnament_mock.BotMock()
    mock_bot.session.add_stub(Tournament(id=1, current_bracket_id=1, guild_id=tosurnament_mock.DEFAULT_GUILD_MOCK.id))

    mock_bot.session.add_stub(
        Bracket(id=1, tournament_id=1, schedules_spreadsheet_id=1, players_spreadsheet_id=1, post_result_channel_id=1)
    )
    sheet_name = "a sheet name"
    schedules_spreadsheet = SchedulesSpreadsheet(
        id=1, sheet_name=sheet_name + " s", range_match_id="B2:B", range_team1="C2:C"
    )
    mock_bot.session.add_stub(schedules_spreadsheet)

    mock_bot.session.add_stub(Bracket(id=2, tournament_id=1, schedules_spreadsheet_id=2))
    mock_bot.session.add_stub(
        SchedulesSpreadsheet(id=2, sheet_name=sheet_name, range_match_id="A1:A", range_score_team1="B1:B")
    )

    cog = tosurnament_mock.mock_cog(bracket_module.get_class(mock_bot))
    mock_ctx = tosurnament_mock.CtxMock(mock_bot)

    await cog.copy_bracket(cog, mock_ctx, 1, 2)
    assert len(mock_bot.session.tables[Bracket.__tablename__]) == 2
    assert mock_bot.session.tables[Bracket.__tablename__][1].post_result_channel_id == 1
    assert len(mock_bot.session.tables[SchedulesSpreadsheet.__tablename__]) == 2
    assert mock_bot.session.tables[SchedulesSpreadsheet.__tablename__][1] != tosurnament_mock.Matcher(
        schedules_spreadsheet
    )
    schedules_spreadsheet.sheet_name = sheet_name
    assert mock_bot.session.tables[SchedulesSpreadsheet.__tablename__][1] == tosurnament_mock.Matcher(
        schedules_spreadsheet
    )
    assert PlayersSpreadsheet.__tablename__ not in mock_bot.session.tables

    players_spreadsheet = PlayersSpreadsheet(id=1, range_team="A1:A")
    mock_bot.session.add_stub(players_spreadsheet)

    await cog.copy_bracket(cog, mock_ctx, 1, 2)
    assert len(mock_bot.session.tables[PlayersSpreadsheet.__tablename__]) == 2
    assert mock_bot.session.tables[PlayersSpreadsheet.__tablename__][1] == tosurnament_mock.Matcher(players_spreadsheet)
Exemplo n.º 10
0
async def test_set_players_spreadsheet_range_value(mocker):
    """Sets players spreadsheet range value."""
    cog, mock_bot, players_spreadsheet = init_mocks()
    mock_ctx = tosurnament_mock.CtxMock(mock_bot)

    range_name = "range_team_name"
    range_value = "A"
    mocker.patch(MODULE_TO_TEST + ".spreadsheet.check_range",
                 mocker.Mock(return_value=False))
    with pytest.raises(commands.UserInputError):
        await cog.set_players_spreadsheet_range_value(mock_ctx, range_name,
                                                      range_value)

    mocker.patch(MODULE_TO_TEST + ".spreadsheet.check_range",
                 mocker.Mock(return_value=True))
    assert players_spreadsheet.range_team_name != range_value
    await cog.set_players_spreadsheet_range_value(mock_ctx, range_name,
                                                  range_value)
    mock_bot.session.update.assert_called_once_with(
        tosurnament_mock.Matcher(
            PlayersSpreadsheet(range_team_name=range_value)))
Exemplo n.º 11
0
 async def set_players_spreadsheet(self,
                                   ctx,
                                   spreadsheet_id: str,
                                   *,
                                   sheet_name: str = ""):
     """Sets the players spreadsheet."""
     tournament = self.get_tournament(ctx.guild.id)
     bracket = tournament.current_bracket
     spreadsheet_id = spreadsheet_api.extract_spreadsheet_id(spreadsheet_id)
     players_spreadsheet = bracket._players_spreadsheet
     if not players_spreadsheet:
         players_spreadsheet = tosurnament_api.create_players_spreadsheet(
             tournament.id, bracket.id,
             PlayersSpreadsheet(spreadsheet_id=spreadsheet_id,
                                sheet_name=sheet_name))
     else:
         players_spreadsheet.spreadsheet_id = spreadsheet_id
         if sheet_name:
             players_spreadsheet.sheet_name = sheet_name
         tosurnament_api.update_players_spreadsheet(tournament.id,
                                                    bracket.id,
                                                    players_spreadsheet)
     await self.send_reply(ctx, "success",
                           players_spreadsheet.spreadsheet_id)