forked from slackapi/bolt-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app_decorators.py
More file actions
106 lines (78 loc) · 3.01 KB
/
test_app_decorators.py
File metadata and controls
106 lines (78 loc) · 3.01 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
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
from typing import Callable
from slack_sdk import WebClient
from slack_bolt import App, Ack, BoltResponse
from tests.mock_web_api_server import (
setup_mock_web_api_server,
cleanup_mock_web_api_server,
)
from tests.utils import remove_os_env_temporarily, restore_os_env
class NoopAck(Ack):
def __call__(self) -> BoltResponse:
pass
class TestAppDecorators:
signing_secret = "secret"
valid_token = "xoxb-valid"
mock_api_server_base_url = "http://localhost:8888"
web_client = WebClient(token=valid_token, base_url=mock_api_server_base_url)
def test_decorators(self):
try:
self.old_os_env = remove_os_env_temporarily()
setup_mock_web_api_server(self)
app = App(signing_secret=self.signing_secret, client=self.web_client)
ack = NoopAck()
@app.event("app_home_opened")
def handle_events(body: dict):
assert body is not None
handle_events({})
assert isinstance(handle_events, Callable)
@app.message("hi")
def handle_message_events(body: dict):
assert body is not None
handle_message_events({})
assert isinstance(handle_message_events, Callable)
@app.command("/hello")
def handle_commands(ack: Ack, body: dict):
assert body is not None
ack()
handle_commands(ack, {})
assert isinstance(handle_commands, Callable)
@app.shortcut("test-shortcut")
def handle_shortcuts(ack: Ack, body: dict):
assert body is not None
ack()
handle_shortcuts(ack, {})
assert isinstance(handle_shortcuts, Callable)
@app.action("some-action-id")
def handle_actions(ack: Ack, body: dict):
assert body is not None
ack()
handle_actions(ack, {})
assert isinstance(handle_actions, Callable)
@app.view("some-callback-id")
def handle_views(ack: Ack, body: dict):
assert body is not None
ack()
handle_views(ack, {})
assert isinstance(handle_views, Callable)
@app.options("some-id")
def handle_views(ack: Ack, body: dict):
assert body is not None
ack()
handle_views(ack, {})
assert isinstance(handle_views, Callable)
@app.error
def handle_errors(body: dict):
assert body is not None
handle_errors({})
assert isinstance(handle_errors, Callable)
@app.use
def middleware(body, next):
assert body is not None
next()
def next_func():
pass
middleware({}, next_func)
assert isinstance(middleware, Callable)
finally:
cleanup_mock_web_api_server(self)
restore_os_env(self.old_os_env)