Skip to content

Commit

Permalink
fix serialization of like matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzhak committed Apr 12, 2017
1 parent b6d175e commit 6a2ca2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions botstory/middlewares/sticker/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class Like:
type = 'Sticker.Like'

def __init__(self, size=ANY_LIKE):
if size == ANY_LIKE:
if isinstance(size, list):
self.valid_likes = size
elif size == ANY_LIKE:
self.valid_likes = LIKE_STICKERS
else:
self.valid_likes = [size]
Expand All @@ -42,8 +44,8 @@ def validate(self, ctx):
return get_sticker(ctx) in self.valid_likes

def serialize(self):
return self.option
return self.valid_likes

@staticmethod
def deserialize(option):
return Match(option)
return Like(option)
7 changes: 7 additions & 0 deletions botstory/middlewares/sticker/sticker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,10 @@ def then(ctx):
})

assert trigger_likes[match_size].is_triggered


def test_serialize_like():
m_old = sticker.Like(sticker.BIG_LIKE)
m_new = matchers.deserialize(matchers.serialize(m_old))
assert isinstance(m_new, sticker.Like)
assert sticker.BIG_LIKE in m_new.valid_likes

0 comments on commit 6a2ca2f

Please sign in to comment.