예제 #1
0
    def test_parse(self):
        input = {
            "type": "section",
            "text": {
                "type":
                "mrkdwn",
                "text":
                "A message *with some bold text* and _some italicized text_."
            },
            "unexpected_field": "test",
            "unexpected_fields": [1, 2, 3],
            "unexpected_object": {
                "something": "wrong"
            },
        }
        block = Block.parse(input)
        self.assertIsNotNone(block)

        self.assertDictEqual(
            {
                "type": "section",
                "text": {
                    "type":
                    "mrkdwn",
                    "text":
                    "A message *with some bold text* and _some italicized text_."
                },
            }, block.to_dict())
예제 #2
0
 def test_document_1(self):
     input = {
         "type":
         "actions",
         "block_id":
         "actions1",
         "elements": [
             {
                 "type":
                 "static_select",
                 "placeholder": {
                     "type": "plain_text",
                     "text": "Which witch is the witchiest witch?",
                 },
                 "action_id":
                 "select_2",
                 "options": [
                     {
                         "text": {
                             "type": "plain_text",
                             "text": "Matilda"
                         },
                         "value": "matilda",
                     },
                     {
                         "text": {
                             "type": "plain_text",
                             "text": "Glinda"
                         },
                         "value": "glinda",
                     },
                     {
                         "text": {
                             "type": "plain_text",
                             "text": "Granny Weatherwax"
                         },
                         "value": "grannyWeatherwax",
                     },
                     {
                         "text": {
                             "type": "plain_text",
                             "text": "Hermione"
                         },
                         "value": "hermione",
                     },
                 ],
             },
             {
                 "type": "button",
                 "text": {
                     "type": "plain_text",
                     "text": "Cancel"
                 },
                 "value": "cancel",
                 "action_id": "button_1",
             },
         ],
     }
     self.assertDictEqual(input, ActionsBlock(**input).to_dict())
     self.assertDictEqual(input, Block.parse(input).to_dict())
예제 #3
0
 def test_with_real_payload(self):
     self.maxDiff = None
     input = {
         "type": "call",
         "call_id": "R00000000",
         "api_decoration_available": False,
         "call": {
             "v1": {
                 "id": "R00000000",
                 "app_id": "A00000000",
                 "app_icon_urls": {
                     "image_32": "https://www.example.com/",
                     "image_36": "https://www.example.com/",
                     "image_48": "https://www.example.com/",
                     "image_64": "https://www.example.com/",
                     "image_72": "https://www.example.com/",
                     "image_96": "https://www.example.com/",
                     "image_128": "https://www.example.com/",
                     "image_192": "https://www.example.com/",
                     "image_512": "https://www.example.com/",
                     "image_1024": "https://www.example.com/",
                     "image_original": "https://www.example.com/",
                 },
                 "date_start": 12345,
                 "active_participants": [
                     {"slack_id": "U00000000"},
                     {
                         "slack_id": "U00000000",
                         "external_id": "",
                         "avatar_url": "https://www.example.com/",
                         "display_name": "",
                     },
                 ],
                 "all_participants": [
                     {"slack_id": "U00000000"},
                     {
                         "slack_id": "U00000000",
                         "external_id": "",
                         "avatar_url": "https://www.example.com/",
                         "display_name": "",
                     },
                 ],
                 "display_id": "",
                 "join_url": "https://www.example.com/",
                 "name": "",
                 "created_by": "U00000000",
                 "date_end": 12345,
                 "channels": ["C00000000"],
                 "is_dm_call": False,
                 "was_rejected": False,
                 "was_missed": False,
                 "was_accepted": False,
                 "has_ended": False,
                 "desktop_app_join_url": "https://www.example.com/",
             }
         },
     }
     self.assertDictEqual(input, CallBlock(**input).to_dict())
     self.assertDictEqual(input, Block.parse(input).to_dict())
예제 #4
0
 def test_document(self):
     input = {
         "type": "file",
         "external_id": "ABCD1",
         "source": "remote",
     }
     self.assertDictEqual(input, FileBlock(**input).to_dict())
     self.assertDictEqual(input, Block.parse(input).to_dict())
