Skip to content

Commit 78b6487

Browse files
authored
Upgrade test dependencies & fix Falcon warning (#588)
* Upgrade test dependencies & fix Falcon warning * Organize dependencies in setup.py
1 parent 1d13969 commit 78b6487

File tree

10 files changed

+67
-27
lines changed

10 files changed

+67
-27
lines changed

.github/maintainers_guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ If you make changes to `slack_bolt/adapter/*`, please verify if it surely works
8989
```bash
9090
# Install all optional dependencies
9191
$ pip install -e ".[adapter]"
92+
$ pip install -e ".[adapter_testing]"
9293

9394
# Set required env variables
9495
$ export SLACK_SIGNING_SECRET=***

.github/workflows/codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
pip install -e ".[async]"
3030
pip install -e ".[adapter]"
3131
pip install -e ".[testing]"
32+
pip install -e ".[adapter_testing]"
3233
- name: Run all tests for codecov
3334
run: |
3435
pytest --cov=slack_bolt/ && bash <(curl -s https://codecov.io/bash)

.github/workflows/tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
- name: Run tests for Socket Mode adapters
3535
run: |
3636
pip install -e ".[adapter]"
37+
pip install -e ".[adapter_testing]"
3738
pytest tests/adapter_tests/socket_mode/
3839
- name: Run tests for HTTP Mode adapters (AWS)
3940
run: |
@@ -47,9 +48,13 @@ jobs:
4748
- name: Run tests for HTTP Mode adapters (Django)
4849
run: |
4950
pytest tests/adapter_tests/django/
50-
- name: Run tests for HTTP Mode adapters (Falcon)
51+
- name: Run tests for HTTP Mode adapters (Falcon 3.x)
5152
run: |
5253
pytest tests/adapter_tests/falcon/
54+
- name: Run tests for HTTP Mode adapters (Falcon 2.x)
55+
run: |
56+
pip install "falcon<3"
57+
pytest tests/adapter_tests/falcon/
5358
- name: Run tests for HTTP Mode adapters (Flask)
5459
run: |
5560
pytest tests/adapter_tests/flask/

scripts/install_all_and_run_tests.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ pip install -e .
1515

1616
if [[ $test_target != "" ]]
1717
then
18-
pip install -e ".[testing]" && \
18+
# To fix: Using legacy 'setup.py install' for greenlet, since package 'wheel' is not installed.
19+
pip install -U wheel && \
20+
pip install -e ".[testing]" && \
1921
pip install -e ".[adapter]" && \
22+
pip install -e ".[adapter_testing]" && \
23+
# To avoid errors due to the old versions of click forced by Chalice
24+
pip install -U pip click && \
2025
black slack_bolt/ tests/ && \
2126
pytest $1
2227
else
23-
pip install -e ".[testing]" && \
28+
# To fix: Using legacy 'setup.py install' for greenlet, since package 'wheel' is not installed.
29+
pip install -U wheel && \
30+
pip install -e ".[testing]" && \
2431
pip install -e ".[adapter]" && \
32+
pip install -e ".[adapter_testing]" && \
33+
# To avoid errors due to the old versions of click forced by Chalice
34+
pip install -U pip click && \
2535
black slack_bolt/ tests/ && \
2636
pytest && \
2737
pip install -U pytype && \

scripts/run_pytype.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ script_dir=$(dirname $0)
55
cd ${script_dir}/.. && \
66
pip install -e ".[async]" && \
77
pip install -e ".[adapter]" && \
8-
pip install "pytype==2022.1.13" && \
8+
pip install "pytype==2022.1.31" && \
99
pytype slack_bolt/

scripts/run_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ else
2020
black slack_bolt/ tests/ \
2121
&& pytest -vv \
2222
&& pip install -e ".[adapter]" \
23+
&& pip install -e ".[adapter_testing]" \
2324
&& pip install -U pip setuptools wheel \
2425
&& pip install -U pytype \
2526
&& pytype slack_bolt/

setup.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,19 @@
1515
test_dependencies = [
1616
"pytest>=6.2.5,<7",
1717
"pytest-cov>=3,<4",
18-
"Flask-Sockets>=0.2,<1",
19-
"Werkzeug<2", # TODO: support Flask 2.x
20-
"black==21.12b0",
18+
"Flask-Sockets>=0.2,<1", # TODO: This module is not yet Flask 2.x compatible
19+
"Werkzeug>=1,<2", # TODO: Flask-Sockets is not yet compatible with Flask 2.x
20+
"black==22.1.0",
21+
]
22+
23+
adapter_test_dependencies = [
24+
"moto>=3,<4", # For AWS tests
25+
"docker>=5,<6", # Used by moto
26+
"boddle>=0.2,<0.3", # For Bottle app tests
27+
"Flask>=1,<2", # TODO: Flask-Sockets is not yet compatible with Flask 2.x
28+
"Werkzeug>=1,<2", # TODO: Flask-Sockets is not yet compatible with Flask 2.x
29+
"sanic-testing>=0.7" if sys.version_info.minor > 6 else "",
30+
"requests>=2,<3", # For Starlette's TestClient
2131
]
2232

2333
async_test_dependencies = test_dependencies + [
@@ -63,36 +73,32 @@
6373
"adapter": [
6474
# used only under src/slack_bolt/adapter
6575
"boto3<=2",
66-
# TODO: Upgrade to v2
67-
"moto<2", # For AWS tests
6876
"bottle>=0.12,<1",
69-
"boddle>=0.2,<0.3", # For Bottle app tests
70-
"chalice>=1.26.1,<2",
77+
"chalice>=1.26.5,<2",
7178
"click>=7,<8", # for chalice
7279
"CherryPy>=18,<19",
73-
"Django>=3,<4",
74-
"falcon>=2,<3",
80+
"Django>=3,<5",
81+
"falcon>=2,<4",
7582
"fastapi>=0.70.0,<1",
76-
"Flask>=1,<2",
77-
"Werkzeug<2", # TODO: support Flask 2.x
78-
"pyramid>=1,<2",
83+
"Flask>=1,<3",
84+
"Werkzeug>=2,<3",
85+
"pyramid>=1,<3",
7986
"sanic>=21,<22" if sys.version_info.minor > 6 else "sanic>=20,<21",
80-
"sanic-testing>=0.7" if sys.version_info.minor > 6 else "",
8187
"starlette>=0.14,<1",
82-
"requests>=2,<3", # For starlette's TestClient
8388
"tornado>=6,<7",
8489
# server
8590
"uvicorn<1",
8691
"gunicorn>=20,<21",
8792
# Socket Mode 3rd party implementation
88-
# TODO: 1.2.2 has a regression (https://github.com/websocket-client/websocket-client/issues/769)
89-
# ERROR on_error invoked (error: AttributeError, message: 'Dispatcher' object has no attribute 'read')
90-
"websocket_client>=1,<1.2.2",
93+
# Note: 1.2.2 has a regression (https://github.com/websocket-client/websocket-client/issues/769)
94+
"websocket_client>=1.2.3,<2",
9195
],
9296
# pip install -e ".[testing_without_asyncio]"
9397
"testing_without_asyncio": test_dependencies,
9498
# pip install -e ".[testing]"
9599
"testing": async_test_dependencies,
100+
# pip install -e ".[adapter_testing]"
101+
"adapter_testing": adapter_test_dependencies,
96102
},
97103
classifiers=[
98104
"Programming Language :: Python :: 3.6",

slack_bolt/adapter/falcon/resource.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime # type: ignore
22
from http import HTTPStatus
33

4-
from falcon import Request, Response
4+
from falcon import Request, Response, version as falcon_version
55

66
from slack_bolt import BoltResponse
77
from slack_bolt.app import App
@@ -50,7 +50,11 @@ def _to_bolt_request(self, req: Request) -> BoltRequest:
5050
)
5151

5252
def _write_response(self, bolt_resp: BoltResponse, resp: Response):
53-
resp.body = bolt_resp.body
53+
if falcon_version.__version__.startswith("2."):
54+
resp.body = bolt_resp.body
55+
else:
56+
resp.text = bolt_resp.body
57+
5458
status = HTTPStatus(bolt_resp.status)
5559
resp.status = str(f"{status.value} {status.phrase}")
5660
resp.set_headers(bolt_resp.first_headers_without_set_cookie())

tests/adapter_tests/django/test_django_settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
"NAME": "logs/db.sqlite3",
66
}
77
}
8+
# Django 4 warning: The default value of USE_TZ will change from False to True in Django 5.0.
9+
# Set USE_TZ to False in your project settings if you want to keep the current default behavior.
10+
USE_TZ = False

tests/adapter_tests/falcon/test_falcon.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from urllib.parse import quote
44

55
import falcon
6+
7+
68
from falcon import testing
79
from slack_sdk.signature import SignatureVerifier
810
from slack_sdk.web import WebClient
@@ -18,6 +20,13 @@
1820
from tests.utils import remove_os_env_temporarily, restore_os_env
1921

2022

23+
def new_falcon_app():
24+
if falcon.version.__version__.startswith("2."):
25+
return falcon.API()
26+
else:
27+
return falcon.App()
28+
29+
2130
class TestFalcon:
2231
signing_secret = "secret"
2332
valid_token = "xoxb-valid"
@@ -87,7 +96,7 @@ def event_handler():
8796
}
8897
timestamp, body = str(int(time())), json.dumps(input)
8998

90-
api = falcon.API()
99+
api = new_falcon_app()
91100
resource = SlackAppResource(app)
92101
api.add_route("/slack/events", resource)
93102

@@ -128,7 +137,7 @@ def shortcut_handler(ack):
128137

129138
timestamp, body = str(int(time())), f"payload={quote(json.dumps(input))}"
130139

131-
api = falcon.API()
140+
api = new_falcon_app()
132141
resource = SlackAppResource(app)
133142
api.add_route("/slack/events", resource)
134143

@@ -169,7 +178,7 @@ def command_handler(ack):
169178
)
170179
timestamp, body = str(int(time())), input
171180

172-
api = falcon.API()
181+
api = new_falcon_app()
173182
resource = SlackAppResource(app)
174183
api.add_route("/slack/events", resource)
175184

@@ -192,7 +201,7 @@ def test_oauth(self):
192201
scopes=["chat:write", "commands"],
193202
),
194203
)
195-
api = falcon.API()
204+
api = new_falcon_app()
196205
resource = SlackAppResource(app)
197206
api.add_route("/slack/install", resource)
198207

0 commit comments

Comments
 (0)