def test_component_builds_fields(values): class ParentFakeComponent(Component): title = StringField() text = TextField() class FakeComponent(ParentFakeComponent): elements = ArrayField(PlainText) users = ArrayField(str) users = ["U123456", "U654321"] component = FakeComponent( values.title, MarkdownText(values.text), [PlainText(values.text) for _ in range(2)], users, ) assert component.build() == { "title": values.title, "text": { "type": "mrkdwn", "text": values.text }, "elements": [ { "type": "plain_text", "text": values.text }, { "type": "plain_text", "text": values.text }, ], "users": users, }
from blockkit import Message, Section, Actions, MarkdownText, Button message = Message(blocks=[ Section(MarkdownText("You have a new request")), Section(fields=[ MarkdownText("*Type:*\nComputer (laptop)"), MarkdownText("*When:*\nSubmitted Aut 10"), MarkdownText("*Last Update:*\nMar 10, 2015 (3 years, 5 months)"), MarkdownText("*Reason:*\nAll vowel keys aren't working."), MarkdownText("*Specs:*\nCheetah Pro 15 - Fast, really fast"), ], ), Actions([ Button("Approve", style=Button.primary, action_id="approve"), Button("Decline", style=Button.danger, action_id="decline"), Button("Discuss", action_id="discuss"), ]), ]) message = message.build()
def markdown_text(values): return MarkdownText(values.text)
def test_builds_markdown_text(values): assert MarkdownText(values.text, verbatim=True).build() == { "type": Text.markdown, "text": values.text, "verbatim": True, }
def test_plain_text_field_with_incorrect_type_raises_exception(values): with pytest.raises(ValidationError): TextField(plain=True).validate(MarkdownText(values.text))