Skip to content

Commit 7cd8198

Browse files
committed
Update tests and samples
1 parent d327f1e commit 7cd8198

7 files changed

Lines changed: 37 additions & 34 deletions

File tree

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
language:
22
python
3-
sudo:
4-
false
53
python:
64
- "3.6"
75
- "3.7"
@@ -11,4 +9,4 @@ python:
119
install:
1210
- python setup.py install
1311
script:
14-
- python setup.py test
12+
- python -m pytest tests/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def event_test(ack, say):
7373
say("What's up?")
7474

7575

76-
if __name__ == '__main__':
76+
if __name__ == "__main__":
7777
app.start(3000) # POST http://localhost:3000/slack/events
7878
```
7979

samples/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def bot_message_deleted(logger):
152152
logger.info("A bot message has been deleted")
153153

154154

155-
if __name__ == '__main__':
155+
if __name__ == "__main__":
156156
app.start(3000)
157157

158158
# pip install slackclient

samples/async_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def event_test(payload, say, logger):
2626
await say("What's up?")
2727

2828

29-
if __name__ == '__main__':
29+
if __name__ == "__main__":
3030
app.start(3000)
3131

3232
# pip install slackclient

samples/oauth_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def event_test(payload, say, logger):
1818
say("What's up?")
1919

2020

21-
if __name__ == '__main__':
21+
if __name__ == "__main__":
2222
app.start(3000)
2323

2424
# pip install slackclient

setup.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@
3131
"slackclient>=2,<3", # TODO: will be replaced with slack_sdk==3.0.0
3232
"aiohttp>=3,<4", # slackclient depends on aiohttp
3333
],
34-
extra_requires=[
35-
# used only under src/slack_bolt/adapter
36-
"Django>=3,<4",
37-
"falcon>=2,<3",
38-
"fastapi>=0.54,<0.55",
39-
"Flask>=1,<2",
40-
"pyramid>=1,<2",
41-
"responder>=2,<3",
42-
"starlette>=0.13,<1",
43-
# used only under src/slack_sdk/*_store
44-
"boto3<=2",
45-
],
34+
extras_require={
35+
"adapters": [
36+
# used only under src/slack_bolt/adapter
37+
"Django>=3,<4",
38+
"falcon>=2,<3",
39+
"fastapi>=0.54,<0.55",
40+
"Flask>=1,<2",
41+
"pyramid>=1,<2",
42+
"responder>=2,<3",
43+
"starlette>=0.13,<1",
44+
# used only under src/slack_sdk/*_store
45+
"boto3<=2",
46+
]
47+
},
4648
classifiers=[
4749
"Programming Language :: Python :: 3.6",
4850
"Programming Language :: Python :: 3.7",

tests/scenario_tests/test_async_events.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ async def test_process_before_response(self):
8484
# no sleep here
8585
assert self.mock_received_requests["/chat.postMessage"] == 1
8686

87+
@pytest.mark.asyncio
88+
async def test_middleware_skip(self):
89+
app = AsyncApp(
90+
client=self.web_client,
91+
signing_secret=self.signing_secret
92+
)
93+
app.event("app_mention", middleware=[skip_middleware])(whats_up)
94+
95+
request = self.build_valid_app_mention_request()
96+
response = await app.async_dispatch(request)
97+
assert response.status == 404
98+
assert self.mock_received_requests["/auth.test"] == 1
99+
87100
@pytest.mark.asyncio
88101
async def test_simultaneous_requests(self):
89102
app = AsyncApp(
@@ -95,27 +108,17 @@ async def test_simultaneous_requests(self):
95108
request = self.build_valid_app_mention_request()
96109

97110
times = 10
111+
tasks = []
98112
for i in range(times):
99-
asyncio.ensure_future(app.async_dispatch(request))
113+
tasks.append(asyncio.ensure_future(app.async_dispatch(request)))
100114

101115
await asyncio.sleep(5)
116+
# Verifies all the tasks have been completed with 200 OK
117+
assert sum([t.result().status for t in tasks if t.done()]) == 200 * times
102118

103119
assert self.mock_received_requests["/auth.test"] == times
104120
assert self.mock_received_requests["/chat.postMessage"] == times
105121

106-
@pytest.mark.asyncio
107-
async def test_middleware_skip(self):
108-
app = AsyncApp(
109-
client=self.web_client,
110-
signing_secret=self.signing_secret
111-
)
112-
app.event("app_mention", middleware=[skip_middleware])(whats_up)
113-
114-
request = self.build_valid_app_mention_request()
115-
response = await app.async_dispatch(request)
116-
assert response.status == 404
117-
assert self.mock_received_requests["/auth.test"] == 1
118-
119122

120123
app_mention_payload = {
121124
"token": "verification_token",
@@ -141,7 +144,7 @@ async def test_middleware_skip(self):
141144

142145
async def random_sleeper(payload, say):
143146
assert payload == app_mention_payload
144-
seconds = random() + 2 # 2-3 seconds
147+
seconds = random() + 2 # 2-3 seconds
145148
await asyncio.sleep(seconds)
146149
await say(f"Sending this message after sleeping for {seconds} seconds")
147150

0 commit comments

Comments
 (0)