forked from slackapi/bolt-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
165 lines (139 loc) · 5.46 KB
/
test_app.py
File metadata and controls
165 lines (139 loc) · 5.46 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
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
import pytest
from slack_sdk import WebClient
from slack_sdk.oauth.installation_store import FileInstallationStore
from slack_sdk.oauth.state_store import FileOAuthStateStore
from slack_bolt.async_app import AsyncApp
from slack_bolt.authorization import AuthorizeResult
from slack_bolt.error import BoltError
from slack_bolt.oauth.async_oauth_flow import AsyncOAuthFlow
from slack_bolt.oauth.async_oauth_settings import AsyncOAuthSettings
from tests.utils import remove_os_env_temporarily, restore_os_env
class TestAsyncApp:
def setup_method(self):
self.old_os_env = remove_os_env_temporarily()
def teardown_method(self):
restore_os_env(self.old_os_env)
def non_coro_func(self, ack):
ack()
def test_non_coroutine_func_listener(self):
app = AsyncApp(signing_secret="valid", token="xoxb-xxx")
with pytest.raises(BoltError):
app.action("a")(self.non_coro_func)
async def simple_listener(self, ack):
await ack()
def test_listener_registration_error(self):
app = AsyncApp(signing_secret="valid", token="xoxb-xxx")
with pytest.raises(BoltError):
app.action({"type": "invalid_type", "action_id": "a"})(self.simple_listener)
# NOTE: We intentionally don't have this test in scenario_tests
# to avoid having async dependencies in the tests.
def test_invalid_client_type(self):
with pytest.raises(BoltError):
AsyncApp(signing_secret="valid", client=WebClient(token="xoxb-xxx"))
# --------------------------
# single team auth
# --------------------------
def test_valid_single_auth(self):
app = AsyncApp(signing_secret="valid", token="xoxb-xxx")
assert app != None
def test_token_absence(self):
with pytest.raises(BoltError):
AsyncApp(signing_secret="valid", token=None)
with pytest.raises(BoltError):
AsyncApp(signing_secret="valid", token="")
# --------------------------
# multi teams auth
# --------------------------
def test_valid_multi_auth(self):
app = AsyncApp(
signing_secret="valid",
oauth_settings=AsyncOAuthSettings(
client_id="111.222", client_secret="valid"
),
)
assert app != None
def test_valid_multi_auth_oauth_flow(self):
oauth_flow = AsyncOAuthFlow(
settings=AsyncOAuthSettings(
client_id="111.222",
client_secret="valid",
installation_store=FileInstallationStore(),
state_store=FileOAuthStateStore(expiration_seconds=120),
)
)
app = AsyncApp(signing_secret="valid", oauth_flow=oauth_flow)
assert app != None
def test_valid_multi_auth_client_id_absence(self):
with pytest.raises(BoltError):
AsyncApp(
signing_secret="valid",
oauth_settings=AsyncOAuthSettings(
client_id=None, client_secret="valid"
),
)
def test_valid_multi_auth_secret_absence(self):
with pytest.raises(BoltError):
AsyncApp(
signing_secret="valid",
oauth_settings=AsyncOAuthSettings(
client_id="111.222", client_secret=None
),
)
def test_authorize_conflicts(self):
oauth_settings = AsyncOAuthSettings(
client_id="111.222",
client_secret="valid",
installation_store=FileInstallationStore(),
state_store=FileOAuthStateStore(expiration_seconds=120),
)
# no error with this
AsyncApp(signing_secret="valid", oauth_settings=oauth_settings)
def authorize() -> AuthorizeResult:
return AuthorizeResult(enterprise_id="E111", team_id="T111")
with pytest.raises(BoltError):
AsyncApp(
signing_secret="valid",
authorize=authorize,
oauth_settings=oauth_settings,
)
oauth_flow = AsyncOAuthFlow(settings=oauth_settings)
# no error with this
AsyncApp(signing_secret="valid", oauth_flow=oauth_flow)
with pytest.raises(BoltError):
AsyncApp(signing_secret="valid", authorize=authorize, oauth_flow=oauth_flow)
def test_installation_store_conflicts(self):
store1 = FileInstallationStore()
store2 = FileInstallationStore()
app = AsyncApp(
signing_secret="valid",
oauth_settings=AsyncOAuthSettings(
client_id="111.222",
client_secret="valid",
installation_store=store1,
),
installation_store=store2,
)
assert app.installation_store is store1
app = AsyncApp(
signing_secret="valid",
oauth_flow=AsyncOAuthFlow(
settings=AsyncOAuthSettings(
client_id="111.222",
client_secret="valid",
installation_store=store1,
)
),
installation_store=store2,
)
assert app.installation_store is store1
app = AsyncApp(
signing_secret="valid",
oauth_flow=AsyncOAuthFlow(
settings=AsyncOAuthSettings(
client_id="111.222",
client_secret="valid",
)
),
installation_store=store1,
)
assert app.installation_store is store1