示例#1
0
 def test_json_with_block_id(self):
     self.assertDictEqual(
         {"type": "divider", "block_id": "foo"},
         DividerBlock(block_id="foo").to_dict(),
     )
     self.assertDictEqual(
         {"type": "divider", "block_id": "foo"},
         DividerBlock(**{"type": "divider", "block_id": "foo"}).to_dict(),
     )
 def test_eq(self):
     input = {
         "type": "modal",
         "blocks": [DividerBlock()],
     }
     another_input = {
         "type": "modal",
         "blocks": [DividerBlock(), DividerBlock()],
     }
     self.assertEqual(View(**input), View(**input))
     self.assertNotEqual(View(**input), View(**another_input))
示例#3
0
 async def test_view_update_2(self):
     ack = AsyncAck()
     response: BoltResponse = await ack(
         response_action="update",
         view=View(
             type="modal",
             callback_id="view-id",
             title=PlainTextObject(text="My App"),
             close=PlainTextObject(text="Cancel"),
             blocks=[DividerBlock(block_id="b")],
         ),
     )
     assert (response.status, response.body) == (
         200,
         ""
         '{"response_action": "update", '
         '"view": {'
         '"blocks": [{"block_id": "b", "type": "divider"}], '
         '"callback_id": "view-id", '
         '"close": {"text": "Cancel", "type": "plain_text"}, '
         '"title": {"text": "My App", "type": "plain_text"}, '
         '"type": "modal"'
         "}"
         "}",
     )
示例#4
0
 def test_close_in_home_tab(self):
     modal_view = View(
         type="home",
         callback_id="home-tab-id",
         close=PlainTextObject(text="Cancel"),
         blocks=[DividerBlock()],
     )
     with self.assertRaises(SlackObjectFormationError):
         modal_view.validate_json()
示例#5
0
def divider_block():
    """
    Generate divider block.

    Returns:
        dict: View block with a divider.

    """
    return DividerBlock().to_dict()
 def test_home_tab_construction(self):
     home_tab_view = View(
         type="home",
         blocks=[
             SectionBlock(
                 text=MarkdownTextObject(
                     text="*Here's what you can do with Project Tracker:*"
                 ),
             ),
             ActionsBlock(
                 elements=[
                     ButtonElement(
                         text=PlainTextObject(text="Create New Task", emoji=True),
                         style="primary",
                         value="create_task",
                     ),
                     ButtonElement(
                         text=PlainTextObject(text="Create New Project", emoji=True),
                         value="create_project",
                     ),
                     ButtonElement(
                         text=PlainTextObject(text="Help", emoji=True),
                         value="help",
                     ),
                 ],
             ),
             ContextBlock(
                 elements=[
                     ImageElement(
                         image_url="https://api.slack.com/img/blocks/bkb_template_images/placeholder.png",
                         alt_text="placeholder",
                     ),
                 ],
             ),
             SectionBlock(
                 text=MarkdownTextObject(text="*Your Configurations*"),
             ),
             DividerBlock(),
             SectionBlock(
                 text=MarkdownTextObject(
                     text="*#public-relations*\n<fakelink.toUrl.com|PR Strategy 2019> posts new tasks, comments, and project updates to <fakelink.toChannel.com|#public-relations>"
                 ),
                 accessory=ButtonElement(
                     text=PlainTextObject(text="Edit", emoji=True),
                     value="public-relations",
                 ),
             ),
         ],
     )
     home_tab_view.validate_json()
 def test_with_blocks(self):
     url = os.environ[SLACK_SDK_TEST_INCOMING_WEBHOOK_URL]
     webhook = WebhookClient(url)
     response = webhook.send(
         text="fallback",
         blocks=[
             SectionBlock(
                 block_id="sb-id",
                 text=MarkdownTextObject(
                     text="This is a mrkdwn text section block."),
                 fields=[
                     PlainTextObject(text="*this is plain_text text*",
                                     emoji=True),
                     MarkdownTextObject(text="*this is mrkdwn text*"),
                     PlainTextObject(text="*this is plain_text text*",
                                     emoji=True),
                 ],
             ),
             DividerBlock(),
             ActionsBlock(elements=[
                 ButtonElement(
                     text=PlainTextObject(text="Create New Task",
                                          emoji=True),
                     style="primary",
                     value="create_task",
                 ),
                 ButtonElement(
                     text=PlainTextObject(text="Create New Project",
                                          emoji=True),
                     value="create_project",
                 ),
                 ButtonElement(
                     text=PlainTextObject(text="Help", emoji=True),
                     value="help",
                 ),
             ], ),
         ],
     )
     self.assertEqual(200, response.status_code)
     self.assertEqual("ok", response.body)
示例#8
0
 def test_valid_construction(self):
     modal_view = View(
         type="modal",
         callback_id="modal-id",
         title=PlainTextObject(text="Awesome Modal"),
         submit=PlainTextObject(text="Submit"),
         close=PlainTextObject(text="Cancel"),
         blocks=[
             InputBlock(
                 block_id="b-id",
                 label=PlainTextObject(text="Input label"),
                 element=PlainTextInputElement(action_id="a-id"),
             ),
             InputBlock(
                 block_id="cb-id",
                 label=PlainTextObject(text="Label"),
                 element=CheckboxesElement(
                     action_id="a-cb-id",
                     options=[
                         Option(
                             text=PlainTextObject(
                                 text="*this is plain_text text*"),
                             value="v1",
                         ),
                         Option(
                             text=MarkdownTextObject(
                                 text="*this is mrkdwn text*"),
                             value="v2",
                         ),
                     ],
                 ),
             ),
             SectionBlock(
                 block_id="sb-id",
                 text=MarkdownTextObject(
                     text="This is a mrkdwn text section block."),
                 fields=[
                     PlainTextObject(text="*this is plain_text text*",
                                     emoji=True),
                     MarkdownTextObject(text="*this is mrkdwn text*"),
                     PlainTextObject(text="*this is plain_text text*",
                                     emoji=True),
                 ],
             ),
             DividerBlock(),
             SectionBlock(
                 block_id="rb-id",
                 text=MarkdownTextObject(
                     text=
                     "This is a section block with radio button accessory"),
                 accessory=RadioButtonsElement(
                     initial_option=Option(
                         text=PlainTextObject(text="Option 1"),
                         value="option 1",
                         description=PlainTextObject(
                             text="Description for option 1"),
                     ),
                     options=[
                         Option(
                             text=PlainTextObject(text="Option 1"),
                             value="option 1",
                             description=PlainTextObject(
                                 text="Description for option 1"),
                         ),
                         Option(
                             text=PlainTextObject(text="Option 2"),
                             value="option 2",
                             description=PlainTextObject(
                                 text="Description for option 2"),
                         ),
                     ],
                 ),
             ),
         ],
     )
     modal_view.validate_json()
示例#9
0
 def test_json(self):
     self.assertDictEqual({"type": "divider"}, DividerBlock().to_dict())
     self.assertDictEqual(
         {"type": "divider"}, DividerBlock(**{"type": "divider"}).to_dict()
     )
示例#10
0
 def test_document(self):
     input = {"type": "divider"}
     self.assertDictEqual(input, DividerBlock(**input).to_dict())
 def test_build_message_blocks2(self):
     message = _build_message(blocks=[DividerBlock(block_id="foo")])
     assert message is not None
     assert isinstance(message["blocks"][0], dict)
     assert message["blocks"][0]["block_id"] == "foo"