Skip to content

Commit

Permalink
Fix #1102 Add __contains__ method in slack_sdk.web.SlackResponse / As…
Browse files Browse the repository at this point in the history
…yncSlackResponse (#1104)
  • Loading branch information
seratch authored Aug 20, 2021
1 parent c23312c commit d679144
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
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
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)

0 comments on commit d679144

Please sign in to comment.