import pickle import json import pytest import sys sys.path.append(".") #New stuff from wee_slack import EventRouter from wee_slack import SlackRequest import wee_slack class fakewebsocket(object): def __init__(self): self.returndata = [] pass def add(self, data): self.returndata.append(data) def recv(self): return json.dumps(self.returndata.pop(0)) def send(self, data): print "websocket received: {}".format(data) return @pytest.fixture def mock_websocket(): return fakewebsocket() @pytest.fixture def realish_eventrouter(): e = EventRouter() pickled_data = pickle.dumps(SlackRequest('xoxoxoxox', "rtm.start", {"meh": "blah"})) rtmstartdata = open('_pytest/data/http/rtm.start.json', 'r').read() e.receive_httprequest_callback(pickled_data, 1, 0, rtmstartdata, 4) e.handle_next() return e 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): pass #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 buffer_new(*args): return "0x8a8a8a8b" def __getattr__(self, name): def method(*args): pass #print "called {}".format(name) #if args: # print "\twith args: {}".format(args) return method @pytest.fixture def mock_weechat(): wee_slack.w = FakeWeechat() wee_slack.config = wee_slack.PluginConfig() wee_slack.debug_string = None wee_slack.slack_debug = "debug_buffer_ptr" wee_slack.STOP_TALKING_TO_SLACK = False wee_slack.proc = {} pass