コード例 #1
0
 def test_section_set_hero_image(self):
     section = Section()
     section.set_hero_image(HeroImage(URL, "Test"))
     self.assertDictEqual(section.as_data(),
                          {"heroImage": {
                              "image": URL,
                              "title": "Test"
                          }})
コード例 #2
0
 def test_section(self):
     hero_image = HeroImage("https://www.example.com/image.png", "Image")
     facts = [Fact("First name", "John"), Fact("Last name", "Johnson")]
     actions = [
         OpenUri("Open",
                 targets=[
                     ActionTarget(OSType.DEFAULT,
                                  "https://www.sample.com/"),
                 ]),
     ]
     section = Section(start_group=True,
                       title="Section title",
                       text="Duis aute irure dolor",
                       activity_image=URL,
                       activity_title="Activity",
                       activity_subtitle="sample subtitle",
                       activity_text="asdf",
                       hero_image=hero_image,
                       facts=facts,
                       actions=actions)
     self.assertDictEqual(
         section.as_data(), {
             "startGroup":
             True,
             "title":
             "Section title",
             "text":
             "Duis aute irure dolor",
             "activityImage":
             URL,
             "activityTitle":
             "Activity",
             "activitySubtitle":
             "sample subtitle",
             "activityText":
             "asdf",
             "heroImage": {
                 "image": "https://www.example.com/image.png",
                 "title": "Image"
             },
             "facts": [{
                 "name": "First name",
                 "value": "John"
             }, {
                 "name": "Last name",
                 "value": "Johnson"
             }],
             "potentialAction": [{
                 "@type":
                 "OpenUri",
                 "name":
                 "Open",
                 "targets": [{
                     "os": "default",
                     "uri": "https://www.sample.com/"
                 }]
             }]
         })
コード例 #3
0
 def test_section_set_activity(self):
     section = Section()
     section.set_activity(image=URL,
                          title="Activity",
                          subtitle="Activity subtitle",
                          text="qwertz")
     self.assertDictEqual(
         section.as_data(), {
             "activityImage": URL,
             "activityTitle": "Activity",
             "activitySubtitle": "Activity subtitle",
             "activityText": "qwertz"
         })
コード例 #4
0
 def test_section_add_facts(self):
     section = Section()
     section.add_facts([Fact("first", "1st"), Fact("second", "2nd")])
     self.assertDictEqual(
         section.as_data(), {
             "facts": [{
                 "name": "first",
                 "value": "1st"
             }, {
                 "name": "second",
                 "value": "2nd"
             }]
         })
     section.add_facts(Fact("third", "3rd"))
     self.assertDictEqual(
         section.as_data(), {
             "facts": [{
                 "name": "first",
                 "value": "1st"
             }, {
                 "name": "second",
                 "value": "2nd"
             }, {
                 "name": "third",
                 "value": "3rd"
             }]
         })
コード例 #5
0
ファイル: models.py プロジェクト: ez-einsatz/ez
 def message_card(self):
     message_card = MessageCard(title=str(self),
                                summary=str(self),
                                theme_color="666666")
     message_card.add_sections(
         Section(facts=[
             Fact("Absender:", self.absender),
             Fact("Anschrift:", self.anschrift),
         ], ))
     message_card.add_sections(Section(text=self.inhalt, ))
     message_card.add_actions([
         OpenUri(name="Anzeigen",
                 targets=[
                     ActionTarget(
                         OSType.DEFAULT,
                         settings.BASE_URL + self.get_absolute_url())
                 ])
     ])
     return message_card
コード例 #6
0
 def test_section_add_potential_actions(self):
     section = Section()
     actions = [
         HttpPOST("Open", target=URL),
         HttpPOST("Click", target="www.example.com", body="asdf")
     ]
     section.add_potential_actions(actions)
     self.assertDictEqual(
         section.as_data(), {
             "potentialAction": [{
                 "@type": "HttpPOST",
                 "name": "Open",
                 "target": URL
             }, {
                 "@type": "HttpPOST",
                 "name": "Click",
                 "target": "www.example.com",
                 "body": "asdf"
             }]
         })
     action = OpenUri("View",
                      targets=[
                          ActionTarget(OSType.IOS,
                                       "http://www.example.com/"),
                      ])
     section.add_potential_actions(action)
     self.assertDictEqual(
         section.as_data(), {
             "potentialAction":
             [{
                 "@type": "HttpPOST",
                 "name": "Open",
                 "target": URL
             }, {
                 "@type": "HttpPOST",
                 "name": "Click",
                 "target": "www.example.com",
                 "body": "asdf"
             }, {
                 "@type": "OpenUri",
                 "name": "View",
                 "targets": [{
                     "os": "iOS",
                     "uri": "http://www.example.com/"
                 }]
             }]
         })
