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

Fix #1102 Add __contains__ method in slack_sdk.web.SlackResponse / AsyncSlackResponse #1104

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions slack/web/async_slack_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def __str__(self):
)
return f"{self.data}"

def __contains__(self, key: str) -> bool:
return self.get(key) is not None

def __getitem__(self, key):
"""Retrieves any key from the data store.

Expand Down
3 changes: 3 additions & 0 deletions slack_sdk/web/async_slack_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def __str__(self):
)
return f"{self.data}"

def __contains__(self, key: str) -> bool:
return self.get(key) is not None

def __getitem__(self, key):
"""Retrieves any key from the data store.

Expand Down
3 changes: 3 additions & 0 deletions slack_sdk/web/slack_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def __str__(self):
)
return f"{self.data}"

def __contains__(self, key: str) -> bool:
return self.get(key) is not None

def __getitem__(self, key):
"""Retrieves any key from the data store.

Expand Down
14 changes: 14 additions & 0 deletions tests/slack_sdk/web/test_slack_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@ def test_issue_1100(self):

foo = response.get("foo")
self.assertIsNone(foo)

# https://github.com/slackapi/python-slack-sdk/issues/1102
def test_issue_1102(self):
response = SlackResponse(
client=WebClient(token="xoxb-dummy"),
http_verb="POST",
api_url="http://localhost:3000/api.test",
req_args={},
data={"ok": True, "args": {"hello": "world"}},
headers={},
status_code=200,
)
self.assertTrue("ok" in response)
self.assertTrue("foo" not in response)
16 changes: 15 additions & 1 deletion tests/slack_sdk_async/web/test_async_slack_response.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from slack.web.async_slack_response import AsyncSlackResponse
Copy link
Member Author

Choose a reason for hiding this comment

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

This import had been just wrong

from slack_sdk.web.async_slack_response import AsyncSlackResponse
from slack_sdk.web.async_client import AsyncWebClient


Expand All @@ -27,3 +27,17 @@ def test_issue_1100(self):

foo = response.get("foo")
self.assertIsNone(foo)

# https://github.com/slackapi/python-slack-sdk/issues/1102
def test_issue_1102(self):
response = AsyncSlackResponse(
client=AsyncWebClient(token="xoxb-dummy"),
http_verb="POST",
api_url="http://localhost:3000/api.test",
req_args={},
data={"ok": True, "args": {"hello": "world"}},
headers={},
status_code=200,
)
self.assertTrue("ok" in response)
self.assertTrue("foo" not in response)