Skip to content

Commit

Permalink
Upgrade test dependencies & fix Falcon warning (#588)
Browse files Browse the repository at this point in the history
* Upgrade test dependencies & fix Falcon warning

* Organize dependencies in setup.py
  • Loading branch information
seratch authored Feb 4, 2022
1 parent 1d13969 commit 78b6487
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 27 deletions.
1 change: 1 addition & 0 deletions .github/maintainers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ If you make changes to `slack_bolt/adapter/*`, please verify if it surely works
```bash
# Install all optional dependencies
$ pip install -e ".[adapter]"
$ pip install -e ".[adapter_testing]"

# Set required env variables
$ export SLACK_SIGNING_SECRET=***
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
pip install -e ".[async]"
pip install -e ".[adapter]"
pip install -e ".[testing]"
pip install -e ".[adapter_testing]"
- name: Run all tests for codecov
run: |
pytest --cov=slack_bolt/ && bash <(curl -s https://codecov.io/bash)
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- name: Run tests for Socket Mode adapters
run: |
pip install -e ".[adapter]"
pip install -e ".[adapter_testing]"
pytest tests/adapter_tests/socket_mode/
- name: Run tests for HTTP Mode adapters (AWS)
run: |
Expand All @@ -47,9 +48,13 @@ jobs:
- name: Run tests for HTTP Mode adapters (Django)
run: |
pytest tests/adapter_tests/django/
- name: Run tests for HTTP Mode adapters (Falcon)
- name: Run tests for HTTP Mode adapters (Falcon 3.x)
run: |
pytest tests/adapter_tests/falcon/
- name: Run tests for HTTP Mode adapters (Falcon 2.x)
run: |
pip install "falcon<3"
pytest tests/adapter_tests/falcon/
- name: Run tests for HTTP Mode adapters (Flask)
run: |
pytest tests/adapter_tests/flask/
Expand Down
14 changes: 12 additions & 2 deletions scripts/install_all_and_run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ pip install -e .

if [[ $test_target != "" ]]
then
pip install -e ".[testing]" && \
# To fix: Using legacy 'setup.py install' for greenlet, since package 'wheel' is not installed.
pip install -U wheel && \
pip install -e ".[testing]" && \
pip install -e ".[adapter]" && \
pip install -e ".[adapter_testing]" && \
# To avoid errors due to the old versions of click forced by Chalice
pip install -U pip click && \
black slack_bolt/ tests/ && \
pytest $1
else
pip install -e ".[testing]" && \
# To fix: Using legacy 'setup.py install' for greenlet, since package 'wheel' is not installed.
pip install -U wheel && \
pip install -e ".[testing]" && \
pip install -e ".[adapter]" && \
pip install -e ".[adapter_testing]" && \
# To avoid errors due to the old versions of click forced by Chalice
pip install -U pip click && \
black slack_bolt/ tests/ && \
pytest && \
pip install -U pytype && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_pytype.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ script_dir=$(dirname $0)
cd ${script_dir}/.. && \
pip install -e ".[async]" && \
pip install -e ".[adapter]" && \
pip install "pytype==2022.1.13" && \
pip install "pytype==2022.1.31" && \
pytype slack_bolt/
1 change: 1 addition & 0 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ else
black slack_bolt/ tests/ \
&& pytest -vv \
&& pip install -e ".[adapter]" \
&& pip install -e ".[adapter_testing]" \
&& pip install -U pip setuptools wheel \
&& pip install -U pytype \
&& pytype slack_bolt/
Expand Down
40 changes: 23 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@
test_dependencies = [
"pytest>=6.2.5,<7",
"pytest-cov>=3,<4",
"Flask-Sockets>=0.2,<1",
"Werkzeug<2", # TODO: support Flask 2.x
"black==21.12b0",
"Flask-Sockets>=0.2,<1", # TODO: This module is not yet Flask 2.x compatible
"Werkzeug>=1,<2", # TODO: Flask-Sockets is not yet compatible with Flask 2.x
"black==22.1.0",
]

adapter_test_dependencies = [
"moto>=3,<4", # For AWS tests
"docker>=5,<6", # Used by moto
"boddle>=0.2,<0.3", # For Bottle app tests
"Flask>=1,<2", # TODO: Flask-Sockets is not yet compatible with Flask 2.x
"Werkzeug>=1,<2", # TODO: Flask-Sockets is not yet compatible with Flask 2.x
"sanic-testing>=0.7" if sys.version_info.minor > 6 else "",
"requests>=2,<3", # For Starlette's TestClient
]

async_test_dependencies = test_dependencies + [
Expand Down Expand Up @@ -63,36 +73,32 @@
"adapter": [
# used only under src/slack_bolt/adapter
"boto3<=2",
# TODO: Upgrade to v2
"moto<2", # For AWS tests
"bottle>=0.12,<1",
"boddle>=0.2,<0.3", # For Bottle app tests
"chalice>=1.26.1,<2",
"chalice>=1.26.5,<2",
"click>=7,<8", # for chalice
"CherryPy>=18,<19",
"Django>=3,<4",
"falcon>=2,<3",
"Django>=3,<5",
"falcon>=2,<4",
"fastapi>=0.70.0,<1",
"Flask>=1,<2",
"Werkzeug<2", # TODO: support Flask 2.x
"pyramid>=1,<2",
"Flask>=1,<3",
"Werkzeug>=2,<3",
"pyramid>=1,<3",
"sanic>=21,<22" if sys.version_info.minor > 6 else "sanic>=20,<21",
"sanic-testing>=0.7" if sys.version_info.minor > 6 else "",
"starlette>=0.14,<1",
"requests>=2,<3", # For starlette's TestClient
"tornado>=6,<7",
# server
"uvicorn<1",
"gunicorn>=20,<21",
# Socket Mode 3rd party implementation
# TODO: 1.2.2 has a regression (https://github.com/websocket-client/websocket-client/issues/769)
# ERROR on_error invoked (error: AttributeError, message: 'Dispatcher' object has no attribute 'read')
"websocket_client>=1,<1.2.2",
# Note: 1.2.2 has a regression (https://github.com/websocket-client/websocket-client/issues/769)
"websocket_client>=1.2.3,<2",
],
# pip install -e ".[testing_without_asyncio]"
"testing_without_asyncio": test_dependencies,
# pip install -e ".[testing]"
"testing": async_test_dependencies,
# pip install -e ".[adapter_testing]"
"adapter_testing": adapter_test_dependencies,
},
classifiers=[
"Programming Language :: Python :: 3.6",
Expand Down
8 changes: 6 additions & 2 deletions slack_bolt/adapter/falcon/resource.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime # type: ignore
from http import HTTPStatus

from falcon import Request, Response
from falcon import Request, Response, version as falcon_version

from slack_bolt import BoltResponse
from slack_bolt.app import App
Expand Down Expand Up @@ -50,7 +50,11 @@ def _to_bolt_request(self, req: Request) -> BoltRequest:
)

def _write_response(self, bolt_resp: BoltResponse, resp: Response):
resp.body = bolt_resp.body
if falcon_version.__version__.startswith("2."):
resp.body = bolt_resp.body
else:
resp.text = bolt_resp.body

status = HTTPStatus(bolt_resp.status)
resp.status = str(f"{status.value} {status.phrase}")
resp.set_headers(bolt_resp.first_headers_without_set_cookie())
Expand Down
3 changes: 3 additions & 0 deletions tests/adapter_tests/django/test_django_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
"NAME": "logs/db.sqlite3",
}
}
# Django 4 warning: The default value of USE_TZ will change from False to True in Django 5.0.
# Set USE_TZ to False in your project settings if you want to keep the current default behavior.
USE_TZ = False
17 changes: 13 additions & 4 deletions tests/adapter_tests/falcon/test_falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from urllib.parse import quote

import falcon


from falcon import testing
from slack_sdk.signature import SignatureVerifier
from slack_sdk.web import WebClient
Expand All @@ -18,6 +20,13 @@
from tests.utils import remove_os_env_temporarily, restore_os_env


def new_falcon_app():
if falcon.version.__version__.startswith("2."):
return falcon.API()
else:
return falcon.App()


class TestFalcon:
signing_secret = "secret"
valid_token = "xoxb-valid"
Expand Down Expand Up @@ -87,7 +96,7 @@ def event_handler():
}
timestamp, body = str(int(time())), json.dumps(input)

api = falcon.API()
api = new_falcon_app()
resource = SlackAppResource(app)
api.add_route("/slack/events", resource)

Expand Down Expand Up @@ -128,7 +137,7 @@ def shortcut_handler(ack):

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

api = falcon.API()
api = new_falcon_app()
resource = SlackAppResource(app)
api.add_route("/slack/events", resource)

Expand Down Expand Up @@ -169,7 +178,7 @@ def command_handler(ack):
)
timestamp, body = str(int(time())), input

api = falcon.API()
api = new_falcon_app()
resource = SlackAppResource(app)
api.add_route("/slack/events", resource)

Expand All @@ -192,7 +201,7 @@ def test_oauth(self):
scopes=["chat:write", "commands"],
),
)
api = falcon.API()
api = new_falcon_app()
resource = SlackAppResource(app)
api.add_route("/slack/install", resource)

Expand Down

0 comments on commit 78b6487

Please sign in to comment.