aboutsummaryrefslogtreecommitdiffstats
path: root/_pytest
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2019-04-02 09:58:56 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2019-04-08 15:11:57 +0200
commitb459586d96ec1f765d7aed86538b8d8576977f6c (patch)
tree63488459b22c11b83589b9cfe562f58b4c701b57 /_pytest
parent82147d2d2a47927528e993816ee9393a4aa15b83 (diff)
downloadwee-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')
-rw-r--r--_pytest/conftest.py55
-rw-r--r--_pytest/test_eventrouter.py1
-rw-r--r--_pytest/test_everything.py17
-rw-r--r--_pytest/test_formatting.py4
-rw-r--r--_pytest/test_linkifytext.py60
-rw-r--r--_pytest/test_presencechange.py32
-rw-r--r--_pytest/test_process_message.py58
-rw-r--r--_pytest/test_processreply.py42
-rw-r--r--_pytest/test_processsubteamcreated.py25
-rw-r--r--_pytest/test_processsubteamupdated.py29
-rw-r--r--_pytest/test_processteamjoin.py30
-rw-r--r--_pytest/test_sendmessage.py28
-rw-r--r--_pytest/test_topic_command.py24
-rw-r--r--_pytest/test_unfurl.py6
14 files changed, 157 insertions, 254 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
-
-
diff --git a/_pytest/test_eventrouter.py b/_pytest/test_eventrouter.py
index b22fec5..beb624e 100644
--- a/_pytest/test_eventrouter.py
+++ b/_pytest/test_eventrouter.py
@@ -3,6 +3,7 @@ from __future__ import print_function, unicode_literals
import pytest
from wee_slack import EventRouter, SlackRequest
+
def test_EventRouter(mock_weechat):
# Sending valid object adds to the queue.
e = EventRouter()
diff --git a/_pytest/test_everything.py b/_pytest/test_everything.py
index 5ac4b62..5aa5138 100644
--- a/_pytest/test_everything.py
+++ b/_pytest/test_everything.py
@@ -3,21 +3,14 @@ from __future__ import print_function, unicode_literals
import glob
import json
-def test_everything(realish_eventrouter, mock_websocket):
-
- eventrouter = realish_eventrouter
-
- t = eventrouter.teams.keys()[0]
-
- socket = mock_websocket
- eventrouter.teams[t].ws = socket
+def test_everything(realish_eventrouter, team):
datafiles = glob.glob("_pytest/data/websocket/*.json")
for fname in sorted(datafiles):
data = json.loads(open(fname, 'r').read())
- socket.add(data)
- eventrouter.receive_ws_callback(t)
- eventrouter.handle_next()
+ team.ws.add(data)
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
- assert len(eventrouter.queue) == 14
+ assert len(realish_eventrouter.queue) == 14
diff --git a/_pytest/test_formatting.py b/_pytest/test_formatting.py
index 2f03c6a..74dffba 100644
--- a/_pytest/test_formatting.py
+++ b/_pytest/test_formatting.py
@@ -12,7 +12,7 @@ import wee_slack
""",
"* Run this command: `find . -name '*.exe'`",
])
-def test_does_not_format(text):
+def test_does_not_format(realish_eventrouter, text):
assert wee_slack.render_formatting(text) == text
@@ -25,5 +25,5 @@ def test_does_not_format(text):
"`* * * * *`",
"`* * * * * *`",
])
-def test_preserves_format_chars_in_code(text):
+def test_preserves_format_chars_in_code(realish_eventrouter, text):
assert wee_slack.render_formatting(text) == text
diff --git a/_pytest/test_linkifytext.py b/_pytest/test_linkifytext.py
index a4db120..a31fa6d 100644
--- a/_pytest/test_linkifytext.py
+++ b/_pytest/test_linkifytext.py
@@ -2,79 +2,55 @@
from __future__ import print_function, unicode_literals
-from wee_slack import linkify_text
-
-
-#def test_linkifytext():
-# linkify_text('@ryan')
-
-# assert False
+import re
+from wee_slack import linkify_text
-def test_linkifytext_does_partial_html_entity_encoding(realish_eventrouter):
- team = realish_eventrouter.teams.values()[0]
+def test_linkifytext_does_partial_html_entity_encoding(team):
text = linkify_text('& < > \' "', team)
assert text == '&amp; &lt; &gt; \' "'
-def test_linkifytext_names_with_paranthesis(realish_eventrouter):
- team = realish_eventrouter.teams.values()[0]
-
+def test_linkifytext_names_with_paranthesis(team):
text = linkify_text('@JohnDoe(jdoe): my test message', team)
assert text == '@JohnDoe(jdoe): my test message'
-def test_linkifytext_names_with_accents(realish_eventrouter):
- team = realish_eventrouter.teams.values()[0]
-
+def test_linkifytext_names_with_accents(team):
text = linkify_text('@ÁrvíztűrőTükörfúrógép(atukorfurogep): my test message', team)
assert text == '@ÁrvíztűrőTükörfúrógép(atukorfurogep): my test message'
-def test_linkifytext_formatting_characters(realish_eventrouter):
- team = realish_eventrouter.teams.values()[0]
-
+def test_linkifytext_formatting_characters(team):
text = linkify_text('\x02\x1Dmy test message\x1D\x02', team)
assert text == '*_my test message_*'
-def test_linkifytext_with_many_paranthesis(realish_eventrouter):
- team = realish_eventrouter.teams.values()[0]
-
+def test_linkifytext_with_many_paranthesis(team):
text = linkify_text('@k(o(v)a)())s: my(( test) message', team)
assert text == '@k(o(v)a)())s: my(( test) message'
-def test_linkifytext_names_with_apostrophe(realish_eventrouter):
- team = realish_eventrouter.teams.values()[0]
-
+def test_linkifytext_names_with_apostrophe(team):
text = linkify_text('@O\'Connor: my test message', team)
assert text == '@O\'Connor: my test message'
-def test_linkifytext_names_with_subgroup_notification(realish_eventrouter):
- subteam_id = "TGX0ALBK3"
- handle = "test"
- team = realish_eventrouter.teams.values()[0]
- channel = team.channels.values()[0]
+def test_linkifytext_names_with_subgroup_notification(team):
+ subteam = team.subteams['TGX0ALBK3']
+ message = 'This is a message for a subteam'
+ text = linkify_text('@{}: {}'.format(subteam.handle, message), team)
- message = 'This is a message for the test team'
- text = linkify_text('@test: {}'.format(message), team)
-
- assert text == '<!subteam^{}|@{}>: {}'.format(subteam_id, handle, message)
-
-def test_linkifytext_at_channel(realish_eventrouter):
- team = realish_eventrouter.teams.values()[0]
+ assert text == '<!subteam^{}|@{}>: {}'.format(subteam.identifier, subteam.handle, message)
+def test_linkifytext_at_channel(team):
text = linkify_text('@channel: my test message', team)
assert text == '<!channel>: my test message'
-def test_linkifytext_channel(realish_eventrouter):
- team = realish_eventrouter.teams.values()[0]
- channel = team.channels.values()[0]
-
- text = linkify_text('#{}: my test message'.format(channel.name), team)
+def test_linkifytext_channel(team, channel_general):
+ channel_name = re.sub(r'^[#&]', '', channel_general.name)
+ text = linkify_text('#{}: my test message'.format(channel_name), team)
- assert text == '<#{}|{}>: my test message'.format(channel.id, channel.name)
+ assert text == '<#{}|{}>: my test message'.format(channel_general.id, channel_name)
diff --git a/_pytest/test_presencechange.py b/_pytest/test_presencechange.py
index 71a992b..3dee5c3 100644
--- a/_pytest/test_presencechange.py
+++ b/_pytest/test_presencechange.py
@@ -1,32 +1,22 @@
from __future__ import print_function, unicode_literals
-def test_PresenceChange(realish_eventrouter, mock_websocket):
- e = realish_eventrouter
-
- t = e.teams.keys()[0]
- u = e.teams[t].users.keys()[0]
-
- user = e.teams[t].users[u]
-
- socket = mock_websocket
- e.teams[t].ws = socket
-
- socket.add({
+def test_PresenceChange(realish_eventrouter, team, user_alice):
+ team.ws.add({
"type": "presence_change",
- "user": user.identifier,
+ "user": user_alice.identifier,
"presence": "active",
})
- socket.add({
+ team.ws.add({
"type": "presence_change",
- "user": user.identifier,
+ "user": user_alice.identifier,
"presence": "away",
})
- e.receive_ws_callback(t)
- e.handle_next()
- assert e.teams[t].users[u].presence == "active"
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
+ assert user_alice.presence == "active"
- e.receive_ws_callback(t)
- e.handle_next()
- assert e.teams[t].users[u].presence == "away"
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
+ assert user_alice.presence == "away"
diff --git a/_pytest/test_process_message.py b/_pytest/test_process_message.py
index 4dc24e5..6209cdf 100644
--- a/_pytest/test_process_message.py
+++ b/_pytest/test_process_message.py
@@ -2,49 +2,55 @@ from __future__ import print_function, unicode_literals
import json
-from wee_slack import render
+from wee_slack import render, SlackTS
-def test_process_message(realish_eventrouter, mock_websocket):
-
- e = realish_eventrouter
-
- t = e.teams.keys()[0]
- u = e.teams[t].users.keys()[0]
-
- user = e.teams[t].users[u]
- #print(user)
-
- socket = mock_websocket
- e.teams[t].ws = socket
+def test_process_message(realish_eventrouter, team, user_alice):
messages = []
messages.append(json.loads(open('_pytest/data/websocket/1485975421.33-message.json', 'r').read()))
# test message and then change
- messages.append(json.loads(open('_pytest/data/websocket/1485976157.18-message.json', 'r').read()))
messages.append(json.loads(open('_pytest/data/websocket/1485976151.6-message.json', 'r').read()))
+ messages.append(json.loads(open('_pytest/data/websocket/1485976157.18-message.json', 'r').read()))
# test message then deletion
messages.append(json.loads(open('_pytest/data/websocket/1485975698.45-message.json', 'r').read()))
messages.append(json.loads(open('_pytest/data/websocket/1485975723.85-message.json', 'r').read()))
for m in messages:
- m["user"] = user.id
- socket.add(m)
+ m["user"] = user_alice.id
+ team.ws.add(m)
+
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
+
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
- e.receive_ws_callback(t)
- e.handle_next()
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
- e.receive_ws_callback(t)
- e.handle_next()
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
- e.receive_ws_callback(t)
- e.handle_next()
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
- e.receive_ws_callback(t)
- e.handle_next()
+ assert sum([len(channel.messages) for channel in team.channels.values()]) == 3
+ unchanged_message_channel = team.channels['D3ZEQULHZ']
+ unchanged_message_ts = SlackTS('1485975421.000002')
+ assert list(unchanged_message_channel.messages.keys()) == [unchanged_message_ts]
+ assert unchanged_message_channel.messages[unchanged_message_ts].message_json['text'] == 'hi bob'
+ assert 'edited' not in unchanged_message_channel.messages[unchanged_message_ts].message_json
- #assert e.teams[t].channels['C407ABS94'].messages.keys()[0] == '1485976151.00016'
- #assert False
+ changed_message_channel = team.channels['C407ABS94']
+ changed_message_ts = SlackTS('1485976151.000016')
+ assert list(changed_message_channel.messages.keys()) == [changed_message_ts]
+ assert changed_message_channel.messages[changed_message_ts].message_json['text'] == 'referencing a <#C407ABS94|general>'
+ assert 'edited' in changed_message_channel.messages[changed_message_ts].message_json
+ deleted_message_channel = team.channels['G3ZGMF4RZ']
+ deleted_message_ts = SlackTS('1485975698.000002')
+ assert list(deleted_message_channel.messages.keys()) == [deleted_message_ts]
+ assert deleted_message_channel.messages[deleted_message_ts].message_json['text'] == '(deleted)'
diff --git a/_pytest/test_processreply.py b/_pytest/test_processreply.py
index 2cf71ec..8b95e11 100644
--- a/_pytest/test_processreply.py
+++ b/_pytest/test_processreply.py
@@ -1,35 +1,17 @@
from __future__ import print_function, unicode_literals
-#from wee_slack import process_reply
+from wee_slack import SlackTS
-def test_process_reply(realish_eventrouter, mock_websocket):
- e = realish_eventrouter
+def test_process_reply(realish_eventrouter, team, channel_general):
+ message_ts = SlackTS('12341234.123456')
+ message_text = 'reply test'
+ channel_general.send_message(message_text)
+ team.ws.add({'reply_to': 1, '_team': team.team_hash, 'ts': str(message_ts)})
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
- t = e.teams.keys()[0]
- #u = e.teams[t].users.keys()[0]
-
- #user = e.teams[t].users[u]
- #print(user)
-
- socket = mock_websocket
- e.teams[t].ws = socket
-
- c = e.teams[t].channels.keys()[0]
- channel = e.teams[t].channels[c]
- channel.send_message('asdf')
-
- socket = mock_websocket
- socket.add({"reply_to": 1, "_team": t, "ts": "12341234.111"})
-
- print(e.teams[t].ws_replies)
-
- e.receive_ws_callback(t)
- e.handle_next()
-
- #reply = {"reply_to": 1, "_team": t, "ts": "12341234.111"}
- #print(reply)
- #process_reply(reply, e)
- #print(e.teams[t].ws_replies)
- #assert False
- pass
+ assert message_ts in channel_general.messages
+ message_json = channel_general.messages[message_ts].message_json
+ assert message_json['ts'] == message_ts
+ assert message_json['text'] == message_text
diff --git a/_pytest/test_processsubteamcreated.py b/_pytest/test_processsubteamcreated.py
index 9cc9201..6c2bb35 100644
--- a/_pytest/test_processsubteamcreated.py
+++ b/_pytest/test_processsubteamcreated.py
@@ -1,24 +1,15 @@
from __future__ import print_function, unicode_literals
-import glob
import json
-def test_process_subteam_created(mock_websocket, realish_eventrouter):
- eventrouter = realish_eventrouter
+def test_process_subteam_created(realish_eventrouter, team):
+ assert len(team.subteams) == 1
- t = eventrouter.teams.keys()[0]
+ datafile = '_pytest/data/websocket/1483975206.59-subteam_created.json'
+ data = json.loads(open(datafile, 'r').read())
+ team.ws.add(data)
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
- assert len(eventrouter.teams[t].subteams) == 1
-
- socket = mock_websocket
- eventrouter.teams[t].ws = socket
- datafiles = glob.glob("_pytest/data/websocket/1483975206.59-subteam_created.json")
-
- for fname in datafiles:
- data = json.loads(open(fname, 'r').read())
- socket.add(data)
- eventrouter.receive_ws_callback(t)
- eventrouter.handle_next()
-
- assert len(eventrouter.teams[t].subteams) == 2
+ assert len(team.subteams) == 2
diff --git a/_pytest/test_processsubteamupdated.py b/_pytest/test_processsubteamupdated.py
index 5781240..0a98aaa 100644
--- a/_pytest/test_processsubteamupdated.py
+++ b/_pytest/test_processsubteamupdated.py
@@ -1,31 +1,18 @@
from __future__ import print_function, unicode_literals
-import glob
-from mock import patch, call
-from wee_slack import SlackTeam, SlackSubteam
import json
-def test_process_subteam_self_updated(mock_websocket, realish_eventrouter):
- eventrouter = realish_eventrouter
+def test_process_subteam_self_updated(realish_eventrouter, team):
+ assert len(team.subteams) == 1
- t = eventrouter.teams.keys()[0]
-
- assert len(eventrouter.teams[t].subteams) == 1
-
- socket = mock_websocket
- eventrouter.teams[t].ws = socket
- datafiles = glob.glob("_pytest/data/websocket/1483975206.59-subteam_updated.json")
-
- for fname in datafiles:
- data = json.loads(open(fname, 'r').read())
- socket.add(data)
- eventrouter.receive_ws_callback(t)
- eventrouter.handle_next()
- team = eventrouter.teams[t]
- subteam = team.subteams.values()[0]
+ datafile = '_pytest/data/websocket/1483975206.59-subteam_updated.json'
+ data = json.loads(open(datafile, 'r').read())
+ team.ws.add(data)
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
+ subteam = team.subteams['TGX0ALBK3']
assert data['subteam']['handle'] == subteam.handle
assert data['subteam']['description'] == subteam.description
assert data['subteam']['name'] == subteam.name
-
diff --git a/_pytest/test_processteamjoin.py b/_pytest/test_processteamjoin.py
index 64e704a..8e83458 100644
--- a/_pytest/test_processteamjoin.py
+++ b/_pytest/test_processteamjoin.py
@@ -1,28 +1,18 @@
from __future__ import print_function, unicode_literals
-import glob
import json
-def test_process_team_join(mock_websocket, realish_eventrouter):
- eventrouter = realish_eventrouter
+def test_process_team_join(realish_eventrouter, team):
+ # delete charles so we can add him
+ del team.users['U4096CBHC']
- t = eventrouter.teams.keys()[0]
+ assert len(team.users) == 3
- #delete charles so we can add him
- del eventrouter.teams[t].users['U4096CBHC']
+ datafile = '_pytest/data/websocket/1485975606.59-team_join.json'
+ data = json.loads(open(datafile, 'r').read())
+ team.ws.add(data)
+ realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.handle_next()
- assert len(eventrouter.teams[t].users) == 3
-
- socket = mock_websocket
- eventrouter.teams[t].ws = socket
-
- datafiles = glob.glob("_pytest/data/websocket/1485975606.59-team_join.json")
-
- for fname in datafiles:
- data = json.loads(open(fname, 'r').read())
- socket.add(data)
- eventrouter.receive_ws_callback(t)
- eventrouter.handle_next()
-
- assert len(eventrouter.teams[t].users) == 4
+ assert len(team.users) == 4
diff --git a/_pytest/test_sendmessage.py b/_pytest/test_sendmessage.py
index 9446e07..17f38d7 100644
--- a/_pytest/test_sendmessage.py
+++ b/_pytest/test_sendmessage.py
@@ -1,22 +1,18 @@
from __future__ import print_function, unicode_literals
-def test_send_message(realish_eventrouter, mock_websocket):
- e = realish_eventrouter
+import json
- t = e.teams.keys()[0]
- #u = e.teams[t].users.keys()[0]
- #user = e.teams[t].users[u]
- #print(user)
+def test_send_message(realish_eventrouter, team, channel_general):
+ message_text = 'send message test'
+ channel_general.send_message(message_text)
- socket = mock_websocket
- e.teams[t].ws = socket
+ sent = json.loads(team.ws.sentdata[0])
- c = e.teams[t].channels.keys()[0]
-
- channel = e.teams[t].channels[c]
- channel.send_message('asdf')
-
- print(c)
-
- #assert False
+ assert sent == {
+ 'text': message_text,
+ 'type': 'message',
+ 'user': team.myidentifier,
+ 'channel': channel_general.id,
+ 'id': 1,
+ }
diff --git a/_pytest/test_topic_command.py b/_pytest/test_topic_command.py
index c8dc8a3..c632148 100644
--- a/_pytest/test_topic_command.py
+++ b/_pytest/test_topic_command.py
@@ -48,10 +48,8 @@ def test_parse_topic_with_channel_and_delete():
assert topic == ''
-def test_call_topic_without_arguments(realish_eventrouter):
- team = realish_eventrouter.teams.values()[-1]
- channel = team.channels.values()[-1]
- current_buffer = channel.channel_buffer
+def test_call_topic_without_arguments(realish_eventrouter, channel_general):
+ current_buffer = channel_general.channel_buffer
wee_slack.EVENTROUTER = realish_eventrouter
command = '/topic'
@@ -59,16 +57,14 @@ def test_call_topic_without_arguments(realish_eventrouter):
with patch('wee_slack.w.prnt') as fake_prnt:
result = topic_command_cb(None, current_buffer, command)
fake_prnt.assert_called_with(
- channel.channel_buffer,
- 'Topic for {} is "{}"'.format(channel.name, channel.topic),
+ channel_general.channel_buffer,
+ 'Topic for {} is "{}"'.format(channel_general.name, channel_general.topic),
)
assert result == wee_slack.w.WEECHAT_RC_OK_EAT
-def test_call_topic_with_unknown_channel(realish_eventrouter):
- team = realish_eventrouter.teams.values()[-1]
- channel = team.channels.values()[-1]
- current_buffer = channel.channel_buffer
+def test_call_topic_with_unknown_channel(realish_eventrouter, team, channel_general):
+ current_buffer = channel_general.channel_buffer
wee_slack.EVENTROUTER = realish_eventrouter
command = '/topic #nonexisting'
@@ -82,10 +78,8 @@ def test_call_topic_with_unknown_channel(realish_eventrouter):
assert result == wee_slack.w.WEECHAT_RC_OK_EAT
-def test_call_topic_with_channel_and_string(realish_eventrouter):
- team = realish_eventrouter.teams.values()[-1]
- channel = team.channels.values()[-1]
- current_buffer = channel.channel_buffer
+def test_call_topic_with_channel_and_string(realish_eventrouter, channel_general):
+ current_buffer = channel_general.channel_buffer
wee_slack.EVENTROUTER = realish_eventrouter
command = '/topic #general new topic'
@@ -94,5 +88,5 @@ def test_call_topic_with_channel_and_string(realish_eventrouter):
request = realish_eventrouter.queue[-1]
assert request.request == 'channels.setTopic'
assert request.post_data == {
- 'channel': 'C407ABS94', 'token': 'xoxoxoxox', 'topic': 'new topic'}
+ 'channel': 'C407ABS94', 'token': 'xoxs-token', 'topic': 'new topic'}
assert result == wee_slack.w.WEECHAT_RC_OK_EAT
diff --git a/_pytest/test_unfurl.py b/_pytest/test_unfurl.py
index c73abaa..17fdc79 100644
--- a/_pytest/test_unfurl.py
+++ b/_pytest/test_unfurl.py
@@ -3,8 +3,6 @@ from __future__ import print_function, unicode_literals
import wee_slack
import pytest
-slack = wee_slack
-
@pytest.mark.parametrize('case', (
{
@@ -70,9 +68,9 @@ slack = wee_slack
}
))
def test_unfurl_refs(case, realish_eventrouter):
- slack.EVENTROUTER = realish_eventrouter
+ wee_slack.EVENTROUTER = realish_eventrouter
- result = slack.unfurl_refs(
+ result = wee_slack.unfurl_refs(
case['input'],
ignore_alt_text=case.get('ignore_alt_text', False),
auto_link_display=case.get('auto_link_display', 'both'),