Пример #1
0
    def test_localized_greeting(self):
        exp = """
            {
                "greeting": [
                    {
                        "locale":"default",
                        "text":"hello"
                    },
                    {
                        "locale":"en_US",
                        "text":"hello US"
                    }
                ]
            }
            """
        with MessengerAPIMock(subpath="messenger_profile",
                              expected=exp,
                              utest=self) as m:
            self.page.localized_greeting([
                LocalizedObj(locale="default", obj="hello"),
                LocalizedObj(locale="en_US", obj="hello US")
            ])

        with MessengerAPIMock(subpath="messenger_profile"):
            with self.assertRaises(ValueError):
                self.page.localized_greeting(
                    [LocalizedObj(locale="bad", obj="hello")])
Пример #2
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')]),
         ])