From 6e3ed588cf7537ae672104281e5cf8720bf29346 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Thu, 10 Jun 2021 18:31:06 +0900 Subject: [PATCH 1/2] Remove confusing warning messages #1030 --- slack_sdk/models/blocks/block_elements.py | 19 ++++++++++++++++--- tests/slack_sdk/models/test_elements.py | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/slack_sdk/models/blocks/block_elements.py b/slack_sdk/models/blocks/block_elements.py index 4f0489c19..e9942687f 100644 --- a/slack_sdk/models/blocks/block_elements.py +++ b/slack_sdk/models/blocks/block_elements.py @@ -149,10 +149,17 @@ def __init__( subtype: Optional[str] = None, **others: dict, ): + """An interactive block element. + + We generally recommend using the concrete subclasses for better supports of available properties. + """ if subtype: self._subtype_warning() super().__init__(type=type or subtype) - show_unknown_key_warning(self, others) + + # Note that we don't intentionally have show_unknown_key_warning for the unknown key warnings here. + # It's fine to pass any kwargs to the held dict here although the class does not do any validation. + # show_unknown_key_warning(self, others) self.action_id = action_id @@ -190,11 +197,17 @@ def __init__( confirm: Optional[Union[dict, ConfirmObject]] = None, **others: dict, ): - """InteractiveElement that is usable in input blocks""" + """InteractiveElement that is usable in input blocks + + We generally recommend using the concrete subclasses for better supports of available properties. + """ if subtype: self._subtype_warning() super().__init__(action_id=action_id, type=type or subtype) - show_unknown_key_warning(self, others) + + # Note that we don't intentionally have show_unknown_key_warning for the unknown key warnings here. + # It's fine to pass any kwargs to the held dict here although the class does not do any validation. + # show_unknown_key_warning(self, others) self.placeholder = TextObject.parse(placeholder) self.confirm = ConfirmObject.parse(confirm) diff --git a/tests/slack_sdk/models/test_elements.py b/tests/slack_sdk/models/test_elements.py index 3b7d600d7..56780b416 100644 --- a/tests/slack_sdk/models/test_elements.py +++ b/tests/slack_sdk/models/test_elements.py @@ -23,6 +23,8 @@ ChannelSelectElement, ConfirmObject, Option, + InputInteractiveElement, + InteractiveElement, ) from . import STRING_3001_CHARS, STRING_301_CHARS @@ -32,6 +34,26 @@ # ------------------------------------------------- +class InteractiveElementTests(unittest.TestCase): + def test_with_interactive_element(self): + input = { + "type": "plain_text_input", + "action_id": "plain_input", + "placeholder": {"type": "plain_text", "text": "Enter some plain text"}, + } + # Any properties should be lost + self.assertDictEqual(input, InteractiveElement(**input).to_dict()) + + def test_with_input_interactive_element(self): + input = { + "type": "plain_text_input", + "action_id": "plain_input", + "placeholder": {"type": "plain_text", "text": "Enter some plain text"}, + } + # Any properties should be lost + self.assertDictEqual(input, InputInteractiveElement(**input).to_dict()) + + class InteractiveElementTests(unittest.TestCase): def test_action_id(self): with self.assertRaises(SlackObjectFormationError): From d38fb86e6b42e9b668277c2ea7060a1ba9da36c4 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Thu, 10 Jun 2021 18:40:01 +0900 Subject: [PATCH 2/2] Fix test comments --- tests/slack_sdk/models/test_elements.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/slack_sdk/models/test_elements.py b/tests/slack_sdk/models/test_elements.py index 56780b416..2e0c453c8 100644 --- a/tests/slack_sdk/models/test_elements.py +++ b/tests/slack_sdk/models/test_elements.py @@ -41,7 +41,7 @@ def test_with_interactive_element(self): "action_id": "plain_input", "placeholder": {"type": "plain_text", "text": "Enter some plain text"}, } - # Any properties should be lost + # Any properties should not be lost self.assertDictEqual(input, InteractiveElement(**input).to_dict()) def test_with_input_interactive_element(self): @@ -50,7 +50,7 @@ def test_with_input_interactive_element(self): "action_id": "plain_input", "placeholder": {"type": "plain_text", "text": "Enter some plain text"}, } - # Any properties should be lost + # Any properties should not be lost self.assertDictEqual(input, InputInteractiveElement(**input).to_dict())