예제 #5
0
 def test_document(self):
     input = {
         "type": "header",
         "block_id": "budget-header",
         "text": {"type": "plain_text", "text": "Budget Performance"},
     }
     self.assertDictEqual(input, HeaderBlock(**input).to_dict())
     self.assertDictEqual(input, Block.parse(input).to_dict())
예제 #6
0
 def test_document_1(self):
     input = {
         "type": "section",
         "text": {
             "type": "mrkdwn",
             "text": "A message *with some bold text* and _some italicized text_.",
         },
     }
     self.assertDictEqual(input, SectionBlock(**input).to_dict())
     self.assertDictEqual(input, Block.parse(input).to_dict())
예제 #7
0
 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())
     self.assertDictEqual(input, Block.parse(input).to_dict())
예제 #8
0
 def test_document(self):
     input = {
         "type": "context",
         "elements": [
             {
                 "type": "image",
                 "image_url": "https://image.freepik.com/free-photo/red-drawing-pin_1156-445.jpg",
                 "alt_text": "images",
             },
             {"type": "mrkdwn", "text": "Location: **Dogpatch**"},
         ],
     }
     self.assertDictEqual(input, ContextBlock(**input).to_dict())
     self.assertDictEqual(input, Block.parse(input).to_dict())
예제 #9
0
 def test_document(self):
     blocks = [{
         "type": "input",
         "element": {
             "type": "plain_text_input"
         },
         "label": {
             "type": "plain_text",
             "text": "Label",
             "emoji": True
         },
     }, {
         "type": "input",
         "element": {
             "type": "plain_text_input",
             "multiline": True
         },
         "label": {
             "type": "plain_text",
             "text": "Label",
             "emoji": True
         },
     }, {
         "type": "input",
         "element": {
             "type": "datepicker",
             "initial_date": "1990-04-28",
             "placeholder": {
                 "type": "plain_text",
                 "text": "Select a date",
                 "emoji": True,
             },
         },
         "label": {
             "type": "plain_text",
             "text": "Label",
             "emoji": True
         },
     }, {
         "type": "input",
         "element": {
             "type": "channels_select",
             "placeholder": {
                 "type": "plain_text",
                 "text": "Select a channel",
                 "emoji": True,
             },
         },
         "label": {
             "type": "plain_text",
             "text": "Label",
             "emoji": True
         },
     }, {
         "type": "input",
         "element": {
             "type": "multi_users_select",
             "placeholder": {
                 "type": "plain_text",
                 "text": "Select users",
                 "emoji": True,
             },
         },
         "label": {
             "type": "plain_text",
             "text": "Label",
             "emoji": True
         },
     }, {
         "type": "input",
         "element": {
             "type":
             "checkboxes",
             "options": [
                 {
                     "text": {
                         "type": "plain_text",
                         "text": "*this is plain_text text*",
                         "emoji": True,
                     },
                     "value": "value-0",
                 },
                 {
                     "text": {
                         "type": "plain_text",
                         "text": "*this is plain_text text*",
                         "emoji": True,
                     },
                     "value": "value-1",
                 },
                 {
                     "text": {
                         "type": "plain_text",
                         "text": "*this is plain_text text*",
                         "emoji": True,
                     },
                     "value": "value-2",
                 },
             ],
         },
         "label": {
             "type": "plain_text",
             "text": "Label",
             "emoji": True
         },
     }, {
         "type": "input",
         "element": {
             "type": "plain_text_input",
         },
         "label": {
             "type": "plain_text",
             "text": "Label",
             "emoji": True,
         },
         "hint": {
             "type": "plain_text",
             "text": "some hint",
             "emoji": True,
         },
     }, {
         "dispatch_action": True,
         "type": "input",
         "element": {
             "type": "plain_text_input",
             "action_id": "plain_text_input-action"
         },
         "label": {
             "type": "plain_text",
             "text": "Label",
             "emoji": True
         }
     }]
     for input in blocks:
         self.assertDictEqual(input, InputBlock(**input).to_dict())
         self.assertDictEqual(input, Block.parse(input).to_dict())
예제 #10
0
 def test_document(self):
     input = {"type": "divider"}
     self.assertDictEqual(input, DividerBlock(**input).to_dict())
     self.assertDictEqual(input, Block.parse(input).to_dict())