async def test_show_schedules_spreadsheet_settings(): """Shows the schedules spreadsheet settings of the current bracket.""" cog, mock_bot, schedules_spreadsheet = init_mocks() schedules_spreadsheet.range_match_id = "A2:A" expected_output = "**__Schedules spreadsheet settings:__**\n\n" expected_output += "__range_match_id__: `A2:A`\n" expected_output += "__range_team1__: `Undefined`\n" expected_output += "__range_score_team1__: `Undefined`\n" expected_output += "__range_score_team2__: `Undefined`\n" expected_output += "__range_team2__: `Undefined`\n" expected_output += "__range_date__: `Undefined`\n" expected_output += "__range_time__: `Undefined`\n" expected_output += "__range_referee__: `Undefined`\n" expected_output += "__range_streamer__: `Undefined`\n" expected_output += "__range_commentator__: `Undefined`\n" expected_output += "__range_mp_links__: `Undefined`\n" expected_output += "__date_format__: `Undefined`\n" expected_output += "__use_range__: `False`\n" expected_output += "__max_referee__: `1`\n" expected_output += "__max_streamer__: `1`\n" expected_output += "__max_commentator__: `2`\n" expected_output += "__id__: `1`\n" expected_output += "__spreadsheet_id__: `Undefined`\n" expected_output += "__sheet_name__: `Undefined`\n" mock_command = tosurnament_mock.CommandMock( cog.qualified_name, "show_schedules_spreadsheet_settings") mock_ctx = tosurnament_mock.CtxMock(mock_bot, command=mock_command) await cog.show_schedules_spreadsheet_settings(cog, mock_ctx) mock_ctx.send.assert_called_once_with(expected_output)
async def test_agree_to_reschedule(mocker): """Agrees to a reschedule by reacting on the reschedule message""" cog, mock_bot, tournament, bracket = init_reschedule_single_mocks(mocker) new_date = datetime.datetime.utcnow() reschedule_message = RescheduleMessage( tournament_id=tournament.id, bracket_id=bracket.id, match_id=MATCH_ID, new_date=new_date.strftime(tosurnament.DATABASE_DATE_FORMAT), ally_user_id=tosurnament_mock.DEFAULT_USER_MOCK.id, opponent_user_id=tosurnament_mock.ANOTHER_USER_MOCK.id, ) mock_command = tosurnament_mock.CommandMock( cog.qualified_name, "reaction_on_reschedule_message") mock_ctx = tosurnament_mock.CtxMock(mock_bot, command=mock_command) await cog.agree_to_reschedule(mock_ctx, reschedule_message, tournament) expected_replies = [ mocker.call(mocker.ANY, "accepted", tosurnament_mock.DEFAULT_USER_MOCK.display_name, MATCH_ID), mocker.call( mocker.ANY, "staff_notification", MATCH_ID, "Team1", "Team2", "**No previous date**", "**" + new_date.strftime(tosurnament.PRETTY_DATE_FORMAT) + "**", tosurnament_mock.REFEREE_USER_MOCK.display_name, tosurnament_mock.STREAMER_USER_MOCK.display_name, mocker. ANY, # TODO: should be "Commentator 1 / Commentator 2", but set is not ordered channel=tosurnament_mock.DEFAULT_CHANNEL_MOCK, ), ] assert cog.send_reply.call_args_list == expected_replies mock_bot.session.delete.assert_called_once_with( tosurnament_mock.Matcher(reschedule_message)) mock_bot.session.add.assert_called_once_with( tosurnament_mock.Matcher( StaffRescheduleMessage( tournament_id=tournament.id, bracket_id=bracket.id, message_id=mocker.ANY, team1="Team1", team2="Team2", match_id=MATCH_ID, previous_date=reschedule_message.previous_date, new_date=reschedule_message.new_date, referees_id=str(tosurnament_mock.REFEREE_USER_MOCK.id), streamers_id=str(tosurnament_mock.STREAMER_USER_MOCK.id), commentators_id=mocker.ANY, # TODO: can be unoredered, to fix )))
async def test_drop_match_as_streamer(mocker): """Drops a match as streamer.""" cog, mock_bot, _, bracket = init_reschedule_single_mocks(mocker) schedules_spreadsheet = await bracket.get_schedules_spreadsheet() mock_role = tosurnament_mock.STREAMER_ROLE_MOCK mock_user = tosurnament_mock.STREAMER_USER_MOCK mock_command = tosurnament_mock.CommandMock(cog.qualified_name, "drop_match_as_streamer") mock_ctx = tosurnament_mock.CtxMock(mock_bot, mock_user, command=mock_command) await cog.drop_match_as_streamer(cog, mock_ctx, "T1-1") mock_ctx.send.assert_called_once_with( "As a __" + mock_role.name + "__, " + mock_user.display_name + " **succesfully dropped** the matches: T1-1\n" ) assert schedules_spreadsheet.spreadsheet.get_updated_values_with_ranges() == (["Tier 1!I2:I2"], [[[""]]])
async def test_show_qualifiers_results_spreadsheet_settings(): """Shows the qualifiers results spreadsheet settings of the current bracket.""" cog, mock_bot, qualifiers_results_spreadsheet = init_mocks() qualifiers_results_spreadsheet.range_score = "A2:A" expected_output = "**__Qualifiers results spreadsheet settings:__**\n\n" expected_output += "__range_osu_id__: `Undefined`\n" expected_output += "__range_score__: `A2:A`\n" expected_output += "__id__: `1`\n" expected_output += "__spreadsheet_id__: `Undefined`\n" expected_output += "__sheet_name__: `Undefined`\n" mock_command = tosurnament_mock.CommandMock(cog.qualified_name, "show_qualifiers_results_spreadsheet_settings") mock_ctx = tosurnament_mock.CtxMock(mock_bot, command=mock_command) await cog.show_qualifiers_results_spreadsheet_settings(cog, mock_ctx) mock_ctx.send.assert_called_once_with(expected_output)
async def test_take_match_as_referee(mocker): """Takes a match as referee.""" cog, mock_bot, _, bracket = init_reschedule_single_mocks(mocker) schedules_spreadsheet = await bracket.get_schedules_spreadsheet() mock_role = tosurnament_mock.REFEREE_ROLE_MOCK mock_user = tosurnament_mock.REFEREE_USER_MOCK mock_command = tosurnament_mock.CommandMock(cog.qualified_name, "take_match_as_referee") mock_ctx = tosurnament_mock.CtxMock(mock_bot, mock_user, command=mock_command) await cog.take_match_as_referee(cog, mock_ctx, "T1-12") mock_ctx.send.assert_called_once_with( "As a __" + mock_role.name + "__, " + mock_user.display_name + " **succesfully took** the matches: T1-12\n" ) assert schedules_spreadsheet.spreadsheet.get_updated_values_with_ranges() == ( ["Tier 1!H13:H13"], [[[mock_user.display_name]]], )
async def test_show_guild_settings(): """Shows the guild settings of the current bracket.""" cog, mock_bot, _ = init_mocks() expected_output = "**__Guild settings:__**\n\n" expected_output += "__id__: `1`\n" expected_output += "__guild_id__: `" + str( tosurnament_mock.DEFAULT_GUILD_MOCK.id) + "`\n" expected_output += "__verified_role_id__: `0`\n" expected_output += "__admin_role_id__: `0`\n" expected_output += "__last_notification_date__: `Undefined`\n" expected_output += "__language__: `Undefined`\n" mock_command = tosurnament_mock.CommandMock(cog.qualified_name, "show_guild_settings") mock_ctx = tosurnament_mock.CtxMock(mock_bot, command=mock_command) await cog.show_guild_settings(cog, mock_ctx) mock_ctx.send.assert_called_once_with(expected_output)
async def test_show_bracket_settings(): """Shows the bracket settings of the current bracket.""" cog, mock_bot, _ = init_mocks() expected_output = "**__Bracket settings:__**\n\n" expected_output += "__id__: `1`\n" expected_output += "__tournament_id__: `1`\n" expected_output += "__name__: `Bracket 1`\n" expected_output += "__role_id__: `0`\n" expected_output += "__challonge__: `Undefined`\n" expected_output += "__players_spreadsheet_id__: `-1`\n" expected_output += "__schedules_spreadsheet_id__: `-1`\n" expected_output += "__qualifiers_spreadsheet_id__: `-1`\n" expected_output += "__qualifiers_results_spreadsheet_id__: `-1`\n" expected_output += "__post_result_channel_id__: `0`\n" expected_output += "__current_round__: `Undefined`\n" expected_output += "__registration_end_date__: `Undefined`\n" mock_command = tosurnament_mock.CommandMock(cog.qualified_name, "show_bracket_settings") mock_ctx = tosurnament_mock.CtxMock(mock_bot, command=mock_command) await cog.show_bracket_settings(cog, mock_ctx) mock_ctx.send.assert_called_once_with(expected_output)
async def test_add_emoji_role_pair_with_already_existing_emoji_role_pairs(mocker): """Adds a emoji/role pair to the role message creation, and it already contains emojis and roles.""" cog, mock_bot, reaction_for_role_message = init_mocks() reaction_for_role_message.emojis = "ā \nā" reaction_for_role_message.roles = str(tosurnament_mock.PLAYER_ROLE_MOCK.id) + "\n12349089" cog.delete_setup_messages = mocker.AsyncMock() cog.send_reply.return_value = tosurnament_mock.MessageMock(tosurnament_mock.SETUP_MESSAGE_MOCK.id + 1) mock_channel = tosurnament_mock.ChannelMock(tosurnament_mock.SETUP_CHANNEL_MOCK.id + 1) mock_command = tosurnament_mock.CommandMock(cog.qualified_name, "add_emoji_role_pair") mock_ctx = tosurnament_mock.CtxMock(mock_bot, channel=mock_channel, command=mock_command) mock_preview_message = tosurnament_mock.MessageMock(tosurnament_mock.PREVIEW_MESSAGE_MOCK.id + 1) mock_ctx.send.return_value = mock_preview_message await cog.add_emoji_role_pair(cog, mock_ctx, "šļø", tosurnament_mock.VERIFIED_ROLE_MOCK) cog.delete_setup_messages.assert_called_once_with(reaction_for_role_message) expected_success_output = "ā | " + tosurnament_mock.PLAYER_ROLE_MOCK.name + "\n" expected_success_output += "ā | Unknown role\n" expected_success_output += "šļø | Verified\n" cog.send_reply.assert_called_once_with(mocker.ANY, "success", expected_success_output) mock_ctx.send.assert_called_once_with("Some text") expected_roles = str(tosurnament_mock.PLAYER_ROLE_MOCK.id) + "\n" expected_roles += "12349089\n" expected_roles += str(tosurnament_mock.VERIFIED_ROLE_MOCK.id) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher( ReactionForRoleMessage( guild_id=tosurnament_mock.DEFAULT_GUILD_MOCK.id, author_id=tosurnament_mock.DEFAULT_USER_MOCK.id, setup_channel_id=tosurnament_mock.SETUP_CHANNEL_MOCK.id + 1, setup_message_id=tosurnament_mock.SETUP_MESSAGE_MOCK.id + 1, preview_message_id=tosurnament_mock.PREVIEW_MESSAGE_MOCK.id + 1, channel_id=tosurnament_mock.DEFAULT_CHANNEL_MOCK.id, text="Some text", emojis="ā \nā\nšļø", roles=expected_roles, ) ) ) assert mock_preview_message.reactions == ["ā ", "ā", "šļø"]
async def test_show_players_spreadsheet_settings(): """Shows the players spreadsheet settings of the current bracket.""" cog, mock_bot, players_spreadsheet = init_mocks() players_spreadsheet.range_team = "A2:A" expected_output = "**__Players spreadsheet settings:__**\n\n" expected_output += "__range_team_name__: `Undefined`\n" expected_output += "__range_team__: `A2:A`\n" expected_output += "__range_discord__: `Undefined`\n" expected_output += "__range_discord_id__: `Undefined`\n" expected_output += "__range_rank__: `Undefined`\n" expected_output += "__range_bws_rank__: `Undefined`\n" expected_output += "__range_osu_id__: `Undefined`\n" expected_output += "__range_pp__: `Undefined`\n" expected_output += "__range_country__: `Undefined`\n" expected_output += "__range_timezone__: `Undefined`\n" expected_output += "__max_range_for_teams__: `0`\n" expected_output += "__id__: `1`\n" expected_output += "__spreadsheet_id__: `Undefined`\n" expected_output += "__sheet_name__: `Undefined`\n" mock_command = tosurnament_mock.CommandMock( cog.qualified_name, "show_players_spreadsheet_settings") mock_ctx = tosurnament_mock.CtxMock(mock_bot, command=mock_command) await cog.show_players_spreadsheet_settings(cog, mock_ctx) mock_ctx.send.assert_called_once_with(expected_output)