async def test_copy_bracket_wrong_index(mocker): """Copies a bracket settings to another one, but input indexes are wrong.""" cog, mock_bot, _ = init_mocks() mock_bot.session.add_stub(Bracket(id=2, tournament_id=1)) with pytest.raises(commands.UserInputError): await cog.copy_bracket(cog, tosurnament_mock.CtxMock(mock_bot), 1, 3) with pytest.raises(commands.UserInputError): await cog.copy_bracket(cog, tosurnament_mock.CtxMock(mock_bot), 0, 2)
async def test_copy_bracket_wrong_index(mocker): """Copies a bracket settings to another one, but input indexes are wrong.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub( Tournament(id=1, guild_id=tosurnament_mock.GUILD_ID)) mock_bot.session.add_stub(Bracket(id=1, tournament_id=1)) mock_bot.session.add_stub(Bracket(id=2, tournament_id=1)) cog = tosurnament_mock.mock_cog(bracket.get_class(mock_bot)) with pytest.raises(commands.UserInputError): await cog.copy_bracket(cog, tosurnament_mock.CtxMock(mock_bot), 1, 3) with pytest.raises(commands.UserInputError): await cog.copy_bracket(cog, tosurnament_mock.CtxMock(mock_bot), 0, 2)
async def test_register_invalid_timezone(mocker): """Registers the player but the specified timezone is invalid.""" cog, mock_bot, _, _ = init_reschedule_single_mocks(mocker) with pytest.raises(exceptions.InvalidTimezone): await cog.register(cog, tosurnament_mock.CtxMock(mock_bot), timezone="abc")
async def test_set_language_invalid_language(mocker): """Sets the language, but the language is not in the list of languages.""" cog, mock_bot, _ = init_mocks() await cog.set_language(cog, tosurnament_mock.CtxMock(mock_bot), language="fr") cog.send_reply.assert_called_once_with(mocker.ANY, "invalid_language")
async def test_set_language_default(mocker): """Sets the language, but no language is specified so instead show the list of languages.""" cog, mock_bot, _ = init_mocks() await cog.set_language(cog, tosurnament_mock.CtxMock(mock_bot), language=None) cog.send_reply.assert_called_once_with(mocker.ANY, "default", "en")
async def test_is_staff(self): """Checks if the user is part of the tournament staff.""" bot_mock = tosurnament_mock.BotMock() bot_mock.session.add_stub(Tournament()) ctx_mock = tosurnament_mock.CtxMock(bot_mock) user_roles = tosurnament.UserRoles.get_from_context(ctx_mock) self.assertFalse(user_roles.is_staff()) ctx_mock.author.roles.append(tosurnament_mock.RoleMock(0, "Random")) user_roles = tosurnament.UserRoles.get_from_context(ctx_mock) self.assertFalse(user_roles.is_staff()) ctx_mock.author.roles.append(tosurnament_mock.RoleMock(0, "Referee")) user_roles = tosurnament.UserRoles.get_from_context(ctx_mock) self.assertTrue(user_roles.is_staff()) self.assertIsNotNone(user_roles.referee) self.assertIsNone(user_roles.streamer) self.assertIsNone(user_roles.commentator) ctx_mock.author.roles.append( tosurnament_mock.RoleMock(0, "Commentator")) user_roles = tosurnament.UserRoles.get_from_context(ctx_mock) self.assertTrue(user_roles.is_staff()) self.assertIsNotNone(user_roles.referee) self.assertIsNone(user_roles.streamer) self.assertIsNotNone(user_roles.commentator) ctx_mock.author.roles.append(tosurnament_mock.RoleMock(0, "Streamer")) user_roles = tosurnament.UserRoles.get_from_context(ctx_mock) self.assertTrue(user_roles.is_staff()) self.assertIsNotNone(user_roles.referee) self.assertIsNotNone(user_roles.streamer) self.assertIsNotNone(user_roles.commentator)
async def test_create_reaction_for_role_message_with_message_already_existing(mocker): """Creates a reaction for role message, one is already existing so it will be deleted.""" cog, mock_bot, reaction_for_role_message = init_mocks() cog.send_reply = mocker.AsyncMock(return_value=tosurnament_mock.SETUP_MESSAGE_MOCK) cog.delete_setup_messages = mocker.AsyncMock() mock_ctx = tosurnament_mock.CtxMock(mock_bot, channel=tosurnament_mock.SETUP_CHANNEL_MOCK) mock_ctx.send = mocker.AsyncMock(return_value=tosurnament_mock.PREVIEW_MESSAGE_MOCK) message_text = "Some text" await cog.create_reaction_for_role_message( cog, mock_ctx, tosurnament_mock.DEFAULT_CHANNEL_MOCK, message_text=message_text ) cog.delete_setup_messages.assert_called_once_with(tosurnament_mock.Matcher(reaction_for_role_message)) mock_bot.session.delete.assert_called_once_with(tosurnament_mock.Matcher(reaction_for_role_message)) cog.send_reply.assert_called_once_with(mocker.ANY, "success", "None\n") mock_ctx.send.assert_called_once_with(message_text) mock_bot.session.add.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, setup_message_id=tosurnament_mock.SETUP_MESSAGE_MOCK.id, preview_message_id=tosurnament_mock.PREVIEW_MESSAGE_MOCK.id, channel_id=tosurnament_mock.DEFAULT_CHANNEL_MOCK.id, text=message_text, ) ) )
async def test_create_reaction_for_role_message(mocker): """Creates a reaction for role message.""" mock_bot = tosurnament_mock.BotMock() cog = tosurnament_mock.mock_cog(reaction_for_role_message_module.get_class(mock_bot)) cog.send_reply = mocker.AsyncMock(return_value=tosurnament_mock.SETUP_MESSAGE_MOCK) mock_ctx = tosurnament_mock.CtxMock(mock_bot, channel=tosurnament_mock.SETUP_CHANNEL_MOCK) mock_ctx.send = mocker.AsyncMock(return_value=tosurnament_mock.PREVIEW_MESSAGE_MOCK) message_text = "Some text" await cog.create_reaction_for_role_message( cog, mock_ctx, tosurnament_mock.DEFAULT_CHANNEL_MOCK, message_text=message_text ) cog.send_reply.assert_called_once_with(mocker.ANY, "success", "None\n") mock_ctx.send.assert_called_once_with(message_text) mock_bot.session.add.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, setup_message_id=tosurnament_mock.SETUP_MESSAGE_MOCK.id, preview_message_id=tosurnament_mock.PREVIEW_MESSAGE_MOCK.id, channel_id=tosurnament_mock.DEFAULT_CHANNEL_MOCK.id, text=message_text, ) ) )
async def test_post_reaction_for_role_message(mocker): """Posts a reaction for role message.""" cog, mock_bot, reaction_for_role_message = init_mocks() reaction_for_role_message.emojis = "🛎️" reaction_for_role_message.roles = str(tosurnament_mock.VERIFIED_ROLE_MOCK.id) cog.delete_setup_messages = mocker.AsyncMock() mock_channel = tosurnament_mock.DEFAULT_CHANNEL_MOCK mock_message = tosurnament_mock.DEFAULT_MESSAGE_MOCK await cog.post_reaction_for_role_message(cog, tosurnament_mock.CtxMock(mock_bot)) mock_channel.send.assert_called_once_with("Some text") 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=0, setup_message_id=0, preview_message_id=0, channel_id=mock_channel.id, text="Some text", emojis="🛎️", roles=str(tosurnament_mock.VERIFIED_ROLE_MOCK.id), message_id=mock_message.id, ) ) ) cog.delete_setup_messages.assert_called_once_with(reaction_for_role_message) assert mock_message.reactions == ["🛎️"]
async def test_add_emoji_role_pair(mocker): """Adds a emoji/role pair to the role message creation.""" cog, mock_bot, reaction_for_role_message = init_mocks() 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_ctx = tosurnament_mock.CtxMock(mock_bot, channel=mock_channel) 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) cog.send_reply.assert_called_once_with(mocker.ANY, "success", "🛎️ | Verified\n") mock_ctx.send.assert_called_once_with("Some text") 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="🛎️", roles=str(tosurnament_mock.VERIFIED_ROLE_MOCK.id), ) ) ) assert mock_preview_message.reactions == ["🛎️"]
async def test_add_emoji_role_pair_invalid_argument(mocker): """Adds a emoji/role pair to the role message creation, but the emoji is an InvalidArgument.""" cog, mock_bot, _ = init_mocks() mock_message = tosurnament_mock.DEFAULT_MESSAGE_MOCK mock_message.add_reaction = mocker.AsyncMock(side_effect=discord.InvalidArgument()) await cog.add_emoji_role_pair(cog, tosurnament_mock.CtxMock(mock_bot, message=mock_message), "🛎️", None) cog.send_reply.assert_called_once_with(mocker.ANY, "invalid_emoji", "🛎️")
async def test_auth_not_linked(self): """Tries to authenticate the user but they didn't link their osu! account yet.""" bot_mock = tosurnament_mock.BotMock() cog = tosurnament_mock.mock_cog(auth.get_class(bot_mock)) with self.assertRaises(base.UserNotLinked): await cog.auth(cog, tosurnament_mock.CtxMock(bot_mock))
async def test_set_registration_end_date_value_error(mocker): """Sets the registration end date.""" cog, mock_bot, bracket = init_mocks() mocker.patch("common.databases.tosurnament.tournament.dateparser.parse", mocker.Mock(side_effect=ValueError())) date = "1 week" with pytest.raises(commands.UserInputError): await cog.set_registration_end(cog, tosurnament_mock.CtxMock(mock_bot), date=date)
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)
async def test_register(mocker): """Registers the player.""" mocker.patch(OSU_MODULE, tosurnament_mock.OsuMock()) cog, mock_bot, tournament, bracket = init_reschedule_single_mocks(mocker) players_spreadsheet = await bracket.get_players_spreadsheet() date = tournament.parse_date("1 week", prefer_dates_from="future") bracket.registration_end_date = date.strftime( tosurnament.DATABASE_DATE_FORMAT) mock_author = tosurnament_mock.DEFAULT_USER_MOCK assert mock_author.display_name != tosurnament_mock.OSU_USER_NAME await cog.register(cog, tosurnament_mock.CtxMock(mock_bot, mock_author), timezone="uTc+1") assert mock_author.roles == [tosurnament_mock.PLAYER_ROLE_MOCK] assert mock_author.display_name == tosurnament_mock.OSU_USER_NAME cog.send_reply.assert_called_once_with(mocker.ANY, "success") assert players_spreadsheet.spreadsheet.get_updated_values_with_ranges( ) == ( ["Players!A14:H14"], [[[ tosurnament_mock.OSU_USER_NAME, tosurnament_mock.DEFAULT_USER_MOCK.user_tag, tosurnament_mock.DEFAULT_USER_MOCK.id, "12345", tosurnament_mock.OSU_USER_ID, "1234", "fr", "UTC+1", ]]], )
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_set_qualifiers_results_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_qualifiers_results_spreadsheet(cog, mock_ctx, spreadsheet_id, sheet_name=sheet_name) update_expected = [ mocker.call(tosurnament_mock.Matcher(Bracket(tournament_id=1, qualifiers_results_spreadsheet_id=1))), mocker.call( tosurnament_mock.Matcher(QualifiersResultsSpreadsheet(spreadsheet_id=spreadsheet_id, sheet_name=sheet_name)) ), ] assert mock_bot.session.update.call_args_list == update_expected await cog.set_qualifiers_results_spreadsheet(cog, mock_ctx, spreadsheet_id, sheet_name="") update_expected = [ mocker.call( tosurnament_mock.Matcher(QualifiersResultsSpreadsheet(spreadsheet_id=spreadsheet_id, sheet_name=sheet_name)) ), ] assert mock_bot.session.update.call_args_list[2:] == update_expected
async def test_set_spreadsheet_values(mocker): """Sets spreadsheet values.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub( Tournament(id=1, current_bracket_id=1, guild_id=tosurnament_mock.GUILD_ID)) mock_bot.session.add_stub( Bracket(id=1, tournament_id=1, schedules_spreadsheet_id=1, players_spreadsheet_id=1)) mock_bot.session.add_stub(SchedulesSpreadsheet(id=1)) cog = tosurnament_mock.mock_cog(bracket.get_class(mock_bot)) mock_ctx = tosurnament_mock.CtxMock(mock_bot) await cog.set_schedules_spreadsheet_values(mock_ctx, {"sheet_name": SHEET_NAME}) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(SchedulesSpreadsheet(sheet_name=SHEET_NAME))) with pytest.raises(base.NoSpreadsheet): await cog.set_players_spreadsheet_values(mock_ctx, {"sheet_name": SHEET_NAME}) mock_bot.session.add_stub(PlayersSpreadsheet(id=1)) await cog.set_players_spreadsheet_values(mock_ctx, {"sheet_name": SHEET_NAME})
def test_validate_reschedule_feasibility(mocker): """Validates the reschedule feasibility and returns the previous date.""" cog, mock_bot, tournament, _ = init_mocks() tournament.reschedule_deadline_end = "monday 12:00" schedules_spreadsheet = SchedulesSpreadsheetSingleMock(id=1) previous_date = dateparser.parse( "2 days 13:00", settings={ "PREFER_DATES_FROM": "future", "TIMEZONE": "+00:00", "RETURN_AS_TIMEZONE_AWARE": True }, ) previous_date = previous_date.replace(second=0).replace(microsecond=0) new_date = dateparser.parse( "monday 11:00", settings={ "PREFER_DATES_FROM": "future", "TIMEZONE": "+00:00", "RETURN_AS_TIMEZONE_AWARE": True, "RELATIVE_BASE": previous_date, }, ) match_info = mocker.MagicMock() match_info.get_datetime.return_value = previous_date.strftime( "%d %B %H:%M") result_date = cog.validate_reschedule_feasibility( tosurnament_mock.CtxMock(mock_bot), tournament, schedules_spreadsheet, match_info, new_date, False, ) assert previous_date == result_date
def test_is_staff(): """Checks if the user is part of the tournament staff.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub(Tournament(guild_id=tosurnament_mock.GUILD_ID)) mock_ctx = tosurnament_mock.CtxMock(mock_bot) user_roles = tosurnament.UserDetails.get_from_ctx(mock_ctx) assert not user_roles.is_staff() mock_ctx.author.roles.append(tosurnament_mock.RoleMock("Random")) user_roles = tosurnament.UserDetails.get_from_ctx(mock_ctx) assert not user_roles.is_staff() mock_ctx.author.roles.append(tosurnament_mock.RoleMock("Referee")) user_roles = tosurnament.UserDetails.get_from_ctx(mock_ctx) assert user_roles.is_staff() assert user_roles.referee assert not user_roles.streamer assert not user_roles.commentator mock_ctx.author.roles.append(tosurnament_mock.RoleMock("Commentator")) user_roles = tosurnament.UserDetails.get_from_ctx(mock_ctx) assert user_roles.is_staff() assert user_roles.referee assert not user_roles.streamer assert user_roles.commentator mock_ctx.author.roles.append(tosurnament_mock.RoleMock("Streamer")) user_roles = tosurnament.UserDetails.get_from_ctx(mock_ctx) assert user_roles.is_staff() assert user_roles.referee assert user_roles.streamer assert user_roles.commentator
async def test_register_not_supported_yet_multiple_brackets(mocker): """Registers to the tournament, but there are multiple brackets.""" cog, mock_bot, _, _ = init_mocks() bracket2 = Bracket(id=2, tournament_id=1) mock_bot.session.add_stub(bracket2) await cog.register(cog, tosurnament_mock.CtxMock(mock_bot)) cog.send_reply.assert_called_once_with(mocker.ANY, "not_supported_yet")
def test_validate_reschedule_feasibility_past_deadline(mocker): """Previous date of the match to reschedule is past the reschedule deadline.""" cog, mock_bot, tournament, _ = init_mocks() schedules_spreadsheet = SchedulesSpreadsheetSingleMock(id=1) previous_date = dateparser.parse( "1 hour", settings={ "PREFER_DATES_FROM": "past", "TIMEZONE": "+00:00", "RETURN_AS_TIMEZONE_AWARE": True }, ) match_info = mocker.MagicMock() match_info.get_datetime.return_value = previous_date.strftime( "%d %B %H:%M") cog.get_referees_mentions_of_match = mocker.Mock() with pytest.raises(exceptions.PastDeadline): cog.validate_reschedule_feasibility( tosurnament_mock.CtxMock(mock_bot), tournament, schedules_spreadsheet, match_info, datetime.datetime.utcnow(), False, )
def test_validate_reschedule_feasibility_past_deadline_end(mocker): """Previous date of the match to reschedule is past the reschedule deadline.""" cog, mock_bot, tournament, _ = init_mocks() tournament.reschedule_deadline_end = "monday 12:00" schedules_spreadsheet = SchedulesSpreadsheetSingleMock(id=1) previous_date = dateparser.parse( "2 days 13:00", settings={ "PREFER_DATES_FROM": "future", "TIMEZONE": "+00:00", "RETURN_AS_TIMEZONE_AWARE": True }, ) new_date = dateparser.parse( "monday 13:00", settings={ "PREFER_DATES_FROM": "future", "TIMEZONE": "+00:00", "RETURN_AS_TIMEZONE_AWARE": True, "RELATIVE_BASE": previous_date, }, ) match_info = mocker.MagicMock() match_info.get_datetime.return_value = previous_date.strftime( "%d %B %H:%M") with pytest.raises(exceptions.PastDeadlineEnd): cog.validate_reschedule_feasibility( tosurnament_mock.CtxMock(mock_bot), tournament, schedules_spreadsheet, match_info, new_date, False, )
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, )))
async def test_on_reaction_add_to_message_emoji_not_in_list(mocker): """Adds the selected role from a role message, but the emoji is not in the list.""" cog, mock_bot, reaction_for_role_message = init_mocks() reaction_for_role_message.message_id = tosurnament_mock.DEFAULT_MESSAGE_MOCK.id mock_author = tosurnament_mock.DEFAULT_USER_MOCK mock_author.add_roles = mocker.AsyncMock() await cog.on_reaction_add_to_message.__wrapped__(cog, tosurnament_mock.CtxMock(mock_bot, mock_author), "🛎️") assert mock_author.add_roles.call_count == 0
async def test_register_registration_ended(): """Registers the player but the registration phase ended.""" cog, mock_bot, tournament, bracket = init_mocks() date = tournament.parse_date("1 week ago") bracket.registration_end_date = date.strftime( tosurnament.DATABASE_DATE_FORMAT) with pytest.raises(exceptions.RegistrationEnded): await cog.register(cog, tosurnament_mock.CtxMock(mock_bot))
def test_validate_new_date_time_is_in_the_past(): """Date is in the past.""" cog, mock_bot, tournament, _ = init_mocks() new_date = datetime.datetime.now( datetime.timezone.utc) - datetime.timedelta(minutes=1) with pytest.raises(exceptions.TimeInThePast): cog.validate_new_date(tosurnament_mock.CtxMock(mock_bot), tournament, None, new_date, False)
async def test_reschedule_invalid_match(mocker): """Reschedules a match, but the author is not a participant in the match.""" cog, mock_bot, _, _ = init_reschedule_single_mocks(mocker) with pytest.raises(exceptions.InvalidMatch): await cog.reschedule(cog, tosurnament_mock.CtxMock(mock_bot), "T1-1", date="3 days")
async def test_reschedule_invalid_match_id(mocker): """Reschedules a match, but the match id is invalid.""" cog, mock_bot, _, _ = init_reschedule_single_mocks(mocker) with pytest.raises(exceptions.InvalidMatchId): await cog.reschedule(cog, tosurnament_mock.CtxMock(mock_bot), "A1", date="3 days")
async def test_reschedule_invalid_new_date(): """Reschedules a match, but the new date in invalid.""" cog, mock_bot, _, _ = init_mocks() with pytest.raises(commands.UserInputError): await cog.reschedule(cog, tosurnament_mock.CtxMock(mock_bot), "", date="test new date")