This repository has been archived by the owner on Oct 23, 2019. It is now read-only.
forked from edwardslabs/CloudBot
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
brew.py: Handle empty search results from API
Fixes #559
- Loading branch information
1 parent
0e72b3a
commit 470e6db
Showing
5 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ exclude_lines = | |
[run] | ||
omit = | ||
tests/data/* | ||
tests/util/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from mock import MagicMock | ||
|
||
from tests.util.mock_bot import MockBot | ||
|
||
|
||
def test_no_results(mock_requests, unset_bot): | ||
from cloudbot.bot import bot | ||
|
||
bot.set(MockBot({"api_keys": {"brewerydb": "APIKEY"}})) | ||
mock_requests.add( | ||
'GET', | ||
'http://api.brewerydb.com/v2/search' | ||
'?format=json&key=APIKEY&type=beer&withBreweries=Y&q=some+text', | ||
match_querystring=True, | ||
json={"totalResults": 0}, | ||
) | ||
from plugins import brew | ||
|
||
reply = MagicMock() | ||
result = brew.brew('some text', reply) | ||
|
||
reply.assert_not_called() | ||
|
||
assert result == 'No results found.' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import asyncio | ||
|
||
from cloudbot.config import Config | ||
|
||
|
||
class MockConfig(Config): | ||
def load_config(self): | ||
self._api_keys.clear() | ||
|
||
|
||
class MockBot: | ||
def __init__(self, config, loop=None): | ||
if loop is None: | ||
loop = asyncio.get_event_loop() | ||
|
||
self.loop = loop | ||
self.config = MockConfig(self, config) |