-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from scrapinghub/raise-click-exceptions
Raise ClickException in case of request errors
- Loading branch information
Showing
5 changed files
with
77 additions
and
31 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
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,7 @@ | ||
from click import ClickException | ||
|
||
|
||
class AuthException(ClickException): | ||
def __init__(self): | ||
msg = 'Authentication failure. Make sure your API key is valid.' | ||
super(AuthException, self).__init__(msg) |
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
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,26 @@ | ||
import unittest | ||
import mock | ||
from collections import namedtuple | ||
|
||
from click.testing import CliRunner | ||
from shub import tool | ||
|
||
FakeResponse = namedtuple('FakeResponse', ['status_code']) | ||
|
||
@mock.patch('shub.fetch_eggs.requests', autospec=True) | ||
class FetchEggsTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.runner = CliRunner() | ||
|
||
def test_raises_auth_exception(self, requests_mock): | ||
fake_response = FakeResponse(403) | ||
requests_mock.get.return_value = fake_response | ||
output = self.runner.invoke(tool.cli, ['fetch-eggs', 'xxx']).output | ||
self.assertTrue('Authentication failure' in output) | ||
|
||
def test_raises_exception_if_request_error(self, requests_mock): | ||
fake_response = FakeResponse(400) | ||
requests_mock.get.return_value = fake_response | ||
output = self.runner.invoke(tool.cli, ['fetch-eggs', 'xxx']).output | ||
self.assertTrue('Eggs could not be fetched' in output) |