Skip to content

Commit

Permalink
Fix slackapi#1178 text type hint in LinkButtonElement does not accept…
Browse files Browse the repository at this point in the history
… PlainTextObject/dict
  • Loading branch information
seratch committed Feb 18, 2022
1 parent 1778647 commit 5339973
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion slack_sdk/models/blocks/block_elements.py
Expand Up @@ -325,7 +325,7 @@ class LinkButtonElement(ButtonElement):
def __init__(
self,
*,
text: str,
text: Union[str, dict, PlainTextObject],
url: str,
action_id: Optional[str] = None,
style: Optional[str] = None,
Expand Down
18 changes: 18 additions & 0 deletions tests/slack_sdk/models/test_elements.py
Expand Up @@ -26,6 +26,7 @@
Option,
InputInteractiveElement,
InteractiveElement,
PlainTextObject,
)
from . import STRING_3001_CHARS, STRING_301_CHARS

Expand Down Expand Up @@ -209,6 +210,23 @@ def test_json(self):
button.to_dict(),
)

# https://github.com/slackapi/python-slack-sdk/issues/1178
def test_text_patterns_issue_1178(self):
button = LinkButtonElement(
action_id="test",
text=PlainTextObject(text="button text"),
url="http://slack.com",
)
self.assertDictEqual(
{
"text": {"text": "button text", "type": "plain_text"},
"url": "http://slack.com",
"type": "button",
"action_id": button.action_id,
},
button.to_dict(),
)

def test_url_length(self):
with self.assertRaises(SlackObjectFormationError):
LinkButtonElement(text="Button", url=STRING_3001_CHARS).to_dict()
Expand Down

0 comments on commit 5339973

Please sign in to comment.