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_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_cancel_reaction_for_role_message_creation(mocker): """Cancels a reaction for role message creation.""" cog, mock_bot, reaction_for_role_message = init_mocks() cog.delete_setup_messages = mocker.AsyncMock() await cog.cancel_reaction_for_role_message_creation(cog, tosurnament_mock.CtxMock(mock_bot)) 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")
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_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.GUILD_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)) 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.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)
async def test_create_bracket(self): """Creates a bracket.""" bot_mock = tosurnament_mock.BotMock() bot_mock.session.add_stub(Tournament(id=1, current_bracket_id=2)) cog = tosurnament_mock.mock_cog(tournament.get_class(bot_mock)) await cog.create_bracket(cog, tosurnament_mock.CtxMock(bot_mock), name=BRACKET_NAME) bot_mock.session.add.assert_called_once_with( tosurnament_mock.Matcher(Bracket(tournament_id=1, name=BRACKET_NAME)) ) bot_mock.session.update.assert_called_once_with( tosurnament_mock.Matcher(Tournament(id=1, current_bracket_id=1)) ) cog.send_reply.assert_called_once_with(mock.ANY, mock.ANY, "success", BRACKET_NAME)
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_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_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_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})
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_set_team_captain_role_remove(self): """Removes the team captain role.""" bot_mock = tosurnament_mock.BotMock() bot_mock.session.add_stub(Tournament(team_captain_role_id=1)) cog = tosurnament_mock.mock_cog(tournament.get_class(bot_mock)) await cog.set_team_captain_role(cog, tosurnament_mock.CtxMock(bot_mock)) bot_mock.session.update.assert_called_once_with(tosurnament_mock.Matcher(Tournament(team_captain_role_id=0)))
async def test_create_bracket(mocker): """Creates a bracket.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub( Tournament(id=1, guild_id=tosurnament_mock.GUILD_ID, current_bracket_id=2)) cog = tosurnament_mock.mock_cog(tournament.get_class(mock_bot)) await cog.create_bracket(cog, tosurnament_mock.CtxMock(mock_bot), name=BRACKET_NAME) mock_bot.session.add.assert_called_once_with( tosurnament_mock.Matcher(Bracket(tournament_id=1, name=BRACKET_NAME))) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(Tournament(current_bracket_id=1))) cog.send_reply.assert_called_once_with(mocker.ANY, mocker.ANY, "success", BRACKET_NAME)
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)))
async def test_set_guild_values_and_create_guild(): """Sets guild values and create Guild object as it does not exist.""" mock_bot = tosurnament_mock.BotMock() cog = tosurnament_mock.mock_cog(guild_module.get_class(mock_bot)) role = tosurnament_mock.RoleMock("role", 324987) await cog.set_guild_values(tosurnament_mock.CtxMock(mock_bot), {"admin_role_id": role.id}) mock_bot.session.add.assert_called_once_with( tosurnament_mock.Matcher(Guild(admin_role_id=role.id)))
async def test_set_language(): """Sets the language.""" cog, mock_bot, guild = init_mocks() assert not guild.language await cog.set_language(cog, tosurnament_mock.CtxMock(mock_bot), language="en") mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(Guild(language="en")))
async def test_set_bracket_role(mocker): """Sets the bracket role.""" cog, mock_bot, bracket = init_mocks() role = tosurnament_mock.RoleMock("role", 324987) assert bracket.role_id != role.id await cog.set_bracket_role(cog, tosurnament_mock.CtxMock(mock_bot), role=role) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(Bracket(tournament_id=1, role_id=role.id, name=BRACKET1_NAME)) )
async def test_set_bracket_name(mocker): """Sets the bracket name.""" cog, mock_bot, bracket = init_mocks() bracket_name = "Bracket name" assert bracket.name != bracket_name await cog.set_bracket_name(cog, tosurnament_mock.CtxMock(mock_bot), name=bracket_name) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(Bracket(tournament_id=1, name=bracket_name)) )
async def test_set_tournament_values(self): """Puts the input values into the corresponding tournament.""" bot_mock = tosurnament_mock.BotMock() bot_mock.session.add_stub(Tournament()) cog = tosurnament_mock.mock_cog(tournament.get_class(bot_mock)) await cog.set_tournament_values(tosurnament_mock.CtxMock(bot_mock), {"current_bracket_id": 1}) bot_mock.session.update.assert_called_once_with(tosurnament_mock.Matcher(Tournament(current_bracket_id=1))) cog.send_reply.assert_called_once_with(mock.ANY, mock.ANY, "success", 1)
async def test_set_post_result_channel(mocker): """Sets the post result channel.""" cog, mock_bot, bracket = init_mocks() channel = tosurnament_mock.ChannelMock(324769) assert bracket.post_result_channel_id != channel.id await cog.set_post_result_channel(cog, tosurnament_mock.CtxMock(mock_bot), channel=channel) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(Bracket(tournament_id=1, post_result_channel_id=channel.id, name=BRACKET1_NAME)) )
async def test_set_current_bracket_round(mocker): """Sets the round of the current bracket.""" cog, mock_bot, bracket = init_mocks() current_round = "RO64" assert bracket.current_round != current_round await cog.set_current_bracket_round(cog, tosurnament_mock.CtxMock(mock_bot), current_round=current_round) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(Bracket(tournament_id=1, current_round=current_round, name=BRACKET1_NAME)) )
async def test_set_schedules_spreadsheet_range_time(mocker): """Sets the schedules spreasheet's range time.""" cog, mock_bot, schedules_spreadsheet = init_mocks() range_time = "A" assert schedules_spreadsheet.range_time != range_time await cog.set_schedules_spreadsheet_range_time( cog, tosurnament_mock.CtxMock(mock_bot), cell_range=range_time) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(SchedulesSpreadsheet(range_time=range_time)))
async def test_set_schedules_spreadsheet_staff_is_range(mocker): """Sets the schedules spreasheet's staff can be in multiple cells.""" cog, mock_bot, schedules_spreadsheet = init_mocks() use_range = True assert schedules_spreadsheet.use_range != use_range await cog.set_schedules_spreadsheet_staff_is_range( cog, tosurnament_mock.CtxMock(mock_bot), use_range=use_range) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(SchedulesSpreadsheet(use_range=use_range)))
async def test_set_qualifiers_spreadsheet_range_date(mocker): """Sets the qualifiers spreasheet's range date.""" cog, mock_bot, qualifiers_spreadsheet = init_mocks() range_date = "A" assert qualifiers_spreadsheet.range_date != range_date await cog.set_qualifiers_spreadsheet_range_date( cog, tosurnament_mock.CtxMock(mock_bot), cell_range=range_date) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(QualifiersSpreadsheet(range_date=range_date)))
async def test_set_schedules_spreadsheet_sheet_name(mocker): """Sets the schedules spreasheet's sheet name.""" cog, mock_bot, schedules_spreadsheet = init_mocks() sheet_name = "a sheet name" assert schedules_spreadsheet.sheet_name != sheet_name await cog.set_schedules_spreadsheet_sheet_name( cog, tosurnament_mock.CtxMock(mock_bot), sheet_name=sheet_name) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(SchedulesSpreadsheet(sheet_name=sheet_name)))
async def test_set_bracket_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.GUILD_ID)) mock_bot.session.add_stub(Bracket(id=1, tournament_id=1)) cog = tosurnament_mock.mock_cog(bracket.get_class(mock_bot)) mock_ctx = tosurnament_mock.CtxMock(mock_bot) await cog.set_bracket_spreadsheet(mock_ctx, "players", SPREADSHEET_ID, "") 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))), ] assert mock_bot.session.update.call_args_list == update_expected await cog.set_bracket_spreadsheet(mock_ctx, "players", 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 await cog.set_bracket_spreadsheet(mock_ctx, "schedules", SPREADSHEET_ID, "") update_expected = [ mocker.call( tosurnament_mock.Matcher( Bracket(tournament_id=1, players_spreadsheet_id=1, schedules_spreadsheet_id=1))), mocker.call( tosurnament_mock.Matcher( SchedulesSpreadsheet(spreadsheet_id=SPREADSHEET_ID))), ] assert mock_bot.session.update.call_args_list[3:] == update_expected
async def test_set_schedules_spreadsheet_date_format(mocker): """Sets the schedules spreasheet's date format.""" cog, mock_bot, schedules_spreadsheet = init_mocks() date_format = "%d %m" assert schedules_spreadsheet.date_format != date_format await cog.set_schedules_spreadsheet_date_format( cog, tosurnament_mock.CtxMock(mock_bot), date_format=date_format) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher( SchedulesSpreadsheet(date_format=date_format)))
async def test_create_tournament(self): """Creates a tournament.""" bot_mock = tosurnament_mock.BotMock() cog = tosurnament_mock.mock_cog(guild_owner.get_class(bot_mock)) await cog.create_tournament(cog, tosurnament_mock.CtxMock(bot_mock), TOURNAMENT_ACRONYM, TOURNAMENT_NAME) assert bot_mock.session.update.call_count == 1 tournament_matcher = tosurnament_mock.Matcher( Tournament(acronym=TOURNAMENT_ACRONYM, name=TOURNAMENT_NAME, current_bracket_id=1), ) bracket_matcher = tosurnament_mock.Matcher( Bracket(tournament_id=1, name=TOURNAMENT_NAME)) expected = [mock.call(tournament_matcher), mock.call(bracket_matcher)] assert bot_mock.session.add.call_args_list == expected cog.send_reply.assert_called_with(mock.ANY, mock.ANY, "success", TOURNAMENT_ACRONYM, TOURNAMENT_NAME, TOURNAMENT_NAME)
async def test_set_team_captain_role_remove(): """Removes the team captain role.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub( Tournament(guild_id=tosurnament_mock.GUILD_ID, team_captain_role_id=1)) cog = tosurnament_mock.mock_cog(tournament.get_class(mock_bot)) await cog.set_team_captain_role(cog, tosurnament_mock.CtxMock(mock_bot)) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(Tournament(team_captain_role_id=0)))