diff --git a/slack/web/async_slack_response.py b/slack/web/async_slack_response.py index c629705b7..9f65c733d 100644 --- a/slack/web/async_slack_response.py +++ b/slack/web/async_slack_response.py @@ -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. diff --git a/slack_sdk/web/async_slack_response.py b/slack_sdk/web/async_slack_response.py index 268ca5401..e9e1a3413 100644 --- a/slack_sdk/web/async_slack_response.py +++ b/slack_sdk/web/async_slack_response.py @@ -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. diff --git a/slack_sdk/web/slack_response.py b/slack_sdk/web/slack_response.py index 199c9920b..0fc9408ba 100644 --- a/slack_sdk/web/slack_response.py +++ b/slack_sdk/web/slack_response.py @@ -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. diff --git a/tests/slack_sdk/web/test_slack_response.py b/tests/slack_sdk/web/test_slack_response.py index 9b1f655ad..bb34d7c2d 100644 --- a/tests/slack_sdk/web/test_slack_response.py +++ b/tests/slack_sdk/web/test_slack_response.py @@ -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) diff --git a/tests/slack_sdk_async/web/test_async_slack_response.py b/tests/slack_sdk_async/web/test_async_slack_response.py index a4036a91e..f2820375b 100644 --- a/tests/slack_sdk_async/web/test_async_slack_response.py +++ b/tests/slack_sdk_async/web/test_async_slack_response.py @@ -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 @@ -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)