-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathtest_say.py
More file actions
65 lines (52 loc) · 2.51 KB
/
test_say.py
File metadata and controls
65 lines (52 loc) · 2.51 KB
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
import pytest
from slack_sdk import WebClient
from slack_sdk.web import SlackResponse
from slack_bolt import Say
from tests.mock_web_api_server import cleanup_mock_web_api_server, setup_mock_web_api_server
class TestSay:
def setup_method(self):
setup_mock_web_api_server(self)
valid_token = "xoxb-valid"
mock_api_server_base_url = "http://localhost:8888"
self.web_client = WebClient(token=valid_token, base_url=mock_api_server_base_url)
def teardown_method(self):
cleanup_mock_web_api_server(self)
def test_say(self):
say = Say(client=self.web_client, channel="C111")
response: SlackResponse = say(text="Hi there!")
assert response.status_code == 200
def test_say_markdown_text(self):
say = Say(client=self.web_client, channel="C111")
response: SlackResponse = say(markdown_text="**Greetings!**")
assert response.status_code == 200
def test_say_unfurl_options(self):
say = Say(client=self.web_client, channel="C111")
response: SlackResponse = say(text="Hi there!", unfurl_media=True, unfurl_links=True)
assert response.status_code == 200
def test_say_reply_in_thread(self):
say = Say(client=self.web_client, channel="C111")
response: SlackResponse = say(text="Hi there!", thread_ts="111.222", reply_broadcast=True)
assert response.status_code == 200
def test_say_dict(self):
say = Say(client=self.web_client, channel="C111")
response: SlackResponse = say({"text": "Hi!"})
assert response.status_code == 200
def test_say_dict_channel(self):
say = Say(client=self.web_client, channel="C111")
response: SlackResponse = say({"text": "Hi!", "channel": "C111"})
assert response.status_code == 200
def test_say_invalid(self):
say = Say(client=self.web_client, channel="C111")
with pytest.raises(ValueError):
say([])
def test_say_shared_dict_as_arg(self):
# this shared dict object must not be modified by say method
shared_template_dict = {"text": "Hi there!"}
say = Say(client=self.web_client, channel="C111")
response: SlackResponse = say(shared_template_dict)
assert response.status_code == 200
assert shared_template_dict.get("channel") is None
say = Say(client=self.web_client, channel="C222")
response: SlackResponse = say(shared_template_dict)
assert response.status_code == 200
assert shared_template_dict.get("channel") is None