Exemplo n.º 1
0
 def test_with_attachments(self):
     url = os.environ[SLACK_SDK_TEST_INCOMING_WEBHOOK_URL]
     webhook = WebhookClient(url)
     response = webhook.send(
         text="fallback",
         attachments=[
             Attachment(
                 text="attachment text",
                 title="Attachment",
                 fallback="fallback_text",
                 pretext="some_pretext",
                 title_link="link in title",
                 fields=[
                     AttachmentField(title=f"field_{i}_title",
                                     value=f"field_{i}_value")
                     for i in range(5)
                 ],
                 color="#FFFF00",
                 author_name="John Doe",
                 author_link="http://johndoeisthebest.com",
                 author_icon="http://johndoeisthebest.com/avatar.jpg",
                 thumb_url="thumbnail URL",
                 footer="and a footer",
                 footer_icon="link to footer icon",
                 ts=123456789,
                 markdown_in=["fields"],
             )
         ],
     )
     self.assertEqual(200, response.status_code)
     self.assertEqual("ok", response.body)
Exemplo n.º 2
0
    def test_basic_json(self):
        self.assertDictEqual(
            Attachment(text="some text").to_dict(), {"text": "some text", "fields": []}
        )

        self.assertDictEqual(
            Attachment(
                text="attachment text",
                title="Attachment",
                fallback="fallback_text",
                pretext="some_pretext",
                title_link="link in title",
                fields=[
                    AttachmentField(title=f"field_{i}_title", value=f"field_{i}_value")
                    for i in range(5)
                ],
                color="#FFFF00",
                author_name="John Doe",
                author_link="http://johndoeisthebest.com",
                author_icon="http://johndoeisthebest.com/avatar.jpg",
                thumb_url="thumbnail URL",
                footer="and a footer",
                footer_icon="link to footer icon",
                ts=123456789,
                markdown_in=["fields"],
            ).to_dict(),
            {
                "text": "attachment text",
                "author_name": "John Doe",
                "author_link": "http://johndoeisthebest.com",
                "author_icon": "http://johndoeisthebest.com/avatar.jpg",
                "footer": "and a footer",
                "title": "Attachment",
                "footer_icon": "link to footer icon",
                "pretext": "some_pretext",
                "ts": 123456789,
                "fallback": "fallback_text",
                "title_link": "link in title",
                "color": "#FFFF00",
                "thumb_url": "thumbnail URL",
                "fields": [
                    {"title": "field_0_title", "value": "field_0_value", "short": True},
                    {"title": "field_1_title", "value": "field_1_value", "short": True},
                    {"title": "field_2_title", "value": "field_2_value", "short": True},
                    {"title": "field_3_title", "value": "field_3_value", "short": True},
                    {"title": "field_4_title", "value": "field_4_value", "short": True},
                ],
                "mrkdwn_in": ["fields"],
            },
        )
Exemplo n.º 3
0
    def test_send_attachments(self):
        client = WebhookClient("http://localhost:8888")

        resp = client.send(
            text="hello!",
            response_type="ephemeral",
            attachments=[{
                "color":
                "#f2c744",
                "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",
            attachments=[
                Attachment(
                    text="attachment text",
                    title="Attachment",
                    fallback="fallback_text",
                    pretext="some_pretext",
                    title_link="link in title",
                    fields=[
                        AttachmentField(title=f"field_{i}_title",
                                        value=f"field_{i}_value")
                        for i in range(5)
                    ],
                    color="#FFFF00",
                    author_name="John Doe",
                    author_link="http://johndoeisthebest.com",
                    author_icon="http://johndoeisthebest.com/avatar.jpg",
                    thumb_url="thumbnail URL",
                    footer="and a footer",
                    footer_icon="link to footer icon",
                    ts=123456789,
                    markdown_in=["fields"],
                )
            ],
        )
        self.assertEqual("ok", resp.body)
Exemplo n.º 4
0
 def test_basic_json(self):
     self.assertDictEqual(
         AttachmentField(title="field", value="something", short=False).to_dict(),
         {"title": "field", "value": "something", "short": False},
     )
Exemplo n.º 5
0
    def test_basic_json(self):
        actions = [
            ActionButton(name="button_1", text="Click me", value="button_value_1"),
            ActionLinkButton(text="navigate", url="http://google.com"),
        ]
        self.assertDictEqual(
            InteractiveAttachment(
                text="some text", callback_id="abc123", actions=actions
            ).to_dict(),
            {
                "text": "some text",
                "fields": [],
                "callback_id": "abc123",
                "actions": [a.to_dict() for a in actions],
            },
        )

        self.assertDictEqual(
            InteractiveAttachment(
                actions=actions,
                callback_id="cb_123",
                text="attachment text",
                title="Attachment",
                fallback="fallback_text",
                pretext="some_pretext",
                title_link="link in title",
                fields=[
                    AttachmentField(title=f"field_{i}_title", value=f"field_{i}_value")
                    for i in range(5)
                ],
                color="#FFFF00",
                author_name="John Doe",
                author_link="http://johndoeisthebest.com",
                author_icon="http://johndoeisthebest.com/avatar.jpg",
                thumb_url="thumbnail URL",
                footer="and a footer",
                footer_icon="link to footer icon",
                ts=123456789,
                markdown_in=["fields"],
            ).to_dict(),
            {
                "text": "attachment text",
                "callback_id": "cb_123",
                "actions": [a.to_dict() for a in actions],
                "author_name": "John Doe",
                "author_link": "http://johndoeisthebest.com",
                "author_icon": "http://johndoeisthebest.com/avatar.jpg",
                "footer": "and a footer",
                "title": "Attachment",
                "footer_icon": "link to footer icon",
                "pretext": "some_pretext",
                "ts": 123456789,
                "fallback": "fallback_text",
                "title_link": "link in title",
                "color": "#FFFF00",
                "thumb_url": "thumbnail URL",
                "fields": [
                    {"title": "field_0_title", "value": "field_0_value", "short": True},
                    {"title": "field_1_title", "value": "field_1_value", "short": True},
                    {"title": "field_2_title", "value": "field_2_value", "short": True},
                    {"title": "field_3_title", "value": "field_3_value", "short": True},
                    {"title": "field_4_title", "value": "field_4_value", "short": True},
                ],
                "mrkdwn_in": ["fields"],
            },
        )