From 6109bd198abc8d860c1ae227fa88ff8f6e1d73c2 Mon Sep 17 00:00:00 2001 From: sColin16 Date: Sun, 10 Dec 2017 16:26:42 +0000 Subject: [PATCH] interactive bots: Improve wikipedia bot. --- zulip_bots/zulip_bots/bots/wikipedia/doc.md | 41 +++++++++++++++++++ .../wikipedia/fixtures/test_status_code.json | 22 ++++++++++ .../bots/wikipedia/test_wikipedia.py | 12 ++++++ 3 files changed, 75 insertions(+) create mode 100644 zulip_bots/zulip_bots/bots/wikipedia/doc.md create mode 100644 zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_status_code.json diff --git a/zulip_bots/zulip_bots/bots/wikipedia/doc.md b/zulip_bots/zulip_bots/bots/wikipedia/doc.md new file mode 100644 index 0000000..0df2bc2 --- /dev/null +++ b/zulip_bots/zulip_bots/bots/wikipedia/doc.md @@ -0,0 +1,41 @@ +# Wikipedia Bot + +The Wikipedia bot is a Zulip bot that will search Wikipedia +for a provided keyword, and fetch a link to the associated +Wikipedia article. The link is returned to the same stream +it was @mentioned in + +The Wikipedia bot uses the +[MediaWiki API](https://www.mediawiki.org/wiki/API:Main_page) +to obtain the search results it returns + +Using the Wikipedia bot is as simple as mentioning @\, +followed by the keyword: + +``` +@ +``` + +## Setup + +Beyond the typical obtaining of the zuliprc file, no extra setup is required to use the Wikipedia Bot + +## Usage + +1. ```@ ``` - +fetches the link to the appropriate Wikipedia article. + + * For example, `@ Zulip` +will return the link `https://en.wikipedia.org/wiki/Zulip` +
+ +2. If the keyword does not return an article link, +the bot will respond with an error message: + + `I am sorry. The search term you provided is not found` + +
+ +3. If no keyword is provided, the bot will return the help text: + + ```Please enter your message after @mention-bot``` diff --git a/zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_status_code.json b/zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_status_code.json new file mode 100644 index 0000000..b94e0fc --- /dev/null +++ b/zulip_bots/zulip_bots/bots/wikipedia/fixtures/test_status_code.json @@ -0,0 +1,22 @@ + +{ + "request": { + "api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=Zulip&format=json" + }, + "response": { + "data": { + "status_code":404 + }, + "query": { + "search": [ + { + "title":"Number sign" + } + ] + } + }, + "response-headers":{ + "status":404, + "content-type":"text/html" + } +} diff --git a/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py b/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py index 11d4f08..1cfeb57 100755 --- a/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py +++ b/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py @@ -55,3 +55,15 @@ class TestWikipediaBot(StubBotTestCase): bot_request = '' bot_response = "Please enter your search term after @mention-bot" self.verify_reply(bot_request, bot_response) + + # Incorrect status code + bot_request = 'Zulip' + bot_response = None + with self.mock_http_conversation('test_status_code'): + self.verify_reply(bot_request, bot_response) + + # Request Exception + bot_request = 'Z' + bot_response = None + with self.mock_request_exception(): + self.verify_reply(bot_request, bot_response)