Commit graph

1491 commits

Author SHA1 Message Date
Steve Howell 6087cf95e2 bot tests: Use StubBotTestCase in tictactoe.
Note that we now only have one conversation, since the case
of sending to streams has the same mechanics as sending PMs.

We'll eventually want a separate test to drive out differences
in the actual mechanics of the reply.
2017-12-01 07:00:20 -08:00
Steve Howell 77dbe92ad8 minor: Remove some dead code in BotTestCaseBase. 2017-12-01 07:00:20 -08:00
Steve Howell c0ceb9857f Rewrite incrementor bot tests.
Using StubBotHandler makes it fairly easy to verify the key
feature of the incrementor bot, which is that it updates
messages sequentially.
2017-12-01 07:00:20 -08:00
Steve Howell fc251460fa bot tests: Eliminate BotTestCaseBase.
We now just put `test_bot_usage` in StubBotTestCase and have
BotTestCase inherit from that.
2017-12-01 07:00:20 -08:00
Steve Howell 205f7c16c7 Add StubBotTestCase and StubBotHandler.
We will start to use these for some of our bot test code.
2017-12-01 07:00:20 -08:00
Steve Howell fe662ed145 bot tests: Split up mock_http_conversation().
This method had two pretty easy-to-separate concerns:

    * find the fixture data using our directory conventions
    * use the fixture data to simulate a real HTTP request

Part of the goal here is to make the extracted functions a
bit easier to use in other TestCase-based classes without
needing to subclass from BotTestCaseBase, which is kind of
complex with its setUp/tearDown.
2017-12-01 07:00:20 -08:00
Steve Howell 0a477b0736 Extract get_bot_message_handler(). 2017-12-01 07:00:20 -08:00
Robert Hönig 4ca11fdd67 Make venv creation with Python 2 harder.
Python 2 venvs can now only be created with
tools/provision --force.
2017-11-30 02:07:55 -08:00
neiljp (Neil Pilgrim) 1e5e931421 Tests: Extend test-lib script to support coverage parameter & add to test-main 2017-11-29 17:07:30 -08:00
neiljp (Neil Pilgrim) 39601d190c bot lib tests: Add test_send_reply. 2017-11-29 15:56:30 -08:00
Steve Howell efeac92d42 Add tools/test-lib.
This starts to add direct test coverage on
zulip_bots/zulip_bots/lib.py.

It is not yet integrated into tools/test-main.
2017-11-29 13:45:51 -08:00
neiljp (Neil Pilgrim) 3e135b8e1e bot testing: Enable testing of multiple responses from single messages. 2017-11-29 10:05:46 -08:00
Abhijeet Kaur 91c4ff668d bots: Clean up terminal.py for running bots directly.
Make terminal.py exit gracefully with a message.
Modify output bot reply for better understanding in multi-line
output.
2017-11-29 10:05:06 -08:00
Skunk 353475f245 docs: Mention Python 3 in the README. 2017-11-29 08:32:33 -08:00
Eeshan Garg c3ab265d3e packaging: Upgrade to release 0.3.9. 2017-11-29 01:23:12 -03:30
Robert Hönig 2cb43256e0 zulip_bots: Get 100% test coverage for giphy bot. 2017-11-28 15:42:22 -08:00
Robert Hönig 93edededdd zulip_bots: Use real Response object for mock_http_conversation(). 2017-11-28 15:42:22 -08:00
Robert Hönig 41d8ffc20e zulip_bots: Fix yoda bot response parsing. 2017-11-28 15:42:22 -08:00
Robert Hönig 13d181cd09 Remove Python 2.7 testing for zulip_bots and zulip_botserver. 2017-11-28 15:42:22 -08:00
Robert Hönig d6a4c02ba5 Rename bot storage endpoint from state to storage. 2017-11-28 20:41:59 +01:00
Steve Howell 80e4ef9f72 Create terminal.py to run bots in the terminal.
This program replaces zulip_bot_output.py, which had
gotten a little out of date.

It should be able to simulate a terminal conversation for
all of our bots, including those that use "advanced" features:

    third party config files: tested with giphy
    message updates: tested with incrementor
    storage: tested with virtual_fs and others
2017-11-28 10:52:13 -08:00
Steve Howell 536ba1843a Add a command line option to run.py for bot config files.
Before this change, we were looking for config files in
default locations in source control, which is not a good
place to look for them.  Now `run.py` and friends have a
command line argument where users can specify the config
files.

