1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
import pytest
import sys
sys.path.append(".")
#sys.path.append(str(pytest.config.rootdir))
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
|