def test_json(self): self.assertDictEqual( { "text": { "text": "some text", "type": "mrkdwn" }, "block_id": "a_block", "type": "section", }, SectionBlock(text="some text", block_id="a_block").to_dict(), ) self.assertDictEqual( { "text": { "text": "some text", "type": "mrkdwn" }, "fields": [ { "text": "field0", "type": "mrkdwn" }, { "text": "field1", "type": "mrkdwn" }, { "text": "field2", "type": "mrkdwn" }, { "text": "field3", "type": "mrkdwn" }, { "text": "field4", "type": "mrkdwn" }, ], "type": "section", }, SectionBlock(text="some text", fields=[f"field{i}" for i in range(5)]).to_dict(), ) button = LinkButtonElement(text="Click me!", url="http://google.com") self.assertDictEqual( { "type": "section", "text": { "text": "some text", "type": "mrkdwn" }, "accessory": button.to_dict(), }, SectionBlock(text="some text", accessory=button).to_dict(), )
def test_json(self): button = LinkButtonElement(text="button text", url="http://google.com") self.assertDictEqual( button.to_dict(), { "text": {"emoji": True, "text": "button text", "type": "plain_text"}, "url": "http://google.com", "type": "button", "action_id": button.action_id, }, )
def test_json_with_accessory(self): button = LinkButtonElement(text=PlainTextObject(text="Click me!"), url="http://google.com") section = SectionBlock(text=MarkdownTextObject(text="some text"), accessory=button).to_dict() coded = { "text": { "text": "some text", "type": "mrkdwn", "verbatim": False }, "accessory": button.to_dict(), "type": "section", } self.assertDictEqual(section, coded)