Skip to content

Commit

Permalink
Merge pull request #408 from sergiusens/bugfix/1560553/login-error
Browse files Browse the repository at this point in the history
Raise a nice error when downloading without a login
  • Loading branch information
sergiusens committed Mar 29, 2016
2 parents b18e4e9 + 75f6794 commit 1b15b6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions snapcraft/storeapi/_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
def download(snap, download_path, config, arch):
"""Download snap from the store to download_path"""
session = get_oauth_session(config)
if session is None:
raise EnvironmentError(
'No valid credentials found. Have you run "snapcraft login"?')

# TODO add release header
session.headers.update({'X-Ubuntu-Architecture': arch})
Expand Down
10 changes: 10 additions & 0 deletions snapcraft/tests/test_storeapi_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,13 @@ def test_snap_already_downloaded(self):
call("Getting details for 'os'"),
call("Already downloaded 'os'")])
self.assertTrue(os.path.exists('os.snap'))

def test_download_fails_when_not_logged_in(self):
self.mock_get_oauth_session.return_value = None

with self.assertRaises(EnvironmentError) as raised:
download('os', 'os.snap', None, 'amd64')

self.assertEqual(
'No valid credentials found. Have you run "snapcraft login"?',
str(raised.exception))

0 comments on commit 1b15b6a

Please sign in to comment.