aboutsummaryrefslogtreecommitdiffstats
path: root/_pytest/test_process_message.py
blob: 225b971aae5a89cdd6288cdfe044c43f3d00d5e3 (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
from __future__ import print_function, unicode_literals

import json

from wee_slack import render, SlackTS


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/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_alice.id
        team.ws.add(m)

    realish_eventrouter.receive_ws_callback(team.team_hash)
    realish_eventrouter.handle_next()
    realish_eventrouter.handle_next()
    realish_eventrouter.handle_next()
    realish_eventrouter.handle_next()
    realish_eventrouter.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

    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)'