Skip to content

Commit 2ff8fe1

Browse files
authored
Fix hero block in bubble container to accept box component (#274)
Resolve #273
1 parent 1753128 commit 2ff8fe1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

linebot/models/flex_message.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ def __init__(self, size=None, direction=None, header=None, hero=None,
109109
self.size = size
110110
self.direction = direction
111111
self.header = self.get_or_new_from_json_dict(header, BoxComponent)
112-
self.hero = self.get_or_new_from_json_dict(hero, ImageComponent)
112+
self.hero = self.get_or_new_from_json_dict_with_types(
113+
hero, {
114+
'image': ImageComponent,
115+
'box': BoxComponent
116+
}
117+
)
113118
self.body = self.get_or_new_from_json_dict(body, BoxComponent)
114119
self.footer = self.get_or_new_from_json_dict(footer, BoxComponent)
115120
self.styles = self.get_or_new_from_json_dict(styles, BubbleStyle)

tests/models/test_flex_message.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def test_bubble_container(self):
6161
'header':
6262
BoxComponent(layout='vertical',
6363
contents=[TextComponent(text='Header text')]),
64-
'hero':
65-
ImageComponent(uri='https://example.com/flex/images/image.jpg'),
6664
'body':
6765
BoxComponent(layout='vertical',
6866
contents=[TextComponent(text='Body text')]),
@@ -79,10 +77,17 @@ def test_bubble_container(self):
7977
separator_color='#00ffff')
8078
)
8179
}
82-
self.assertEqual(
83-
self.serialize_as_dict(arg, type=self.BUBBLE),
84-
BubbleContainer(**arg).as_json_dict()
85-
)
80+
heros = [
81+
ImageComponent(uri='https://example.com/flex/images/image.jpg'),
82+
BoxComponent(layout='vertical',
83+
contents=[TextComponent(text='Body text')]),
84+
]
85+
for hero in heros:
86+
arg['hero'] = hero
87+
self.assertEqual(
88+
self.serialize_as_dict(arg, type=self.BUBBLE),
89+
BubbleContainer(**arg).as_json_dict()
90+
)
8691

8792
def test_bubble_style(self):
8893
arg = {

0 commit comments

Comments
 (0)