aboutsummaryrefslogtreecommitdiffstats
path: root/_pytest/test_unfurl.py
blob: e8043a83ec749f9f34b017c732fad3f1c334111b (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
from __future__ import print_function, unicode_literals

from datetime import datetime, timedelta
import pytest
import time
import wee_slack
import os

os.environ["TZ"] = "UTC"


@pytest.mark.parametrize(
    "case",
    (
        {
            "input": "foo",
            "output": "foo",
        },
        {
            "input": "<!channel>",
            "output": "@channel",
        },
        {
            "input": "<!everyone>",
            "output": "@everyone",
        },
        {
            "input": "<!group>",
            "output": "@group",
        },
        {
            "input": "<!here>",
            "output": "@here",
        },
        {
            "input": "<@U407ABLLW|@othernick>: foo",
            "output": "@alice: foo",
        },
        {
            "input": "<@UNKNOWN|@othernick>: foo",
            "output": "@othernick: foo",
        },
        {
            "input": "foo <#C407ABS94|otherchannel> foo",
            "output": "foo #general foo",
        },
        {
            "input": "foo <#UNKNOWN|otherchannel> foo",
            "output": "foo #otherchannel foo",
        },
        {
            "input": "url: <https://example.com|fallback> suffix",
            "output": "url: https://example.com suffix",
            "ignore_alt_text": True,
        },
        {
            "input": "url: <https://example.com|example> suffix",
            "output": "url: https://example.com (example) suffix",
            "auto_link_display": "both",
        },
        {
            "input": "url: <https://example.com|example with spaces> suffix",
            "output": "url: https://example.com (example with spaces) suffix",
            "auto_link_display": "both",
        },
        {
            "input": "url: <https://example.com|example.com> suffix",
            "output": "url: https://example.com (example.com) suffix",
            "auto_link_display": "both",
        },
        {
            "input": "url: <mailto:name@example.com|name@example.com> suffix",
            "output": "url: mailto:name@example.com (name@example.com) suffix",
            "auto_link_display": "both",
        },
        {
            "input": "url: <https://example.com|example.com> suffix",
            "output": "url: example.com suffix",
            "auto_link_display": "text",
        },
        {
            "input": "url: <https://example.com|different text> suffix",
            "output": "url: https://example.com (different text) suffix",
            "auto_link_display": "text",
        },
        {
            "input": "url: <mailto:name@example.com|name@example.com> suffix",
            "output": "url: name@example.com suffix",
            "auto_link_display": "text",
        },
        {
            "input": "url: <https://example.com|different text> suffix",
            "output": "url: https://example.com (different text) suffix",
            "auto_link_display": "url",
        },
        {
            "input": "url: <https://example.com|example.com> suffix",
            "output": "url: https://example.com suffix",
            "auto_link_display": "url",
        },
        {
            "input": "url: <mailto:name@example.com|name@example.com> suffix",
            "output": "url: mailto:name@example.com suffix",
            "auto_link_display": "url",
        },
        {
            "input": "<@U407ABLLW> multiple unfurl <https://example.com|example with spaces>",
            "output": "@alice multiple unfurl https://example.com (example with spaces)",
            "auto_link_display": "both",
        },
        {
            "input": "url with equal fallback: <https://example.com|https://example.com> suffix",
            "output": "url with equal fallback: https://example.com suffix",
            "auto_link_display": "both",
        },
        {
            "input": "try the #general channel",
            "output": "try the #general channel",
        },
        {
            "input": "<@U407ABLLW> I think 3 > 2",
            "output": "@alice I think 3 > 2",
        },
        {
            "input": "<!subteam^TGX0ALBK3|@othersubteam> This is announcement for the dev team",
            "output": "@test This is announcement for the dev team",
        },
        {
            "input": "<!subteam^UNKNOWN|@othersubteam> This is announcement for the dev team",
            "output": "@othersubteam This is announcement for the dev team",
        },
        {
            "input": "Ends <!date^1577880000^{date_num} - {date} - {date_short} - {date_long}|Jan 01, 2020>.",
            "output": "Ends 2020-01-01 - January 01, 2020 - Jan 01, 2020 - Wednesday, January 01, 2020.",
        },
        {
            "input": "Ends <!date^1577880000^{time} - {time_secs}|12:00 PM>.",
            "output": "Ends 12:00 - 12:00:00.",
        },
        {
            "input": "Ends <!date^1577880000^{date_num} {invalid_token}>.",
            "output": "Ends 2020-01-01 {invalid_token}.",
        },
        {
            "input": "Ends <!date^1577880000^{date_num}^http://github.com>.",
            "output": "Ends 2020-01-01 (http://github.com).",
        },
        {
            "input": "Ends <!date^{}^{{date_pretty}} - {{date_short_pretty}} - {{date_long_pretty}}>.".format(
                int(time.mktime(datetime.today().timetuple()))
            ),
            "output": "Ends today - today - today.",
        },
        {
            "input": "Ends <!date^{}^{{date_pretty}} - {{date_short_pretty}} - {{date_long_pretty}}>.".format(
                int(time.mktime((datetime.today() - timedelta(days=1)).timetuple()))
            ),
            "output": "Ends yesterday - yesterday - yesterday.",
        },
        {
            "input": "Ends <!date^{}^{{date_pretty}} - {{date_short_pretty}} - {{date_long_pretty}}>.".format(
                int(time.mktime((datetime.today() + timedelta(days=1)).timetuple()))
            ),
            "output": "Ends tomorrow - tomorrow - tomorrow.",
        },
        {
            "input": "Ends <!date^1577880000^{date_pretty} - {date_short_pretty} - {date_long_pretty}>.",
            "output": "Ends January 01, 2020 - Jan 01, 2020 - Wednesday, January 01, 2020.",
        },
    ),
)
def test_unfurl_refs(case, realish_eventrouter):
    wee_slack.EVENTROUTER = realish_eventrouter
    wee_slack.config.unfurl_ignore_alt_text = case.get("ignore_alt_text")
    wee_slack.config.unfurl_auto_link_display = case.get("auto_link_display")

    result = wee_slack.unfurl_refs(case["input"])
    assert result == case["output"]