def test_image(): server = limbo.FakeServer() with vcr.use_cassette('test/fixtures/image_bananas.yaml'): on_message(msgobj(u"!image bananas"), server) url = json.loads(server.slack.posted_messages[0][1]["attachments"])[0]['image_url'] assert url in bananas_images, "{0} not in {1}".format(url, bananas_images)
def test_handle_member_left(): event = {"type": "member_left_channel", "user": "******"} hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(hooks=hooks) assert limbo.handle_event(event, server) == "user 2 left"
def test_loop_hook(): hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(hooks=hooks) slack = limbo.FakeSlack() limbo.loop(server, test_loop=1) assert server._loop_plugin_ran == True
def test_handle_message_basic(): msg = u"!echo Iñtërnâtiônàlizætiøn" event = {"user": "******", "text": msg} hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(hooks=hooks) eq_(limbo.handle_message(event, server), msg)
def test_handle_bot_message(): msg = u"!echo Iñtërnâtiônàlizætiøn bot" event = {"bot_id": "2", "text": msg, "subtype": "bot_message"} hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(hooks=hooks) assert limbo.handle_message(event, server) == msg
def test_basic(): server = limbo.FakeServer() with vcr.use_cassette('test/fixtures/weather_basic.yaml'): on_message(msgobj(u"!weather Oahu, HI"), server) attachment = json.loads( server.slack.posted_messages[0][1]['attachments'])[0] assert "Weather for Honolulu, HI" in attachment['pretext'] assert attachment['fields'][0]['value'] == u':sun_small_cloud: 73°f'
def test_loop_hook(): hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(hooks=hooks) slack = limbo.FakeSlack() metrics = limbo.NullMetrics() limbo.loop(server, metrics, test_loop=1) assert server._loop_plugin_ran == True assert metrics.count == 0
def test_handle_message_slack_user_nil(): msg = u"!echo Iñtërnâtiônàlizætiøn" event = {"user": "******", "text": msg} users = {"0": User("nobody", 0, "", 0)} hooks = limbo.init_plugins("test/plugins") slack = limbo.FakeSlack(users=users) server = limbo.FakeServer(slack=slack, hooks=hooks) assert limbo.handle_message(event, server) == u"!echo Iñtërnâtiônàlizætiøn"
def test_handle_message_handles_mention(): msg = u"!echo Iñtërnâtiônàlizætiøn <@1>" event = {"user": "******", "text": msg} config = {"needmention": "true"} slack = limbo.FakeSlack() hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(config=config, slack=slack, hooks=hooks) assert limbo.handle_message(event, server) == msg
def test_handle_message_ignores_wrongmention(): msg = u"!echo Iñtërnâtiônàlizætiøn bot <@3>" event = {"bot_id": "2", "text": msg, "subtype": "bot_message"} config = {"needmention": "true"} slack = limbo.FakeSlack() hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(config=config, slack=slack, hooks=hooks) assert limbo.handle_message(event, server) == None
def test_basic(): from weather import on_message server = limbo.FakeServer() with vcr.use_cassette("test/fixtures/weather_basic.yaml"): on_message(msgobj(u"!weather Oahu, HI"), server) attachment = json.loads( server.slack.posted_messages[0][1]["attachments"])[0] assert "Weather for Oahu" in attachment["pretext"] assert attachment["fields"][0]["value"] == u":rain_cloud: 75°f"
def test_handle_message_slack_user_nil(): msg = u"!echo Iñtërnâtiônàlizætiøn" event = {"user": "******", "text": msg} users = SearchList([User(None, "nobody", 0, "", 0)]) hooks = limbo.init_plugins("test/plugins") slack = limbo.FakeSlack(users=users) server = limbo.FakeServer(slack=slack, hooks=hooks) eq_(limbo.handle_message(event, server), None)
def test_handle_delete_message(): oldmsg = u"!echo old message" event = {"type": "message", "subtype": "message_deleted", "previous_message": {"text": oldmsg, "user": "******"}} hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(hooks=hooks) assert limbo.handle_message(event, server) == "Deleted: {}".format(oldmsg)
def test_units(monkeypatch): from weather import on_message monkeypatch.setenv("WEATHER_CELSIUS", "yes") server = limbo.FakeServer() #todo record a fixture with correct content for celcius with vcr.use_cassette("test/fixtures/weather_celsius.yaml"): on_message(msgobj(u"!weather Oahu, HI"), server) attachment = json.loads( server.slack.posted_messages[0][1]["attachments"])[0] assert "Weather for Oahu" in attachment["pretext"] assert attachment["fields"][0]["value"] == u":rain_cloud: 75°c"
def test_handle_channel_join(): event = { "user": "******", "type": "message", "subtype": "channel_join", "text": "User has joined" } hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(hooks=hooks) assert limbo.handle_message(event, server) == "saw user 2 join"
def test_handle_edit_message(): oldmsg = u"old message" newmsg = u"!echo new message" event = {"type": "message", "subtype": "message_changed", "previous_message": {"text": oldmsg}, "message": {"text": newmsg, "user": "******"}} hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(hooks=hooks) assert limbo.handle_message(event, server) == "Changed: {}".format(newmsg)
def test_event_count(): msg = u"!echo Iñtërnâtiônàlizætiøn bot" oldmsg = u"old message" newmsg = u"!echo new message" events = [[{ "channel": "none", "user": "******", "text": msg }, { "channel": "none", "user": "******", "type": "message", "subtype": "channel_join", "text": "User has joined" }, { "channel": "none", "user": "******", "type": "member_left_channel" }, { "channel": "none", "type": "message", "subtype": "message_changed", "previous_message": { "text": oldmsg }, "message": { "text": newmsg, "user": "******" } }]] slack = limbo.FakeSlack(events=events) hooks = limbo.init_plugins("test/plugins") server = limbo.FakeServer(hooks=hooks, slack=slack) metrics = limbo.NullMetrics() limbo.loop(server, metrics, test_loop=1) assert metrics.count == 4
def test_extended_not_there(): hooks = {"extendedhelp": {"test": "!test help system\nline 2"}} server = limbo.FakeServer(hooks=hooks) ret = on_message({"text": u"!help not_there"}, server) eq_(ret, 'No help found for not_there')
def test_extended(): hooks = {"extendedhelp": {"test": "!test help system\nline 2"}} server = limbo.FakeServer(hooks=hooks) ret = on_message({"text": u"!help test"}, server) eq_(ret, hooks["extendedhelp"]["test"])
def test_nonexistent(): hooks = {} server = limbo.FakeServer(hooks=hooks) ret = on_message({"text": u"!help"}, server) eq_(ret, '')
def test_basic(): hooks = {"help": {"test": "!test help system"}} server = limbo.FakeServer(hooks=hooks) ret = on_message({"text": u"!help"}, server) eq_(ret, hooks["help"]["test"])
def test_handle_message_ignores_slackbot(): server = limbo.FakeServer() event = {"user": "******"} eq_(limbo.handle_message(event, server), None)
def test_handle_message_ignores_self(): server = limbo.FakeServer() event = {"user": "******"} eq_(limbo.handle_message(event, server), None)
def test_handle_message_subtype(): server = limbo.FakeServer() eq_(limbo.handle_message({"subtype": "bot_message"}, server), None) eq_(limbo.handle_message({"subtype": "message_changed"}, server), None)
def test_unicode(): from weather import on_message server = limbo.FakeServer() with vcr.use_cassette("test/fixtures/weather_unicode.yaml"): on_message(msgobj(u"!weather กรุงเทพมหานคร"), server)
def test_unicode(): server = limbo.FakeServer() with vcr.use_cassette('test/fixtures/image_unicode.yaml'): on_message(msgobj(u"!image Mötörhead"), server)
def test_handle_message_ignores_slackbot(): server = limbo.FakeServer() event = {"user": "******"} assert limbo.handle_message(event, server) == None
def test_handle_message_ignores_self(): server = limbo.FakeServer() event = {"user": "******", "type": "message", "id": "1"} assert limbo.handle_message(event, server) == None
def test_handle_message_subtype(): msg = u"!echo Iñtërnâtiônàlizætiøn" server = limbo.FakeServer() event = {"bot_id": "1", "text": msg} event["subtype"] = "message_changed" assert limbo.handle_message(event, server) == None