Commit graph

26 commits

Author SHA1 Message Date
Abhijeet Kaur 400d46a532 bots: Move "EmbeddedBotHandler" class to "zerver/lib/bot_lib.py" file.
This would keep embedded classes for zulip at one place, that is, in
"zerver" directory. This also fixes break in PyPI package for bindings.
2017-06-21 16:01:16 -04:00
Abhijeet Kaur 3c41033d8c bots: Add a separate class "EmbeddedHandlerBots" in bot_lib.py.
Add another class for bot type as embedded bot, for bots that run directly
on Zulip server. This class uses internal 'internal_send_messages' from
actions.py instead of using the 'send_message' function from Zulip Client
class.

We haven't gone ahead with creating an abstract superclass right away.
We just have two versions for now, it would be easier to iterate a little
more on the interfaces, and then only add the superclass when we're ready
to lock down the interface.
2017-06-21 10:22:53 -04:00
Abhijeet Kaur b406150a56 bots: Rename BotHandlerApi class to ExternalBotHandler.
This change is done for better understanding of the class functionality
from its class name. Now there will be 3 different classes for bots,
namely 'ExternalBotHandler', 'FlaskBotHandler' and  'EmbeddedBotHandler'.
2017-06-21 10:22:53 -04:00
neiljp 08b4ebf597 Extend message parameters passed in check_expected_responses 2017-06-20 07:19:12 -04:00
Robert Hönig 94587db657 bots: Correctly set paths to bot modules for testing. 2017-06-19 07:11:08 -04:00
Tim Abbott 107bbff769 mypy: Fix likely typeshed warning with readfp. 2017-06-15 03:42:05 -07:00
Robert Hönig 6e44c1bb88 bots: Check existance of config file in get_config_info(). 2017-06-15 02:17:31 -07:00
Robert Hönig 84c1827291 bots: Test get_config_info with giphy bot.
This involves both using the new `initialize`
method for calling `get_config_info`, and
refactoring the testing framework by adding a
way for mocking this method.
2017-06-14 20:25:07 -07:00
Robert Hönig f4369fe013 bots: tests: Mock bots only once.
This is done by moving the mocking and patching
code to the `setUp` and `tearDown` functions.
2017-06-14 20:25:07 -07:00
Robert Hönig 8fba251b69 bots: Add get_config_info function for bots. 2017-06-14 20:25:07 -07:00
Robert Hönig acd71fb96e bots: Add non-obligatory initialize func for bots.
A bot that implements `initialize(client)` has initial
access to the `client` object, before `handle_message`
is called.
2017-06-14 20:25:07 -07:00
Robert Hönig fcb4cf6721 bots: Rename BotHandlerApi object client to bot_handler. 2017-06-13 11:13:23 -07:00
Robert Hönig c193443541 bots: Move mock http conversations to fixtures. 2017-06-13 09:22:35 -07:00
Robert Hönig 01c363317e bots: tests: Move http mock to context manager.
This commit decouples the http mock conversation
feature from assert_bot_response(), and moves it
to the context manager mock_http_conversation().
This allows a modular design with context managers
that could be added for assert_bot_response().
2017-06-09 05:25:17 -05:00
Tim Abbott a9bb0c9417 test-bots: Fail if a bot is missing __init__.py. 2017-06-08 09:21:12 -07:00
neiljp 225328e3af Switch back to single suite of tests & add --exclude option 2017-06-08 09:18:24 -07:00
Tim Abbott f94bfd6de4 test-bots: Fix lint errors. 2017-06-07 14:02:27 -07:00
derAnfaenger 8f2fc6069d bots: Refactor and simplify bot_test_lib.py.
This commit integrates the mock_test function in
check_expected_responses and makes this function usable
for simple tests only by not allowing mock http conversations.

assert_bot_response() is now used for single message-response pairs,
resolving potential issues with multiple messages and a single http
request-response pair.

The giphy bot test file is updated accordingly.
2017-06-06 23:06:40 -07:00
neiljp 894a816618 test-bots: Enable list of bots to test & check for valid bot names. 2017-06-06 22:29:57 -07:00
Tim Abbott d0e5447cd0 bots: Refactor bot testing library to still support un-mocked HTTP.
Several of our bots haven't been converted to have mock responses for
third-party APIs yet, and we may want that code path for with-network
testing anyway.
2017-06-05 15:11:46 -07:00
Abhijeet Kaur 919db13fa8 bots: Add mock test support for bots using internet services.
Mock requests.get function for bots relying on external services
which may return different results. 'http_response' is mocked to
check if the bots run well and to make the tests determinitic. The
code first checks if the http request corresponding to the http response
is called or not.

This commit renders test files of bots using the internet
(third party) services to Fail. As requests.get() is replaced
by our mock function.

Since we have not provided mock http response for bots like xkcd,
wikipedia, define etc. Their requests.get() function returns empty
message.
2017-06-05 15:11:24 -07:00
Aditya Bansal 72ddcc1902 pep8: Add compliance with rule E261 bots_test_lib.py. 2017-06-04 09:18:22 -07:00
Aditya Bansal dd50dc3a33 pep8: Add compliance with rule E261 test-bots. 2017-06-04 15:00:58 +05:30
Aditya Bansal 60e8943ed2 pep8: Add compliance with rule E261 bot_lib.py. 2017-06-04 15:00:42 +05:30
Abhijeet Kaur e857a97427 bots: Add mock test for 'send_message' function in 'bots_test_lib' file.
Since few bots directly call 'send_message' function of
'BotHandlerApi' class instead of calling 'send_reply' function
first, add 'mock_test_send_message' to check for 'send_message'
function.

All test_<bot>.py files now need to specify which function the bot
will be sending the response to, for each particular message.

Make 'test_virtual_fs.py' and 'test_thesaurus.py' test files
consistent with other bots.
2017-06-02 17:24:41 -07:00
Rohitt Vashishtha 894adb1e43 bots: Move contrib_bots to api/bots*.
This will make it convenient to include these bots in Zulip API
releases on pypi.

Fix #5009.
2017-06-01 12:31:54 -07:00