aboutsummaryrefslogtreecommitdiffstats
path: root/_pytest/test_eventrouter.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2017-04-12 22:28:27 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-04-12 22:32:17 +0200
commit8c0203ebdc0674e924f711e92c0056244a866f6d (patch)
treecbac1595e9998eff1f002d07372f272cb76c60aa /_pytest/test_eventrouter.py
parent01beb42fec5c6dbfc0d8c53ce1de88b48b48f6db (diff)
parent82f6df320adc0d2b3d6c4d6cd1e949ad427ed29f (diff)
downloadwee-slack-8c0203ebdc0674e924f711e92c0056244a866f6d.tar.gz
Merge remote-tracking branch 'wee-ng/master' into wee-ng-merge
Diffstat (limited to '_pytest/test_eventrouter.py')
-rw-r--r--_pytest/test_eventrouter.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/_pytest/test_eventrouter.py b/_pytest/test_eventrouter.py
new file mode 100644
index 0000000..b235512
--- /dev/null
+++ b/_pytest/test_eventrouter.py
@@ -0,0 +1,86 @@
+import pytest
+from wee_slack import EventRouter, ProcessNotImplemented, SlackRequest
+
+def test_EventRouter(mock_weechat):
+ # Sending valid json adds to the queue.
+ e = EventRouter()
+ e.receive_json('{}')
+ assert len(e.queue) == 1
+
+ # Handling an event removes from the queue.
+ e = EventRouter()
+ # Create a function to test we are called
+ e.proc['testfunc'] = lambda x, y: x
+ e.receive_json('{"type": "testfunc"}')
+ e.handle_next()
+ assert len(e.queue) == 0
+
+ # Handling a local event removes from the queue.
+ e = EventRouter()
+ # Create a function to test we are called
+ e.proc['local_testfunc'] = lambda x, y: x
+ e.receive_json('{"type": "local_testfunc"}')
+ e.handle_next()
+ assert len(e.queue) == 0
+
+ # Handling an event without an associated processor
+ # raises an exception.
+ e = EventRouter()
+ # Create a function to test we are called
+ e.receive_json('{"type": "testfunc"}')
+ with pytest.raises(ProcessNotImplemented):
+ e.handle_next()
+
+def test_EventRouterReceivedata(mock_weechat):
+
+ e = EventRouter()
+ context = e.store_context(SlackRequest('xoxoxoxox', "rtm.startold", {"meh": "blah"}))
+ print context
+ e.receive_httprequest_callback(context, 1, -1, ' {"JSON": "MEH", ', 4)
+ #print len(e.reply_buffer)
+ context = e.store_context(SlackRequest('xoxoxoxox', "rtm.startold", {"meh": "blah"}))
+ print context
+ e.receive_httprequest_callback(context, 1, -1, ' "JSON2": "MEH", ', 4)
+ #print len(e.reply_buffer)
+ context = e.store_context(SlackRequest('xoxoxoxox', "rtm.startold", {"meh": "blah"}))
+ print context
+ e.receive_httprequest_callback(context, 1, 0, ' "JSON3": "MEH"}', 4)
+ #print len(e.reply_buffer)
+ try:
+ e.handle_next()
+ e.handle_next()
+ e.handle_next()
+ e.handle_next()
+ except:
+ pass
+
+ print e.context
+ #assert False
+
+ context = e.store_context(SlackRequest('xoxoxoxox', "rtm.start", {"meh": "blah"}))
+ rtmstartdata = open('_pytest/data/http/rtm.start.json', 'r').read()
+ e.receive_httprequest_callback(context, 1, -1, rtmstartdata[:5000], 4)
+ e.receive_httprequest_callback(context, 1, 0, rtmstartdata[5000:], 4)
+ e.handle_next()
+
+ #print len(e.reply_buffer)
+
+ #print e.teams
+
+ for t in e.teams:
+ #print vars(e.teams[t])
+ for c in e.teams[t].channels:
+ pass
+ #print c
+ for u in e.teams[t].users:
+ pass
+ #print vars(u)
+
+
+# e = EventRouter()
+# # Create a function to test we are called
+# e.receive_json('{"type": "message"}')
+# e.handle_next()
+# assert False
+
+ #assert False