Пример #1
0
    def test_buttons(self):
        btns1 = Template.Buttons(text="Title",
                                 buttons=[
                                     {
                                         'type': 'web_url',
                                         'title': 'title',
                                         'value': 'https://test.com'
                                     },
                                     {
                                         'type': 'postback',
                                         'title': 'title',
                                         'value': 'TEST_PAYLOAD'
                                     },
                                     {
                                         'type': 'phone_number',
                                         'title': 'title',
                                         'value': '+82108011'
                                     },
                                     {
                                         'type': 'element_share'
                                     },
                                 ])

        btns2 = Template.Buttons(
            text="Title",
            buttons=[
                Template.ButtonWeb(title="title", url="https://test.com"),
                Template.ButtonPostBack(title="title", payload="TEST_PAYLOAD"),
                Template.ButtonPhoneNumber(title="title", payload="+82108011"),
                Template.ButtonShare()
            ])

        self.assertEquals(utils.to_json(btns1), utils.to_json(btns2))
Пример #2
0
    def test_persistent_menu(self):
        exp = """
        {
            "persistent_menu": [
                {
                    "locale":"default",
                    "call_to_actions": [
                        {
                            "type": "postback",
                            "title": "yes",
                            "payload": "hobbang"
                        },
                        {
                            "type": "web_url",
                            "title": "url",
                            "url": "url"
                        },
                        {
                            "type": "postback",
                            "title": "ho",
                            "payload": "bbang"
                        }
                    ]
                }
            ]
        }
        """
        with MessengerAPIMock(subpath="messenger_profile",
                              expected=exp,
                              utest=self) as m:
            self.page.show_persistent_menu([{
                'type': 'postback',
                'title': 'yes',
                'payload': 'hobbang'
            }, {
                'type': 'web_url',
                'title': 'url',
                'value': 'url'
            },
                                            Template.ButtonPostBack(
                                                'ho', 'bbang')])

        with MessengerAPIMock(subpath="messenger_profile", expected=exp):
            with self.assertRaises(ValueError):
                self.page.show_persistent_menu("hi")

            with self.assertRaises(ValueError):
                self.page.show_persistent_menu([
                    Template.ButtonPhoneNumber('ho', 'bbang'),
                    Template.ButtonWeb('title', 'url')
                ])

            with self.assertRaises(ValueError):
                self.page.show_persistent_menu([{'type': 'ho'}])
Пример #3
0
 def test_button_postback(self):
     btn = Template.ButtonPostBack(title="title", payload="TEST_PAYLOAD")
     self.assertEquals(
         '{"payload": "TEST_PAYLOAD", "title": "title", "type": "postback"}',
         utils.to_json(btn))
     print(utils.to_json(btn))
Пример #4
0
 def test_localized_persistent_menu(self):
     exp = """
     {
         "persistent_menu": [
             {
                 "locale":"default",
                 "call_to_actions": [
                     {
                         "type": "postback",
                         "title": "yes",
                         "payload": "hobbang"
                     },
                     {
                         "type": "web_url",
                         "title": "url",
                         "url": "url"
                     },
                     {
                         "type": "postback",
                         "title": "ho",
                         "payload": "bbang"
                     }
                 ]
             },
             {
                 "locale":"zh_CN",
                 "call_to_actions": [
                     {
                         "type": "postback",
                         "title": "yes CN",
                         "payload": "hobbang_cn"
                     },
                     {
                         "type": "web_url",
                         "title": "url CN",
                         "url": "url_cn"
                     },
                     {
                         "type": "postback",
                         "title": "ho CN",
                         "payload": "bbang_cn"
                     }
                 ]
             }
         ]
     }
     """
     with MessengerAPIMock(subpath="messenger_profile",
                           expected=exp,
                           utest=self) as m:
         self.page.show_localized_persistent_menu([
             LocalizedObj(locale="default",
                          obj=[{
                              'type': 'postback',
                              'title': 'yes',
                              'payload': 'hobbang'
                          }, {
                              'type': 'web_url',
                              'title': 'url',
                              'value': 'url'
                          },
                               Template.ButtonPostBack('ho', 'bbang')]),
             LocalizedObj(locale="zh_CN",
                          obj=[{
                              'type': 'postback',
                              'title': 'yes CN',
                              'payload': 'hobbang_cn'
                          }, {
                              'type': 'web_url',
                              'title': 'url CN',
                              'value': 'url_cn'
                          },
                               Template.ButtonPostBack('ho CN',
                                                       'bbang_cn')]),
         ])
Пример #5
0
class buttons:
    btnmenu = [
        Template.ButtonPostBack("Serviços", "MUSIC_PAYLOAD"),
        Template.ButtonPostBack('"Produtos recreativos"',"PROD_PAYLOAD"),
        Template.ButtonPostBack("Ajuda","AJUDA_PAYLOAD")
    ]
Пример #6
0
    def test_persistent_menu(self):
        self.page.show_persistent_menu([{
            'type': 'postback',
            'title': 'yes',
            'payload': 'hobbang'
        }, {
            'type': 'web_url',
            'title': 'url',
            'value': 'url'
        },
                                        Template.ButtonPostBack('ho',
                                                                'bbang')])

        self.page._send_thread_settings.assert_called_with(
            json.dumps({
                "setting_type":
                "call_to_actions",
                "thread_state":
                "existing_thread",
                "call_to_actions": [{
                    'type': 'postback',
                    'title': 'yes',
                    'payload': 'hobbang'
                }, {
                    'type': 'web_url',
                    'title': 'url',
                    'url': 'url'
                }, {
                    'type': 'postback',
                    'title': 'ho',
                    'payload': 'bbang'
                }]
            }))

        self.page.show_persistent_menu([
            Template.ButtonPostBack('ho', 'bbang'),
            Template.ButtonWeb('title', 'url')
        ])

        self.page._send_thread_settings.assert_called_with(
            json.dumps({
                "setting_type":
                "call_to_actions",
                "thread_state":
                "existing_thread",
                "call_to_actions": [{
                    'type': 'postback',
                    'title': 'ho',
                    'payload': 'bbang'
                }, {
                    'type': 'web_url',
                    'title': 'title',
                    'url': 'url'
                }]
            }))

        with self.assertRaises(ValueError):
            self.page.show_persistent_menu("hi")

        with self.assertRaises(ValueError):
            self.page.show_persistent_menu([
                Template.ButtonPhoneNumber('ho', 'bbang'),
                Template.ButtonWeb('title', 'url')
            ])

        with self.assertRaises(ValueError):
            self.page.show_persistent_menu([{'type': 'ho'}])

        self.page.hide_persistent_menu()
        self.page._send_thread_settings.assert_called_with(
            json.dumps({
                "setting_type": "call_to_actions",
                "thread_state": "existing_thread"
            }))