Skip to content

Commit

Permalink
🪲 fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzhak committed Apr 30, 2017
1 parent 3f7302a commit b2120a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions botstory/ast/forking_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ async def start(ctx):
def location_case():
@story.part()
def store_location(ctx):
trigger_location.receive(story_context.get_message_data(ctx))
trigger_location.receive(
story_context.get_message_attachment(ctx, 'location')['payload']
)

@story.case(match='text')
def text_case():
Expand All @@ -53,7 +55,7 @@ def after_switch(ctx):
await say_location({'x': 123, 'y': 321})

assert trigger_location.result() == {
'location': {'x': 123, 'y': 321}
'x': 123, 'y': 321
}
assert not trigger_text.result()
assert trigger_after_switch.is_triggered
Expand Down
6 changes: 5 additions & 1 deletion botstory/ast/story_context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,12 @@ def get_message_attachment(ctx, attachment_type):
logger.debug('# get_message_data(ctx)')
logger.debug(get_message_data(ctx))
attachment_list = get_message_data(ctx, 'attachments')
if attachment_list is None or len(attachment_list) == 0:
return None
attachment_list_of_type = [a for a in attachment_list if a['type'] == attachment_type]
return len(attachment_list_of_type) > 0 and attachment_list_of_type[0]
if attachment_list_of_type is None or len(attachment_list_of_type) == 0:
return None
return attachment_list_of_type[0]


def set_user_data(ctx, data):
Expand Down
5 changes: 4 additions & 1 deletion botstory/utils/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ async def location(loc, session=None, user=None, story=None):
story_context.clean_message_data({
'session': session,
'user': user,
}), 'location', loc))
}), 'attachments', [{
'type': 'location',
'payload': loc
}]))


async def pure_text(text, session=None, user=None, story=None):
Expand Down

0 comments on commit b2120a5

Please sign in to comment.