Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade test dependencies & fix Falcon warning #588

Merged
merged 2 commits into from Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/maintainers_guide.md
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
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
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
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
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
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
38 changes: 21 additions & 17 deletions setup.py
Expand Up @@ -15,9 +15,9 @@
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>=2,<3",
"black==22.1.0",
]

async_test_dependencies = test_dependencies + [
Expand Down Expand Up @@ -63,36 +63,40 @@
"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": [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Organized the optional dependencies by moving test-related ones to this group

"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
],
},
classifiers=[
"Programming Language :: Python :: 3.6",
Expand Down
8 changes: 6 additions & 2 deletions slack_bolt/adapter/falcon/resource.py
@@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.text does not exist in 2.x

else:
resp.text = bolt_resp.body
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.body is deprecated in 3.x


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
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
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()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

falcon.API is deprecated in 3.x. However, the new recommended way falcon.App does not exist in 2.x

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