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_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_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
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)))
async def test_get_a_bracket(self): """Sets a bracket as current bracket.""" bot_mock = tosurnament_mock.BotMock() bot_mock.session.add_stub(Tournament(current_bracket_id=1)) bot_mock.session.add_stub(Bracket(id=1, name=BRACKET_NAME)) bot_mock.session.add_stub(Bracket(id=2, name=BRACKET_NAME_2)) cog = tosurnament_mock.mock_cog(tournament.get_class(bot_mock)) await cog.get_bracket(cog, tosurnament_mock.CtxMock(bot_mock), number=2) bot_mock.session.update.assert_called_once_with(tosurnament_mock.Matcher(Tournament(current_bracket_id=2))) cog.send_reply.assert_called_once_with(mock.ANY, mock.ANY, "success", BRACKET_NAME_2)
async def test_set_tournament_values(mocker): """Puts the input values into the corresponding tournament.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub(Tournament(guild_id=tosurnament_mock.GUILD_ID)) cog = tosurnament_mock.mock_cog(tournament.get_class(mock_bot)) await cog.set_tournament_values(tosurnament_mock.CtxMock(mock_bot), {"current_bracket_id": 1}) 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", 1)
async def test_set_reschedule_deadline_end(day_name, day_time): """Sets a reschedule deadline end.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub( Tournament(id=1, guild_id=tosurnament_mock.GUILD_ID)) cog = tosurnament_mock.mock_cog(tournament.get_class(mock_bot)) date = day_name + day_time.strftime(" %H:%M") await cog.set_reschedule_deadline_end(cog, tosurnament_mock.CtxMock(mock_bot), date=date) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(Tournament(reschedule_deadline_end=date)))
async def test_set_reschedule_deadline_end_empty(): """Unsets a reschedule deadline end.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub( Tournament(id=1, guild_id=tosurnament_mock.GUILD_ID, reschedule_deadline_end="tuesday 12:00")) cog = tosurnament_mock.mock_cog(tournament.get_class(mock_bot)) await cog.set_reschedule_deadline_end(cog, tosurnament_mock.CtxMock(mock_bot), date="") mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(Tournament(reschedule_deadline_end="")))
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)
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_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_get_a_bracket_that_does_not_exist(self): """Sets a bracket as current bracket but it does not exist.""" bot_mock = tosurnament_mock.BotMock() bot_mock.session.add_stub(Tournament()) bot_mock.session.add_stub(Bracket(name=BRACKET_NAME)) cog = tosurnament_mock.mock_cog(tournament.get_class(bot_mock)) with self.assertRaises(discord.ext.commands.UserInputError): await cog.get_bracket(cog, tosurnament_mock.CtxMock(bot_mock), number=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_end_tournament(self): """Sends a message to react on in order to end the tournament.""" bot_mock = tosurnament_mock.BotMock() bot_mock.session.add_stub(Tournament()) cog = tosurnament_mock.mock_cog(guild_owner.get_class(bot_mock)) await cog.end_tournament(cog, tosurnament_mock.CtxMock(bot_mock)) cog.send_reply.assert_called_with(mock.ANY, mock.ANY, "are_you_sure") assert bot_mock.session.add.call_count == 1
async def test_copy_bracket_not_enough_bracket(mocker): """Copies a bracket settings to another one, but there is only one bracket.""" 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)) 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, 2)
async def test_end_tournament(mocker): """Sends a message to react on in order to end the tournament.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub(Tournament(guild_id=tosurnament_mock.GUILD_ID)) cog = tosurnament_mock.mock_cog(guild_owner.get_class(mock_bot)) await cog.end_tournament(cog, tosurnament_mock.CtxMock(mock_bot)) cog.send_reply.assert_called_with(mocker.ANY, mocker.ANY, "are_you_sure") mock_bot.session.add.assert_called_once_with( tosurnament_mock.Matcher(EndTournamentMessage()))
async def test_set_reschedule_deadline_end_invalid_date(): """Sets a reschedule deadline end but date is invalid.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub( Tournament(id=1, guild_id=tosurnament_mock.GUILD_ID)) cog = tosurnament_mock.mock_cog(tournament.get_class(mock_bot)) with pytest.raises(discord.ext.commands.UserInputError): await cog.set_reschedule_deadline_end( cog, tosurnament_mock.CtxMock(mock_bot), date="some date")
async def test_get_a_bracket_that_does_not_exist(): """Sets a bracket as current bracket but it does not exist.""" 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(tournament_id=1, name=BRACKET_NAME)) cog = tosurnament_mock.mock_cog(tournament.get_class(mock_bot)) with pytest.raises(discord.ext.commands.UserInputError): await cog.get_bracket(cog, tosurnament_mock.CtxMock(mock_bot), number=0)
async def test_create_tournament_already_created(self): """Creates a tournament but one has already been created.""" bot_mock = tosurnament_mock.BotMock() bot_mock.session.add_stub(Tournament()) cog = tosurnament_mock.mock_cog(guild_owner.get_class(bot_mock)) with self.assertRaises(tosurnament.TournamentAlreadyCreated): await cog.create_tournament( cog, tosurnament_mock.CtxMock(bot_mock), TOURNAMENT_ACRONYM, TOURNAMENT_NAME, )
async def test_set_bracket_values(self): """Puts the input values into the corresponding bracket.""" bot_mock = tosurnament_mock.BotMock() bot_mock.session.add_stub(Tournament()) bot_mock.session.add_stub(Bracket(name=BRACKET_NAME)) cog = tosurnament_mock.mock_cog(bracket.get_class(bot_mock)) await cog.set_bracket_values(tosurnament_mock.CtxMock(bot_mock), {"name": BRACKET_NAME_2}) bot_mock.session.update.assert_called_once_with( tosurnament_mock.Matcher(Bracket(name=BRACKET_NAME_2))) cog.send_reply.assert_called_once_with(mock.ANY, mock.ANY, "success", BRACKET_NAME_2)
async def test_get_bracket(self): """Shows all brackets.""" bot_mock = tosurnament_mock.BotMock() bot_mock.session.add_stub(Tournament(current_bracket_id=1)) bot_mock.session.add_stub(Bracket(id=1, name=BRACKET_NAME)) bot_mock.session.add_stub(Bracket(id=2, name=BRACKET_NAME_2)) cog = tosurnament_mock.mock_cog(tournament.get_class(bot_mock)) expected_output = "1: `" + BRACKET_NAME + "` (current bracket)\n" expected_output += "2: `" + BRACKET_NAME_2 + "`\n" await cog.get_bracket(cog, tosurnament_mock.CtxMock(bot_mock)) cog.send_reply.assert_called_once_with(mock.ANY, mock.ANY, "default", expected_output)
def post(handler, parameters, url_parameters, *ids_parameters): """POST method""" if not parameters: handler.logger.debug("Ignoring") handler.send_json("{}") return obj = Tournament() for key, value in parameters.items(): if key in obj.__dict__: setattr(obj, key, value) obj = handler.session.add(obj) handler.logger.debug("Created successfully") handler.send_object(obj)
async def test_create_tournament_already_created(): """Creates a tournament but one has already been created.""" mock_bot = tosurnament_mock.BotMock() mock_bot.session.add_stub(Tournament(guild_id=tosurnament_mock.GUILD_ID)) cog = tosurnament_mock.mock_cog(guild_owner.get_class(mock_bot)) with pytest.raises(tosurnament.TournamentAlreadyCreated): await cog.create_tournament( cog, tosurnament_mock.CtxMock(mock_bot), TOURNAMENT_ACRONYM, TOURNAMENT_NAME, )
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 create_tournament(self, ctx, acronym: str, name: str, bracket_name: str = ""): """ Creates a tournament. If a bracket name is not specified, the bracket takes the tournament's name as its name too. """ guild_id = ctx.guild.id tournament = self.bot.session.query(Tournament).where( Tournament.guild_id == guild_id).first() if tournament: raise tosurnament.TournamentAlreadyCreated() tournament = Tournament(guild_id=guild_id, acronym=acronym, name=name) self.bot.session.add(tournament) if not bracket_name: bracket_name = name bracket = Bracket(tournament_id=tournament.id, name=bracket_name) self.bot.session.add(bracket) tournament.current_bracket_id = bracket.id self.bot.session.update(tournament) await self.send_reply(ctx, ctx.command.name, "success", acronym, name, bracket_name)
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")
async def test_set_challonge(mocker): """Sets the challonge.""" 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)) await cog.set_challonge(cog, tosurnament_mock.CtxMock(mock_bot), challonge_tournament=CHALLONGE_ID_URL) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher( Bracket(tournament_id=1, challonge=CHALLONGE_ID))) cog.send_reply.assert_called_once_with(mocker.ANY, mocker.ANY, "success", CHALLONGE_ID)
async def test_set_bracket_values(mocker): """Puts the input values into the corresponding bracket.""" 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, name=BRACKET_NAME)) cog = tosurnament_mock.mock_cog(bracket.get_class(mock_bot)) await cog.set_bracket_values(tosurnament_mock.CtxMock(mock_bot), {"name": BRACKET_NAME_2}) mock_bot.session.update.assert_called_once_with( tosurnament_mock.Matcher(Bracket(tournament_id=1, name=BRACKET_NAME_2))) cog.send_reply.assert_called_once_with(mocker.ANY, mocker.ANY, "success", BRACKET_NAME_2)
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_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)