diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-04-02 09:58:56 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-04-08 15:11:57 +0200 |
commit | b459586d96ec1f765d7aed86538b8d8576977f6c (patch) | |
tree | 63488459b22c11b83589b9cfe562f58b4c701b57 /_pytest/conftest.py | |
parent | 82147d2d2a47927528e993816ee9393a4aa15b83 (diff) | |
download | wee-slack-b459586d96ec1f765d7aed86538b8d8576977f6c.tar.gz |
Cleanup tests and make them compatible with python 3
This mainly adds team, channel_general and user_alice as fixtures, so we
can use those directly instead of picking arbitrary ones from the lists.
It also adds assertions to some tests which where missing it.
Diffstat (limited to '_pytest/conftest.py')
-rw-r--r-- | _pytest/conftest.py | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/_pytest/conftest.py b/_pytest/conftest.py index 8b24559..1af03c7 100644 --- a/_pytest/conftest.py +++ b/_pytest/conftest.py @@ -2,51 +2,57 @@ from __future__ import print_function, unicode_literals import json import pytest +import random +import string import sys sys.path.append(".") -#New stuff -from wee_slack import EventRouter -from wee_slack import SlackRequest import wee_slack +from wee_slack import EventRouter, SlackRequest class fakewebsocket(object): def __init__(self): self.returndata = [] - pass + self.sentdata = [] 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 + self.sentdata.append(data) @pytest.fixture def mock_websocket(): return fakewebsocket() @pytest.fixture -def realish_eventrouter(mock_weechat): +def realish_eventrouter(mock_websocket, mock_weechat): e = EventRouter() - context = e.store_context(SlackRequest('xoxoxoxox', "rtm.start", {"meh": "blah"})) - rtmstartdata = open('_pytest/data/http/rtm.start.json', 'r').read() - if sys.version_info.major == 2: - rtmstartdata = rtmstartdata.decode('utf-8') - e.receive_httprequest_callback(context, 1, 0, rtmstartdata, 4) + context = e.store_context(SlackRequest('xoxs-token', 'rtm.start', {})) + with open('_pytest/data/http/rtm.start.json') as rtmstartfile: + if sys.version_info.major == 2: + rtmstartdata = rtmstartfile.read().decode('utf-8') + else: + rtmstartdata = rtmstartfile.read() + e.receive_httprequest_callback(context, '', 0, rtmstartdata, '') 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 - + for team in e.teams.values(): + team.ws = mock_websocket return e +@pytest.fixture +def team(realish_eventrouter): + return next(iter(realish_eventrouter.teams.values())) + +@pytest.fixture +def channel_general(team): + return team.channels[team.get_channel_map()['general']] + +@pytest.fixture +def user_alice(team): + return team.users[team.get_username_map()['alice']] class FakeWeechat(): """ @@ -58,7 +64,6 @@ class FakeWeechat(): WEECHAT_RC_OK_EAT = 2 def __init__(self): self.config = {} - #print("INITIALIZE FAKE WEECHAT") def prnt(*args): output = "(" for arg in args: @@ -74,7 +79,7 @@ class FakeWeechat(): def hdata_string(*args): return "testuser" def buffer_new(*args): - return "0x8a8a8a8b" + return "0x" + "".join(random.choice(string.digits) for _ in range(8)) def prefix(self, type): return "" def config_get_plugin(self, key): @@ -90,9 +95,6 @@ class FakeWeechat(): def __getattr__(self, name): def method(*args): pass - #print("called {}".format(name)) - #if args: - # print("\twith args: {}".format(args)) return method @pytest.fixture @@ -105,6 +107,3 @@ def mock_weechat(): wee_slack.STOP_TALKING_TO_SLACK = False wee_slack.proc = {} wee_slack.weechat_version = 0x10500000 - pass - - |