Skip to content

Commit

Permalink
Merge pull request #36 from anton-nayshtut/square_image
Browse files Browse the repository at this point in the history
Generic Template: image_aspect_ratio supported
  • Loading branch information
Anton Nayshtut authored Sep 26, 2017
2 parents bc103e3 + acc8743 commit f75cf34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions fbmq/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ def __init__(self):


class Generic(object):
def __init__(self, elements):
def __init__(self, elements, square_image=False):
self.type = 'template'
self.payload = {
'template_type': 'generic',
'elements': elements
'elements': elements,
'image_aspect_ratio': 'square' if square_image else 'horizontal'
}


Expand Down
13 changes: 12 additions & 1 deletion tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,22 @@ def test_generic(self):
image_url='https://test.com/img',
buttons=[
{'type': 'web_url', 'title': 'title', 'value': 'https://test.com'}])])
self.assertEquals(
'{"payload": {"elements": [{"buttons": [{"title": "title", "type": "web_url", "url": "https://test.com"}],'
' "image_url": "https://test.com/img", "item_url": "https://test.com", "subtitle": "subtitle",'
' "title": "generic"}], "image_aspect_ratio": "horizontal", "template_type": "generic"}, "type": "template"}', utils.to_json(generic))

def test_generic_square_image(self):
generic = Template.Generic(
elements=[Template.GenericElement(title='generic', subtitle='subtitle', item_url='https://test.com',
image_url='https://test.com/img',
buttons=[
{'type': 'web_url', 'title': 'title', 'value': 'https://test.com'}])],
square_image=True)
self.assertEquals(
'{"payload": {"elements": [{"buttons": [{"title": "title", "type": "web_url", "url": "https://test.com"}],'
' "image_url": "https://test.com/img", "item_url": "https://test.com", "subtitle": "subtitle",'
' "title": "generic"}], "template_type": "generic"}, "type": "template"}', utils.to_json(generic))
' "title": "generic"}], "image_aspect_ratio": "square", "template_type": "generic"}, "type": "template"}', utils.to_json(generic))

def test_list(self):
listt = Template.List(
Expand Down

0 comments on commit f75cf34

Please sign in to comment.