Skip to content

Commit 4a85b3a

Browse files
committed
Add unit tests
1 parent 44920ab commit 4a85b3a

File tree

14 files changed

+219
-5
lines changed

14 files changed

+219
-5
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language:
2+
python
3+
sudo:
4+
false
5+
python:
6+
- "3.6"
7+
- "3.7"
8+
- "3.8"
9+
- "3.8-dev" # 3.8 development branch
10+
- "nightly" # nightly build
11+
install:
12+
- python setup.py install
13+
script:
14+
- python setup.py test

logs/.gitkeep

Whitespace-only changes.

pytest.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[pytest]
2+
log_file = logs/pytest.log
3+
log_file_level = DEBUG
4+
log_format = %(asctime)s %(levelname)s %(message)s
5+
log_date_format = %Y-%m-%d %H:%M:%S
6+
filterwarnings =
7+
ignore:"@coroutine" decorator is deprecated since Python 3.8, use "async def" instead:DeprecationWarning

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[bdist_wheel]
2+
universal = 1
3+
4+
[aliases]
5+
test=pytest

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
setup_requires=["pytest-runner==5.2"],
2626
tests_require=["pytest==3.8.2"],
2727
install_requires=[
28-
"slackclient>=2,<3", # TODO: will be replaced with slack_sdk==3.0.0
29-
"aiohttp>=3,<4", # slackclient depends on aiohttp
28+
"slackclient>=2,<3", # TODO: will be replaced with slack_sdk==3.0.0
29+
"aiohttp>=3,<4", # slackclient depends on aiohttp
3030
],
3131
extra_requires=[
3232
# used only under src/slack_bolt/adapter

src/slack_bolt/app/app.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(
4545
signing_secret: str = os.environ["SLACK_SIGNING_SECRET"],
4646
# for single-workspace apps
4747
token: Optional[str] = os.environ.get("SLACK_BOT_TOKEN", None),
48+
client: Optional[WebClient] = None,
4849
# for multi-workspace apps
4950
installation_store: Optional[InstallationStore] = None,
5051
oauth_state_store: Optional[OAuthStateStore] = None,
@@ -67,10 +68,16 @@ def __init__(
6768
self.name = name or inspect.stack()[1].filename.split(os.path.sep)[-1]
6869
self._signing_secret: str = signing_secret
6970
self._verification_token: Optional[str] = verification_token
70-
71-
self._client = WebClient(token=token) # NOTE: the token here can be None
7271
self._framework_logger = get_bolt_logger(App)
7372

73+
if client is not None:
74+
self._client = client
75+
if token is not None:
76+
self._framework_logger.warning(
77+
"As you gave client as well, the bot token will be unused.")
78+
else:
79+
self._client = WebClient(token=token) # NOTE: the token here can be None
80+
7481
self._token: Optional[str] = token
7582
self._installation_store: Optional[InstallationStore] = installation_store
7683
self._oauth_state_store: Optional[OAuthStateStore] = oauth_state_store
@@ -166,6 +173,10 @@ def _sync_client_logger_with_oauth_flow(self):
166173
# -------------------------
167174
# accessors
168175

176+
@property
177+
def client(self) -> WebClient:
178+
return self._client
179+
169180
@property
170181
def installation_store(self) -> Optional[InstallationStore]:
171182
return self._installation_store

src/slack_bolt/middleware/ssl_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ def process(
2222
if self.verification_token and \
2323
self.verification_token == req.payload["token"]:
2424
return BoltResponse(status=401, body={"error": "invalid verification token"})
25-
return BoltResponse(status=200, body={})
25+
return BoltResponse(status=200, body="")
2626
else:
2727
return next()

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import sys
2+
from os.path import dirname
3+
4+
sys.path.append(f"{dirname(__file__)}/../src")

tests/fixture/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)