Note that the change to server.py is only a partial fix
to make it so that bots that don't use third party config
files won't crash.  That program needs an overhaul, anyway.
2017-11-28 10:52:13 -08:00
Steve Howell 57c90ddca0 refactor: Extract display_config_file_errors().
This will be useful for handling errors with third party
config files.
2017-11-28 10:52:13 -08:00
Steve Howell 8a15452525 bots: Require bots_details in ExternalBotHandler.
This parameter was defaulting to a dictionary, which is
a classic Python pitfall.
2017-11-28 10:52:13 -08:00
Steve Howell ef30261858 giphy: Make config_info an instance variable.
There was no reason to use a `global` here.
2017-11-28 10:52:13 -08:00
Eeshan Garg 50b5ec0f49 packages: Release 0.3.8 for all PyPI packages. 2017-11-27 23:34:38 -03:30
Robert Hönig a75f1abc60 zulip_bots: Add -c shortcut for --config-file for zulip-run-bots. 2017-11-27 16:45:37 +01:00
Robert Hönig 5894ce131f README.md: Fix typo. 2017-11-27 16:45:19 +01:00
Robert Hönig ea6ddb2312 zulip_bots: Only cache storage.get(). Don't cache put(). 2017-11-24 10:44:34 -08:00
derAnfaenger c264f7ef12 provisioning: Enhance warning for Python 2.7.
Color-highlight the warning. Use print instead
of warnings.warn (this omits unnecessary debug info).
2017-11-23 15:20:34 -08:00
derAnfaenger 819d5f6ebe provisioning: Fix real and venv Python version mixup. 2017-11-23 15:20:34 -08:00
Steve Howell a32446f557 Report client.get_profile() errors nicely (e.g. API key).
This patch is particularly useful in the scenario that your
API key is wrong or out of date, but it's targeted more
generally at any error that `client.get_profile()` reports.
2017-11-22 11:15:00 -08:00
Steve Howell 043d963a99 Fail fast for bad connections with the API and bots.
The API has aggressive retry logic for connecting to a
server, which may make sense for situation where you have
connection blips or server restarts.

When you're first connecting to the API, however, connection
failures are almost certainly a sign of misconfiguration, so
now we fail fast.

The bot lib takes advantage of this API change by catching the
ZulipError exception and exiting gracefully.
2017-11-21 14:21:04 -08:00
Steve Howell a19278da65 Handle configparser errors more gracefully. 2017-11-21 11:54:59 -08:00
Steve Howell e216a29277 minor: Extract client_name local var. 2017-11-21 11:26:12 -08:00
Steve Howell 73ebd719b2 Handle missing config files gracefully.
Before this commit, you would get a traceback if you supplied
a non-existent filename for your config file.  Now we exit
gracefully with a useful error message.
2017-11-21 10:32:45 -08:00
Steve Howell f6440e5b65 Require --config-file and simplify command line usage.
We now require users to specify where their config file is
located, and we no longer default to ~/.zuliprc.

As part of this, we needed to make the "usage" more accurate
in the command line, which I mostly achieved by cutting out
unnecessary stuff.
2017-11-21 09:11:41 -08:00
Steve Howell 57f7088304 Ignore prior coverage data in tools/test-main.
Before this patch, we were reading in old coverage data every
time we ran test-main and had a .coverage file lying around.
This would cause inaccurate data when you changed code, and it
would cause crashes if you moved your working directory on the
file system.
2017-11-20 12:48:36 -08:00
derAnfaenger 940e1260b2 docs: Update outdated links. 2017-11-20 15:09:50 +01:00
derAnfaenger 2a74ad11c5 zulip_bots: Make StateHandler optional.
This has the convenient side-effect of making
the bot_handler.storage attribute read-only.
2017-11-18 08:58:47 -08:00
derAnfaenger f41030b515 API: rename get_state & update_state to get_storage & update_storage. 2017-11-18 08:58:47 -08:00
derAnfaenger 2736223073 bots: Make StateHandler store state on Zulip server.
This makes the StateHandler functional. To reduce the
number of server roundtrips when fetching/updating the
state, the entire state is fetched ocne at bot
initialization and cached. All changes are stored in the
cache and only saved externally after handle_message()
has been executed.

Fixes #141.
2017-11-18 08:58:47 -08:00
derAnfaenger 979bbb1c14 bot tests: Consistently use mock_bot_handler instance of MockClass. 2017-11-18 08:58:47 -08:00
derAnfaenger daad7f24e4 bots: Set JSON as default serializer for StateHandler.
With this change, StateHandler.put() does only accept JSON-able
objects by default. The incrementor test tried to store the return
value of send_reply(), a non-JSON-able MockObject, in the state.
Therefore, this commits also sets functional default test return
values for send_message() and send_reply().
Finally, it fixes the tictactoe bot which relied on directly
modifying the state_ attribute.
2017-11-18 08:58:47 -08:00
derAnfaenger 66da09324e zulip package: Add API functions to access state. 2017-11-18 08:58:47 -08:00
Eeshan Garg bd7db69bac bots/giphy: Document the bot. 2017-11-16 09:09:04 -08:00
derAnfaenger a8b858d78f zulip_bots: Update links to docs. 2017-11-16 13:54:02 +01:00
neiljp (Neil Pilgrim) c24c1d2e61 mypy: Add 'type: ignore' comment due to patching function. 2017-11-15 13:43:08 -08:00
neiljp (Neil Pilgrim) 59b86b5b68 mypy: Add reported issue to 'type: ignore' line in generate_manifest.py. 2017-11-15 13:43:08 -08:00
neiljp (Neil Pilgrim) d929cdb91e botserver testing: Move to six.assertRaisesRegex from Regexp variant.
This ensures 2/3 compatibility. The mypy test also now passes, though
the six stubs appear very minimal - maybe incorrect?
2017-11-15 13:43:08 -08:00