Exemplo n.º 1
0
 def test_button_template_with_multiple_buttons(self):
     btn = elements.Button(button_type='web_url',
                           title='Web button',
                           url='http://facebook.com')
     btn2 = elements.Button(button_type='postback',
                            title='Postback button',
                            payload='payload')
     res = templates.ButtonTemplate(text='Button template',
                                    buttons=[btn, btn2])
     expected = {
         'attachment': {
             'type': 'template',
             'payload': {
                 'template_type':
                 'button',
                 'text':
                 'Button template',
                 'buttons': [{
                     'type': 'web_url',
                     'title': 'Web button',
                     'url': 'http://facebook.com'
                 }, {
                     'type': 'postback',
                     'title': 'Postback button',
                     'payload': 'payload'
                 }]
             }
         }
     }
     assert expected == res.to_dict()
Exemplo n.º 2
0
 def test_button_template_with_no_buttons(self):
     with pytest.raises(ValueError) as err:
         res = templates.ButtonTemplate(
             text='Button template',
             buttons=[],
         )
         res.to_dict()
     assert str(err.value) == 'At least 1 buttons are required.'
Exemplo n.º 3
0
 def test_button_template_with_too_many_buttons(self):
     btn = elements.Button(button_type='web_url', title='Web button', url='http://facebook.com')
     with pytest.raises(ValueError) as err:
         res = templates.ButtonTemplate(
             text='Button template',
             buttons=[btn]*4,
         )
         res.to_dict()
     assert str(err.value) == 'You cannot have more than 3 buttons in the template.'
Exemplo n.º 4
0
 def test_button_template_with_single_button(self):
     btn = elements.Button(button_type='web_url',
                           title='Web button',
                           url='http://facebook.com')
     res = templates.ButtonTemplate(text='Button template', buttons=btn)
     expected = {
         'attachment': {
             'type': 'template',
             'payload': {
                 'template_type':
                 'button',
                 'text':
                 'Button template',
                 'buttons': [{
                     'type': 'web_url',
                     'title': 'Web button',
                     'url': 'http://facebook.com'
                 }]
             }
         }
     }
     assert expected == res.to_dict()