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))
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'}])
def test_button_phone(self): btn = Template.ButtonPhoneNumber(title="title", payload="+82108011") self.assertEquals( '{"payload": "+82108011", "title": "title", "type": "phone_number"}', utils.to_json(btn)) print(utils.to_json(btn))
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" }))