def test_is_mention(self, *args): """ The bot should be able to identify direct mentions """ bot = GifBot("test.config", MagicMock()) self.assertTrue(bot.is_mention("@test_bot_name")) self.assertTrue(bot.is_mention("@test_bot_name help")) self.assertFalse(bot.is_mention("Something @test_bot_name"))
def test_is_trigger(self, *args): """ The bot should be able to identify trigger words being used in messages """ bot = GifBot("test.config", MagicMock()) self.assertTrue(bot.is_trigger("test_trigger blah")) self.assertTrue(bot.is_trigger("blah test_trigger")) self.assertFalse(bot.is_trigger("something else"))
def _main(): try: bot = GifBot(config_filename="bot.config", log_filename="wbb.log") except Exception as e: print("[ERROR] Unable to initialise the bot") print("[ERROR] {}".format(e)) return bot.run()
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_admin_access(self, *args): """ Test that basic admin commands work only for the owner """ 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.assertNotIn("tag", bot.store.tags) self.assertEqual(len(bot.store.elements), 2)
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()