aboutsummaryrefslogtreecommitdiffstats
path: root/_pytest/conftest.py
blob: 74ed53794ca445cac2346e6407f6f75e1bdc25e8 (plain) (blame)
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
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(mock_weechat):
    e = EventRouter()
    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, 0, rtmstartdata, 4)
    while len(e.queue):
        e.handle_next()
    #e.sc is just shortcuts to these items
    e.sc = {}
    e.sc["team_id"] = e.teams.keys()[0]
    e.sc["team"] = e.teams[e.sc["team_id"]]
    e.sc["user"] = e.teams[e.sc["team_id"]].users[e.teams[e.sc["team_id"]].users.keys()[0]]
    socket = mock_websocket
    e.teams[e.sc["team_id"]].ws = socket

    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_ERROR = 0
    WEECHAT_RC_OK = 1
    WEECHAT_RC_OK_EAT = 2

    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 prefix(self, type):
        return ""
    def config_get_plugin(self, key):
        return ""
    def config_get(self, key):
        return ""
    def config_string(self, key):
        return ""
    def color(self, name):
        return ""
    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 = {}
    wee_slack.weechat_version = 0x10500000
    pass