def test_builds_section(values, markdown_text, button): section = Section( markdown_text, block_id=values.block_id, fields=[markdown_text for _ in range(2)], accessory=button, ) assert section.build() == { "type": "section", "text": markdown_text.build(), "block_id": values.block_id, "fields": [markdown_text.build() for _ in range(2)], "accessory": button.build(), }
def test_builds_message(values, markdown_text, button): blocks = [Section(markdown_text, accessory=button)] attachments = [{ "color": "#36a64f", "mrkdwn_in": ["text"], "text": "Optional `text` that appears within the attachment", }] thread_ts = "1233333456.33" mrkdwn = True message = Message( values.text, blocks=blocks, attachments=attachments, thread_ts=thread_ts, mrkdwn=mrkdwn, ) assert message.build() == { "text": values.text, "blocks": [b.build() for b in blocks], "attachments": attachments, "thread_ts": thread_ts, "mrkdwn": mrkdwn, }
def test_builds_modal(values, modal_text, markdown_text, button): blocks = [Section(markdown_text, accessory=button)] private_metadata = "foobar" callback_id = "view_callback" clear_on_close = True notify_on_close = False external_id = "external" modal = Modal( modal_text, blocks, close=modal_text, submit=modal_text, private_metadata=private_metadata, callback_id=callback_id, clear_on_close=clear_on_close, notify_on_close=notify_on_close, external_id=external_id, ) assert modal.build() == { "type": "modal", "title": modal_text.build(), "blocks": [b.build() for b in blocks], "close": modal_text.build(), "submit": modal_text.build(), "private_metadata": private_metadata, "callback_id": callback_id, "clear_on_close": clear_on_close, "notify_on_close": notify_on_close, "external_id": external_id, }
def test_create_block_kit_builder_url_success_with_object(): message = Message(blocks=[Section(text="HELLLOOOO WORLD!")]) captured_output = io.StringIO() sys.stdout = captured_output create_block_kit_builder_url(message) sys.stdout = sys.__stdout__ # Re-direct output to console resulting_message = "Block kit builder example/validation: " \ "\n\thttps://app.slack.com/block-kit-builder/#%7B%22blocks%22:%20%5B%7B%22type%22:%20" \ "%22section%22%2C%20%22text%22:%20%7B%22text%22:%20%22HELLLOOOO%20WORLD%21%22%2C%20%22type%22" \ ":%20%22plain_text%22%2C%20%22emoji%22:%20true%7D%7D%5D%7D\n" assert captured_output.getvalue() == resulting_message
def test_builds_home(values, markdown_text, button): blocks = [Section(markdown_text, accessory=button)] private_metadata = "foobar" callback_id = "view_callback" external_id = "external" home = Home( blocks, private_metadata=private_metadata, callback_id=callback_id, external_id=external_id, ) assert home.build() == { "type": "home", "blocks": [b.build() for b in blocks], "private_metadata": private_metadata, "callback_id": callback_id, "external_id": external_id, }
def test_section_without_text_and_fields_raises_exception(values, button): with pytest.raises(ValidationError): Section(accessory=button)
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()
from blockkit import Section, Message from blockkit.display import create_block_kit_builder_url message = Message(blocks=[Section(text="HELLLOOOO WORLD!")]) """ outputs: Block kit builder example/validation: https://app.slack.com/block-kit-builder/#%7B%22blocks%22:%20%5B%7B%22type%22:%20%22section%22%2C%20%22text%22:%20%7B%22text%22:%20%22HELLLOOOO%20WORLD%21%22%2C%20%22type%22:%20%22plain_text%22%2C%20%22emoji%22:%20true%7D%7D%5D%7D """ create_block_kit_builder_url(message)