def test_text_input_set_is_multiline(self):
     text_input = TextInput()
     text_input.set_is_multiline()
     self.assertDictEqual(text_input.as_data(), {
         "@type": "TextInput",
         "isMultiline": True
     })
 def test_action_card_set_name(self):
     inputs = [
         TextInput(input_id="id_text", max_length=128, is_multiline=True),
     ]
     actions = [
         OpenUri("Open", targets=[
             ActionTarget(OSType.DEFAULT, URL),
         ]),
     ]
     action_card = ActionCard("Actions", inputs=inputs, actions=actions)
     action_card.set_name("Donec")
     self.assertDictEqual(
         action_card.as_data(), {
             "@type":
             "ActionCard",
             "name":
             "Donec",
             "inputs": [{
                 "@type": "TextInput",
                 "id": "id_text",
                 "isMultiline": True,
                 "maxLength": 128
             }],
             "actions": [{
                 "@type": "OpenUri",
                 "name": "Open",
                 "targets": [{
                     "os": "default",
                     "uri": URL
                 }]
             }]
         })
 def test_text_input_set_value(self):
     text_input = TextInput()
     text_input.set_value("accumsan")
     self.assertDictEqual(text_input.as_data(), {
         "@type": "TextInput",
         "isMultiline": False,
         "value": "accumsan"
     })
 def test_text_input_set_title(self):
     text_input = TextInput()
     text_input.set_title("interdum")
     self.assertDictEqual(text_input.as_data(), {
         "@type": "TextInput",
         "isMultiline": False,
         "title": "interdum"
     })
 def test_text_input_set_id(self):
     text_input = TextInput()
     text_input.set_id("id_text_input4")
     self.assertDictEqual(text_input.as_data(), {
         "@type": "TextInput",
         "isMultiline": False,
         "id": "id_text_input4"
     })
 def test_text_input_set_max_length(self):
     text_input = TextInput()
     text_input.set_max_length(19)
     self.assertDictEqual(text_input.as_data(), {
         "@type": "TextInput",
         "isMultiline": False,
         "maxLength": 19
     })
 def test_action_card_add_inputs(self):
     action_card = ActionCard("Inputs")
     action_card.add_inputs([
         DateInput(include_time=True),
         TextInput(input_id="id_text", max_length=16, is_multiline=True)
     ])
     self.assertDictEqual(
         action_card.as_data(), {
             "@type":
             "ActionCard",
             "name":
             "Inputs",
             "inputs": [{
                 "@type": "DateInput",
                 "includeTime": True
             }, {
                 "@type": "TextInput",
                 "id": "id_text",
                 "isMultiline": True,
                 "maxLength": 16
             }]
         })
     action_card.add_inputs(TextInput(max_length=64, is_multiline=True))
     self.assertDictEqual(
         action_card.as_data(), {
             "@type":
             "ActionCard",
             "name":
             "Inputs",
             "inputs": [{
                 "@type": "DateInput",
                 "includeTime": True
             }, {
                 "@type": "TextInput",
                 "id": "id_text",
                 "isMultiline": True,
                 "maxLength": 16
             }, {
                 "@type": "TextInput",
                 "isMultiline": True,
                 "maxLength": 64
             }]
         })
 def test_text_input(self):
     text_input = TextInput(input_id="id_text", title="Title", value=5, is_required=True, max_length=8,
                            is_multiline=True)
     self.assertDictEqual(text_input.as_data(), {
         "@type": "TextInput",
         "id": "id_text",
         "title": "Title",
         "value": 5,
         "isRequired": True,
         "isMultiline": True,
         "maxLength": 8
     })
 def test_text_input_set_is_required(self):
     text_input = TextInput()
     text_input.set_is_required(False)
     self.assertDictEqual(text_input.as_data(), {
         "@type": "TextInput",
         "isMultiline": False,
         "isRequired": False
     })
     text_input.set_is_required(True)
     self.assertDictEqual(text_input.as_data(), {
         "@type": "TextInput",
         "isMultiline": False,
         "isRequired": True
     })
     text_input.set_is_required()
     self.assertDictEqual(text_input.as_data(), {
         "@type": "TextInput",
         "isMultiline": False,
         "isRequired": True
     })
示例#10
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)
示例#11
0
"""

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",
            targets=[ActionTarget(OSType.DEFAULT, "http://...")])
])
            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=[
                                        InputChoice("List 1", "l1"),
                                        InputChoice("List 2", "l2")
                                    ])
               ],
               actions=[HttpPOST("OK", target="http://...")]),
    ActionCard(name="Add a comment",
               inputs=[
                   TextInput(input_id="comment",
                             is_multiline=True,
                             title="Enter your comment")
               ],
               actions=[HttpPOST("OK", target="http://...")]),
    OpenUri("View in Trello",
            targets=[ActionTarget(OSType.DEFAULT, "http://...")])
])
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")
])
示例#14
0
     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://...")
             ]
         ),
         ActionCard(
             name="Reject",
             inputs=[
                 TextInput(input_id="comment", is_multiline=True, title="Reason (optional)")
             ],
             actions=[
                 HttpPOST("OK", target="http://...")
             ]
         )
     ]