def test_admin(self, *args): """ Test that basic admin commands work """ bot = GifBot("test.config", MagicMock()) self.assertNotIn("tag", bot.store.tags) self.assertEqual(len(bot.store.elements), 2) bot.handle_message({ "user": "******", "text": "add url tag", "channel": "Dtest_channel", "ts": "test_ts" }) self.assertIn("tag", bot.store.tags) self.assertEqual(len(bot.store.elements), 3) bot.handle_message({ "user": "******", "text": "remove url", "channel": "Dtest_channel", "ts": "test_ts" }) self.assertNotIn("tag", bot.store.tags) self.assertEqual(len(bot.store.elements), 2)
def test_not_trigger_self(self, *args): """ The bot shouldn't be able to trigger itself """ bot = GifBot("test.config", MagicMock()) bot.handle_message({ "user": "******", "text": "Something something test_trigger", "channel": "test_channel", "ts": "test_ts" }) api_collector.assert_not_called()
def test_handle_request_success(self, *args): """ The bot should post a gif and a happy reaction when they can fulfill a request """ bot = GifBot("test.config", MagicMock()) bot.handle_message({ "user": "******", "text": "@test_bot_name request tag_a1", "channel": "test_channel", "ts": "test_ts" }) api_collector.assert_any_call("chat.postMessage", text=Any(str), channel="test_channel", as_user=True) api_collector.assert_any_call("reactions.add", name="test_reaction", channel="test_channel", timestamp="test_ts")
def test_handle_trigger_message(self, *args): """ The bot should trigger on messages from users containing a trigger word """ bot = GifBot("test.config", MagicMock()) bot.handle_message({ "user": "******", "text": "Something something test_trigger", "channel": "test_channel", "ts": "test_ts" }) api_collector.assert_any_call("chat.postMessage", text=Any(str), channel="test_channel", as_user=True) api_collector.assert_any_call("reactions.add", name="test_reaction", channel="test_channel", timestamp="test_ts")
def test_handle_request_failure(self, *args): """ The bot should send a message and react with :brokenheart: when it cannot fulfill a request """ bot = GifBot("test.config", MagicMock()) bot.handle_message({ "user": "******", "text": "@test_bot_name request invalid_tag", "channel": "test_channel", "ts": "test_ts" }) api_collector.assert_any_call("chat.postMessage", text=Any(str), channel="test_channel", as_user=True) api_collector.assert_any_call("reactions.add", name="broken_heart", channel="test_channel", timestamp="test_ts")
def test_not_trigger_non_message(self, *args): """ The bot should ignore non-messages """ bot = GifBot("test.config", MagicMock()) bot.handle_message({"channel": "test_channel", "ts": "test_ts"}) api_collector.assert_not_called()