コード例 #7
0
 def test_section_set_activity_empty(self):
     section = Section()
     section.set_activity()
     self.assertDictEqual(section.as_data(), {})
コード例 #8
0
from django_actionable_messages.message_card.utils import OSType
"""
Trello - card created
https://messagecardplayground.azurewebsites.net/
"""

trello_card = MessageCard(title="Card created: \"Name of card\"",
                          summary="Card \"Test card\"",
                          theme_color="0078D7")
trello_card.add_sections([
    Section(
        activity_title="Miguel Garcia",
        activity_subtitle="9/13/2016, 3:34pm",
        activity_image=
        "https://connectorsdemo.azurewebsites.net/images/MSC12_Oscar_002.jpg",
        facts=[
            Fact("Board:", "Name of board"),
            Fact("List:", "Name of list"),
            Fact("Assigned to:", "(none)"),
            Fact("Due date:", "(none)")
        ])
])
trello_card.add_actions([
    ActionCard(name="Set due date",
               inputs=[DateInput(input_id="dueDate", title="select a date")],
               actions=[HttpPOST("OK", target="http://...")]),
    ActionCard(name="Move",
               inputs=[
                   MultiChoiceInput(input_id="move",
                                    title="Pick a list",
                                    choices=[
コード例 #9
0
 def test_section_set_text(self):
     section = Section()
     section.set_text("Excepteur sint occaecat cupidatat non proident")
     self.assertDictEqual(
         section.as_data(),
         {"text": "Excepteur sint occaecat cupidatat non proident"})
コード例 #10
0
 def test_section_set_title(self):
     section = Section()
     section.set_title("Section title")
     self.assertDictEqual(section.as_data(), {"title": "Section title"})
コード例 #11
0
 def test_section_start_group(self):
     section = Section()
     section.set_start_group()
     self.assertDictEqual(section.as_data(), {"startGroup": True})
コード例 #12
0
https://messagecardplayground.azurewebsites.net/
"""

tiny_pulse = MessageCard(summary="Poll: What do you love about your job?",
                         theme_color="E81123")
tiny_pulse.add_sections([
    HeroImage(
        "https://messagecardplayground.azurewebsites.net/assets/TINYPulseEngageBanner.png"
    ),
    Section(
        start_group=True,
        activity_title="*What do you love about your job?**",
        activity_text=
        "It can be nothing, everything, and anything in between. Sharing is caring.",
        actions=[
            ActionCard(name="Yes",
                       inputs=[
                           TextInput(input_id="comment",
                                     is_multiline=True,
                                     title="Feel free to elaborate")
                       ],
                       actions=[
                           HttpPOST("Answer anonymously",
                                    target="http://...",
                                    is_primary=True)
                       ])
        ]),
    Section(activity_title="**Streak: 0** surveys in a row",
            activity_subtitle="Survey expires in 15 days on 4/6/2017")
])
コード例 #13
0
"""
Github - issue opened
https://messagecardplayground.azurewebsites.net/
"""

issue_opened = MessageCard(
    title="Issue opened: \"Push notifications not working\"",
    summary="Issue 176715375",
    theme_color="0078D7")
issue_opened.add_sections(
    Section(
        activity_title="Miguel Garcie",
        activity_subtitle="9/13/2016, 11:46am",
        activity_image=
        "https://connectorsdemo.azurewebsites.net/images/MSC12_Oscar_002.jpg",
        text=
        "There is a problem with Push notifications, they don't seem to be picked up by the connector.",
        facts=[
            Fact("Repository:", "mgarcia\\test"),
            Fact("Issue #:", "176715375")
        ]))
issue_opened.add_actions([
    ActionCard(name="Add a comment",
               inputs=[
                   TextInput(input_id="comment",
                             title="Enter a comment",
                             is_multiline=True)
               ],
               actions=[HttpPOST("OK", target="http://...")]),
    HttpPOST("Close", target="http://..."),
    OpenUri("View in Github",
コード例 #14
0
 def test_message_card(self):
     url1, url2 = "https://www.example.com", "www.sample.com"
     hero_image1, hero_image2 = HeroImage(
         "www.sample.com", "image1"), HeroImage("www.asdf.com",
                                                title="image2")
     fact1, fact2 = Fact("Value", "5"), Fact("Name", "lorem")
     action1 = OpenUri("View",
                       targets=[
                           ActionTarget(OSType.ANDROID,
                                        "http://www.android.com/"),
                       ])
     action2 = HttpPOST("Send",
                        URL,
                        headers=[
                            Header("Content-Length", 128),
                        ],
                        body="post body",
                        body_content_type="content type")
     action3 = InvokeAddInCommand("Command",
                                  "id_cmd",
                                  "show",
                                  initialization_context={
                                      "parameter1": 1,
                                      "parameter2": "blah"
                                  })
     inputs = [
         TextInput(input_id="id_text",
                   max_length=128,
                   is_multiline=True,
                   is_required=True),
     ]
     actions = [
         OpenUri("Open", targets=[
             ActionTarget(OSType.WINDOWS, URL),
         ]),
     ]
     action4 = ActionCard("Action card", inputs=inputs, actions=actions)
     section1 = Section(title="Section first",
                        activity_image=url1,
                        activity_title="Activity 1",
                        activity_subtitle="activity subtitle",
                        activity_text="asdf",
                        hero_image=hero_image1,
                        facts=[fact1, fact2],
                        actions=[action1, action3])
     section2 = Section(start_group=False,
                        title="Section second",
                        activity_image=url2,
                        activity_title="Activity 2",
                        activity_subtitle="sample subtitle",
                        activity_text="zxcv",
                        hero_image=hero_image2,
                        facts=[
                            fact2,
                        ],
                        actions=[action2, action1, action4])
     correlation_id = str(uuid.uuid4())
     message_card = MessageCard(title="Message card",
                                text="asdf",
                                summary="sample summary",
                                originator="asdf",
                                theme_color="0faabbff",
                                correlation_id=correlation_id,
                                auto_correlation_id=False,
                                expected_actors=["*****@*****.**", "*****@*****.**"],
                                hide_original_body=True,
                                sections=[section1, section2],
                                actions=[
                                    action1,
                                ])
     self.assertDictEqual(
         message_card.payload, {
             "@type":
             "MessageCard",
             "@context":
             "https://schema.org/extensions",
             "title":
             "Message card",
             "text":
             "asdf",
             "summary":
             "sample summary",
             "themeColor":
             "0faabbff",
             "correlationId":
             correlation_id,
             "expectedActors": ["*****@*****.**", "*****@*****.**"],
             "hideOriginalBody":
             True,
             "originator":
             "asdf",
             "sections": [{
                 "title":
                 "Section first",
                 "activityImage":
                 url1,
                 "activityTitle":
                 "Activity 1",
                 "activitySubtitle":
                 "activity subtitle",
                 "activityText":
                 "asdf",
                 "heroImage": {
                     "image": "www.sample.com",
                     "title": "image1"
                 },
                 "facts": [{
                     "name": "Value",
                     "value": "5"
                 }, {
                     "name": "Name",
                     "value": "lorem"
                 }],
                 "potentialAction": [{
                     "@type":
                     "OpenUri",
                     "name":
                     "View",
                     "targets": [{
                         "os": "android",
                         "uri": "http://www.android.com/"
                     }]
                 }, {
                     "@type": "InvokeAddInCommand",
                     "name": "Command",
                     "addInId": "id_cmd",
                     "desktopCommandId": "show",
                     "initializationContext": {
                         "parameter1": 1,
                         "parameter2": "blah"
                     }
                 }]
             }, {
                 "title":
                 "Section second",
                 "activityImage":
                 url2,
                 "activityTitle":
                 "Activity 2",
                 "activitySubtitle":
                 "sample subtitle",
                 "activityText":
                 "zxcv",
                 "heroImage": {
                     "image": "www.asdf.com",
                     "title": "image2"
                 },
                 "facts": [{
                     "name": "Name",
                     "value": "lorem"
                 }],
                 "potentialAction": [
                     {
                         "@type": "HttpPOST",
                         "name": "Send",
                         "target": URL,
                         "headers": [{
                             "name": "Content-Length",
                             "value": 128
                         }],
                         "body": "post body",
                         "bodyContentType": "content type"
                     }, {
                         "@type":
                         "OpenUri",
                         "name":
                         "View",
                         "targets": [{
                             "os": "android",
                             "uri": "http://www.android.com/"
                         }]
                     }, {
                         "@type":
                         "ActionCard",
                         "name":
                         "Action card",
                         "inputs": [{
                             "@type": "TextInput",
                             "id": "id_text",
                             "isRequired": True,
                             "isMultiline": True,
                             "maxLength": 128
                         }],
                         "actions": [{
                             "@type":
                             "OpenUri",
                             "name":
                             "Open",
                             "targets": [{
                                 "os": "windows",
                                 "uri": URL
                             }]
                         }]
                     }
                 ]
             }],
             "potentialAction": [{
                 "@type":
                 "OpenUri",
                 "name":
                 "View",
                 "targets": [{
                     "os": "android",
                     "uri": "http://www.android.com/"
                 }]
             }]
         })
     self.assertDictEqual(json.loads(message_card.json_payload),
                          message_card.payload)
     self.assertIn("application/ld+json", message_card.html_payload)
コード例 #15
0
 def test_section_set_activity_text(self):
     section = Section()
     section.set_activity_text("Asdf zxcv")
     self.assertDictEqual(section.as_data(), {"activityText": "Asdf zxcv"})
コード例 #16
0
 def test_section_set_activity_subtitle(self):
     section = Section()
     section.set_activity_subtitle("Subtitle")
     self.assertDictEqual(section.as_data(),
                          {"activitySubtitle": "Subtitle"})
コード例 #17
0
 def test_section_set_activity_image(self):
     section = Section()
     section.set_activity_image("https://www.example.com/")
     self.assertDictEqual(section.as_data(),
                          {"activityImage": "https://www.example.com/"})
コード例 #18
0
 def test_section_set_activity_title(self):
     section = Section()
     section.set_activity_title("Example")
     self.assertDictEqual(section.as_data(), {"activityTitle": "Example"})
コード例 #19
0
 def test_message_card_add_sections(self):
     hero_image = HeroImage("www.zxcv.com", title="image2")
     fact1, fact2 = Fact("Value", "normal"), Fact("Lorem", "ipsum")
     action1 = OpenUri("View",
                       targets=[
                           ActionTarget(OSType.ANDROID,
                                        "http://www.android.com/"),
                       ])
     action2 = HttpPOST("Send",
                        URL,
                        headers=[
                            Header("Content-Length", 16),
                        ],
                        body="post body",
                        body_content_type="content type")
     action3 = OpenUri("Click",
                       targets=[
                           ActionTarget(OSType.DEFAULT,
                                        "http://www.example.com/"),
                       ])
     section1 = Section(title="Sample section",
                        activity_image="www.example.com",
                        activity_title="Activity title",
                        activity_subtitle="activity subtitle",
                        activity_text="zxcv",
                        hero_image=hero_image,
                        facts=[fact1, fact2],
                        actions=[action1, action2])
     section2 = Section(title="Section 9",
                        activity_image="www.section.com",
                        activity_title="Activity",
                        activity_subtitle="activity qwer",
                        activity_text="asdf",
                        hero_image=hero_image,
                        facts=[
                            fact1,
                        ],
                        actions=[
                            action3,
                        ])
     section3 = Section(title="Section 3",
                        activity_image="www.section3.com",
                        activity_title="Activity",
                        activity_subtitle="activity zxcv",
                        activity_text="zxcv",
                        hero_image=hero_image,
                        facts=[
                            fact2,
                        ],
                        actions=[
                            action1,
                        ])
     message_card = MessageCard(auto_correlation_id=False)
     message_card.add_sections([section1, section2])
     self.assertDictEqual(
         message_card.payload, {
             "@type":
             "MessageCard",
             "@context":
             "https://schema.org/extensions",
             "sections": [{
                 "title":
                 "Sample section",
                 "activityImage":
                 "www.example.com",
                 "activityTitle":
                 "Activity title",
                 "activitySubtitle":
                 "activity subtitle",
                 "activityText":
                 "zxcv",
                 "heroImage": {
                     "image": "www.zxcv.com",
                     "title": "image2"
                 },
                 "facts": [{
                     "name": "Value",
                     "value": "normal"
                 }, {
                     "name": "Lorem",
                     "value": "ipsum"
                 }],
                 "potentialAction": [
                     {
                         "@type":
                         "OpenUri",
                         "name":
                         "View",
                         "targets": [{
                             "os": "android",
                             "uri": "http://www.android.com/"
                         }]
                     }, {
                         "@type": "HttpPOST",
                         "name": "Send",
                         "target": URL,
                         "headers": [{
                             "name": "Content-Length",
                             "value": 16
                         }],
                         "body": "post body",
                         "bodyContentType": "content type"
                     }
                 ]
             }, {
                 "title":
                 "Section 9",
                 "activityImage":
                 "www.section.com",
                 "activityTitle":
                 "Activity",
                 "activitySubtitle":
                 "activity qwer",
                 "activityText":
                 "asdf",
                 "heroImage": {
                     "image": "www.zxcv.com",
                     "title": "image2"
                 },
                 "facts": [{
                     "name": "Value",
                     "value": "normal"
                 }],
                 "potentialAction": [{
                     "@type":
                     "OpenUri",
                     "name":
                     "Click",
                     "targets": [{
                         "os": "default",
                         "uri": "http://www.example.com/"
                     }]
                 }]
             }]
         })
     message_card.add_sections(section3)
     self.assertDictEqual(
         message_card.payload, {
             "@type":
             "MessageCard",
             "@context":
             "https://schema.org/extensions",
             "sections": [{
                 "title":
                 "Sample section",
                 "activityImage":
                 "www.example.com",
                 "activityTitle":
                 "Activity title",
                 "activitySubtitle":
                 "activity subtitle",
                 "activityText":
                 "zxcv",
                 "heroImage": {
                     "image": "www.zxcv.com",
                     "title": "image2"
                 },
                 "facts": [{
                     "name": "Value",
                     "value": "normal"
                 }, {
                     "name": "Lorem",
                     "value": "ipsum"
                 }],
                 "potentialAction": [
                     {
                         "@type":
                         "OpenUri",
                         "name":
                         "View",
                         "targets": [{
                             "os": "android",
                             "uri": "http://www.android.com/"
                         }]
                     }, {
                         "@type": "HttpPOST",
                         "name": "Send",
                         "target": URL,
                         "headers": [{
                             "name": "Content-Length",
                             "value": 16
                         }],
                         "body": "post body",
                         "bodyContentType": "content type"
                     }
                 ]
             }, {
                 "title":
                 "Section 9",
                 "activityImage":
                 "www.section.com",
                 "activityTitle":
                 "Activity",
                 "activitySubtitle":
                 "activity qwer",
                 "activityText":
                 "asdf",
                 "heroImage": {
                     "image": "www.zxcv.com",
                     "title": "image2"
                 },
                 "facts": [{
                     "name": "Value",
                     "value": "normal"
                 }],
                 "potentialAction": [{
                     "@type":
                     "OpenUri",
                     "name":
                     "Click",
                     "targets": [{
                         "os": "default",
                         "uri": "http://www.example.com/"
                     }]
                 }]
             }, {
                 "title":
                 "Section 3",
                 "activityImage":
                 "www.section3.com",
                 "activityTitle":
                 "Activity",
                 "activitySubtitle":
                 "activity zxcv",
                 "activityText":
                 "zxcv",
                 "heroImage": {
                     "image": "www.zxcv.com",
                     "title": "image2"
                 },
                 "facts": [{
                     "name": "Lorem",
                     "value": "ipsum"
                 }],
                 "potentialAction": [{
                     "@type":
                     "OpenUri",
                     "name":
                     "View",
                     "targets": [{
                         "os": "android",
                         "uri": "http://www.android.com/"
                     }]
                 }]
             }]
         })
コード例 #20
0
"""
Microsoft - flow approval
https://messagecardplayground.azurewebsites.net/
"""


flow_approval = MessageCard(summary="This is the summary property", theme_color="0075FF")
flow_approval.add_sections([
    HeroImage("https://messagecardplayground.azurewebsites.net/assets/FlowLogo.png"),
    Section(
        start_group=True,
        title="**Pending approval**",
        activity_image="https://connectorsdemo.azurewebsites.net/images/MSC12_Oscar_002.jpg",
        activity_title="Requested by **Miguel Garcia**",
        activity_subtitle="*****@*****.**",
        facts=[
            Fact("Date submitted:", "06/27/2017, 2:44 PM"),
            Fact("Details:", "Please approve the awesome changes I made to this fantastic document."),
            Fact("Link:", "[Link to the awesome document.pptx](https://awesomedocument)"),
        ]
    ),
    Section(
        actions=[
            ActionCard(
                name="Approve",
                inputs=[
                    TextInput(input_id="comment", is_multiline=True, title="Reason (optional)")
                ],
                actions=[
                    HttpPOST("OK", target="http://...")
                ]