async def test_member_went_afk_in_no_channels(self): bot = GatherBot('testuser') bot.say = get_mock_coro(True) bot.announce_players = get_mock_coro(True) bot.organiser = unittest.mock.Mock() bot.organiser.remove_from_all.return_value = set() player = unittest.mock.Mock() await bot.member_went_afk(player) self.assertTrue(bot.organiser.remove_from_all.called)
async def test_on_message_error(self): bot = GatherBot('testuser') regex = r'^test' action = get_mock_coro_throwing_exception(AssertionError, 'error') bot.actions = {regex: (re.compile(regex, re.IGNORECASE), action)} bot.say = get_mock_coro(True) mock_message = mock.Mock() mock_message.author = 'anotheruser' mock_message.content = 'test' await bot.on_message(mock_message) self.assertTrue(action.called) self.assertTrue(bot.say.called)
async def test_announce_players(self, mock_organiser): bot = GatherBot('testuser') bot.say = get_mock_coro(True) bot.player_count_display = unittest.mock.Mock(return_value='(1/10)') bot.organiser.queues['test channel'] = set(['mac']) await bot.announce_players('test channel') bot.say.assert_called_with( 'test channel', 'Currently signed in players (1/10): mac' )
async def test_member_went_offline_in_channels(self): bot = GatherBot('testuser') bot.say = get_mock_coro(True) bot.announce_players = get_mock_coro(True) bot.player_count_display = get_mock_coro(True) bot.organiser = unittest.mock.Mock() bot.organiser.remove_from_all.return_value = set(['testchannel']) player = unittest.mock.Mock() await bot.member_went_offline(player) self.assertTrue(bot.organiser.remove_from_all.called) self.assertTrue(bot.say.called) self.assertTrue(bot.announce_players.called)
async def test_say_lines(self, mock_organiser): bot = GatherBot('testuser') bot.say = get_mock_coro(True) await bot.say_lines( 'test channel', [ 'test message 1', 'test message 2', ] ) bot.say.assert_has_calls([ unittest.mock.call('test channel', 'test message 1'), unittest.mock.call('test channel', 'test message 2'), ])