def test_send_blocks(self): client = WebhookClient("http://localhost:8888") resp = client.send( text="hello!", response_type="ephemeral", blocks=[ SectionBlock(text="Some text"), ImageBlock(image_url="image.jpg", alt_text="an image"), ], ) self.assertEqual("ok", resp.body) resp = client.send( text="hello!", response_type="ephemeral", blocks=[ { "type": "section", "text": { "type": "mrkdwn", "text": "This is a mrkdwn section block :ghost: *this is bold*, and ~this is crossed out~, and <https://google.com|this is a link>", }, }, { "type": "divider" }, { "type": "section", "text": { "type": "mrkdwn", "text": "Pick a date for the deadline." }, "accessory": { "type": "datepicker", "initial_date": "1990-04-28", "placeholder": { "type": "plain_text", "text": "Select a date", }, }, }, ], ) self.assertEqual("ok", resp.body) resp = client.send( text="hello!", response_type="ephemeral", blocks=[ SectionBlock(text="Some text"), ImageBlock(image_url="image.jpg", alt_text="an image"), ], ) self.assertEqual("ok", resp.body)
def test_basic_json(self): blocks = [ SectionBlock(text="Some text"), ImageBlock(image_url="image.jpg", alt_text="an image"), ] self.assertDictEqual( BlockAttachment(blocks=blocks).to_dict(), {"blocks": [b.to_dict() for b in blocks]}, )
def test_json(self): self.assertDictEqual( { "image_url": "http://google.com", "alt_text": "not really an image", "type": "image", }, ImageBlock(image_url="http://google.com", alt_text="not really an image").to_dict(), )
def test_document(self): input = { "type": "image", "title": { "type": "plain_text", "text": "Please enjoy this photo of a kitten", }, "block_id": "image4", "image_url": "http://placekitten.com/500/500", "alt_text": "An incredibly cute kitten.", } self.assertDictEqual(input, ImageBlock(**input).to_dict())
def test_issue_919_response_url_flag_options(self): client = WebhookClient("http://localhost:8888") resp = client.send( text="hello!", response_type="ephemeral", replace_original=True, blocks=[ SectionBlock(text="Some text"), ImageBlock(image_url="image.jpg", alt_text="an image"), ], ) self.assertEqual("ok", resp.body) resp = client.send( text="hello!", response_type="ephemeral", delete_original=True, blocks=[ SectionBlock(text="Some text"), ImageBlock(image_url="image.jpg", alt_text="an image"), ], ) self.assertEqual("ok", resp.body)
def test_title_length(self): with self.assertRaises(SlackObjectFormationError): ImageBlock( image_url="http://google.com", alt_text="text", title=STRING_3001_CHARS ).to_dict()
def test_image_url_length(self): with self.assertRaises(SlackObjectFormationError): ImageBlock(image_url=STRING_3001_CHARS, alt_text="text").to_dict()