Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raising exception on utils#find_api_key #37

Merged
merged 1 commit into from
Jun 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion shub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,20 @@ def missing_modules(*modules):


def find_api_key():
"""Finds and returns the Scrapy Cloud APIKEY"""
"""Finds and returns the Scrapy Cloud APIKEY

Raises:
ClickException: if no API key is found
"""
key = os.getenv("SHUB_APIKEY")
if not key:
key = get_key_netrc()

if not key:
err = ("Your credentials haven't been defined.\n"
"Use 'shub login' or set the SHUB_APIKEY environment variable.")
raise ClickException(err)

return key


Expand Down
1 change: 1 addition & 0 deletions tests/test_deploy_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def setUp(self):

self.fake_requester = FakeRequester()
deploy_egg.utils.make_deploy_request = self.fake_requester.fake_request
deploy_egg.utils.find_api_key = lambda: ''

self.tmp_dir = tempfile.mktemp(prefix="shub-test-deploy-eggs")

Expand Down
9 changes: 6 additions & 3 deletions tests/test_fetch_eggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
class FetchEggsTest(unittest.TestCase):

def setUp(self):
self.runner = CliRunner()
# defining SHUB_APIKEY so it passes the login validation
self.runner = CliRunner(env={'SHUB_APIKEY': 'xxx'})

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)
err = 'Unexpected output: %s' % output
self.assertTrue('Authentication failure' in output, err)

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)
err = 'Unexpected output: %s' % output
self.assertTrue('Eggs could not be fetched' in output, err)