aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--_pytest/conftest.py104
-rw-r--r--_pytest/data/message-changed.json19
-rw-r--r--_pytest/data/message-deleted.json9
-rw-r--r--_pytest/data/message-normal.json8
-rw-r--r--_pytest/data/message-normal2.json8
-rw-r--r--_pytest/test_process_message.py40
6 files changed, 188 insertions, 0 deletions
diff --git a/_pytest/conftest.py b/_pytest/conftest.py
new file mode 100644
index 0000000..0cbceb9
--- /dev/null
+++ b/_pytest/conftest.py
@@ -0,0 +1,104 @@
+import pytest
+from wee_slack import SlackServer
+from wee_slack import Channel
+from wee_slack import User
+from wee_slack import SearchList
+import wee_slack
+
+class FakeWeechat():
+ """
+ this is the thing that acts as "w." everywhere..
+ basically mock out all of the weechat calls here i guess
+ """
+ WEECHAT_RC_OK = True
+
+ def __init__(self):
+ print "INITIALIZE FAKE WEECHAT"
+ def prnt(*args):
+ output = "("
+ for arg in args:
+ if arg != None:
+ output += "{}, ".format(arg)
+ print "w.prnt {}".format(output)
+ def hdata_get(*args):
+ return "0x000001"
+ def hdata_pointer(*args):
+ return "0x000002"
+ def hdata_time(*args):
+ return "1355517519"
+ def hdata_string(*args):
+ return "testuser"
+
+ def __getattr__(self, name):
+ def method(*args):
+ print "called {}".format(name)
+ if args:
+ print "\twith args: {}".format(args)
+ return method
+
+@pytest.fixture
+def fake_weechat():
+ wee_slack.w = FakeWeechat()
+ pass
+
+
+@pytest.fixture
+def slack_debug():
+ wee_slack.slack_debug = "debug_buffer_ptr"
+
+@pytest.fixture
+def server(fake_weechat, monkeypatch):
+#def server(monkeypatch, mychannels, myusers):
+ def mock_connect_to_slack(*args):
+ return True
+ monkeypatch.setattr(SlackServer, 'connect_to_slack', mock_connect_to_slack)
+ myserver = SlackServer('xoxo-12345')
+ myserver.identifier = 'test.slack.com'
+ myserver.nick = 'myusername'
+ return myserver
+
+@pytest.fixture
+def myservers(server):
+ servers = SearchList()
+ servers.append(server)
+ return servers
+
+
+
+@pytest.fixture
+def channel(monkeypatch, server):
+ def mock_buffer_prnt(*args):
+ print "called buffer_prnt\n\twith args: {}".format(args)
+ return
+ def mock_do_nothing(*args):
+ print args
+ return True
+ monkeypatch.setattr(Channel, 'create_buffer', mock_do_nothing)
+ monkeypatch.setattr(Channel, 'attach_buffer', mock_do_nothing)
+ monkeypatch.setattr(Channel, 'set_topic', mock_do_nothing)
+ monkeypatch.setattr(Channel, 'set_topic', mock_do_nothing)
+ monkeypatch.setattr(Channel, 'buffer_prnt', mock_buffer_prnt)
+ mychannel = Channel(server, '#testchan', 'C2147483705', True, last_read=0, prepend_name="", members=[], topic="")
+ return mychannel
+
+@pytest.fixture
+def mychannels(channel):
+ channels = SearchList()
+ channels.append(channel)
+ return channels
+
+@pytest.fixture
+def user(monkeypatch, server):
+ wee_slack.domain = None
+ wee_slack.colorize_nicks = True
+ pass
+ myuser = User(server, "testuser", 'U2147483697', presence="away")
+ myuser.color = ''
+ return myuser
+
+@pytest.fixture
+def myusers(monkeypatch, user):
+ users = SearchList()
+ users.append(user)
+ return users
+
diff --git a/_pytest/data/message-changed.json b/_pytest/data/message-changed.json
new file mode 100644
index 0000000..5a229dc
--- /dev/null
+++ b/_pytest/data/message-changed.json
@@ -0,0 +1,19 @@
+{
+ "type": "message",
+ "subtype": "message_changed",
+ "hidden": true,
+ "channel": "C2147483705",
+ "ts": "1355517529.000005",
+ "message": {
+ "type": "message",
+ "user": "U2147483697",
+ "text": "Hello world",
+ "ts": "1355517519.000005",
+ "edited": {
+ "user": "U2147483697",
+ "ts": "12341234"
+ }
+ },
+
+ "myserver": "test.slack.com"
+}
diff --git a/_pytest/data/message-deleted.json b/_pytest/data/message-deleted.json
new file mode 100644
index 0000000..91190b3
--- /dev/null
+++ b/_pytest/data/message-deleted.json
@@ -0,0 +1,9 @@
+{
+ "type": "message",
+ "subtype": "message_deleted",
+ "hidden": true,
+ "channel": "C2147483705",
+ "ts": "1358878755.000001",
+ "deleted_ts": "1355517519.000005",
+ "myserver": "test.slack.com"
+}
diff --git a/_pytest/data/message-normal.json b/_pytest/data/message-normal.json
new file mode 100644
index 0000000..f3dc568
--- /dev/null
+++ b/_pytest/data/message-normal.json
@@ -0,0 +1,8 @@
+{
+ "type": "message",
+ "channel": "C2147483705",
+ "user": "U2147483697",
+ "text": "Hello world",
+ "ts": "1355517523.000005",
+ "myserver": "test.slack.com"
+}
diff --git a/_pytest/data/message-normal2.json b/_pytest/data/message-normal2.json
new file mode 100644
index 0000000..b67be66
--- /dev/null
+++ b/_pytest/data/message-normal2.json
@@ -0,0 +1,8 @@
+{
+ "type": "message",
+ "channel": "C2147483705",
+ "user": "U2147483697",
+ "text": "A Second message!",
+ "ts": "1355517524.000005",
+ "myserver": "test.slack.com"
+}
diff --git a/_pytest/test_process_message.py b/_pytest/test_process_message.py
new file mode 100644
index 0000000..6c58336
--- /dev/null
+++ b/_pytest/test_process_message.py
@@ -0,0 +1,40 @@
+
+import wee_slack
+import pytest
+import json
+from collections import defaultdict
+
+
+def test_process_message(slack_debug, monkeypatch, myservers, mychannels, myusers):
+ called = defaultdict(int)
+ wee_slack.servers = myservers
+ wee_slack.channels = mychannels
+ wee_slack.users = myusers
+ wee_slack.message_cache = {}
+ wee_slack.servers[0].users = myusers
+
+ def mock_buffer_prnt(*args):
+ called['buffer_prnt'] += 1
+ monkeypatch.setattr(wee_slack.Channel, 'buffer_prnt', mock_buffer_prnt)
+
+# def mock_buffer_prnt_changed(*args):
+# called['buffer_prnt_changed'] += 1
+# print args
+# monkeypatch.setattr(wee_slack.Channel, 'buffer_prnt_changed', mock_buffer_prnt_changed)
+
+
+ messages = []
+ messages.append( json.loads(open('_pytest/data/message-normal.json', 'r').read()) )
+ messages.append( json.loads(open('_pytest/data/message-normal2.json', 'r').read()) )
+ messages.append( json.loads(open('_pytest/data/message-changed.json', 'r').read()) )
+ messages.append( json.loads(open('_pytest/data/message-deleted.json', 'r').read()) )
+ for m in messages:
+ wee_slack.process_message(m)
+ print called
+# assert called['buffer_prnt'] == 2
+# assert called['buffer_prnt_changed'] == 1
+
+
+
+
+