Skip to content

Commit

Permalink
Make quilt.install and other commands work
Browse files Browse the repository at this point in the history
- Move `main` to `main.py`, just for clarity
- Create the session automatically
- Import useful functions from `tools.command` into `__init__.py`
  • Loading branch information
dimaryaz committed Apr 20, 2017
1 parent c30343e commit 7797b0d
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 162 deletions.
22 changes: 22 additions & 0 deletions quilt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Makes functions in .tools.command accessible directly from quilt.
"""

from .tools.command import (
access_add,
access_list,
access_remove,
build,
inspect,
install,
log,
login,
logout,
ls,
push,
tag_add,
tag_list,
tag_remove,
version_add,
version_list,
)
20 changes: 6 additions & 14 deletions quilt/test/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import json
import os
import pytest
import requests
import responses
import time

Expand All @@ -16,20 +15,16 @@

class CommandTest(QuiltTestCase):
def test_push_invalid_package(self):
session = requests.Session()

with assertRaisesRegex(self, command.CommandException, "owner/package_name"):
command.push(session=session, package="no_user")
command.push(package="no_user")
with assertRaisesRegex(self, command.CommandException, "owner/package_name"):
command.push(session=session, package="a/b/c")
command.push(package="a/b/c")

def test_install_invalid_package(self):
session = requests.Session()

with assertRaisesRegex(self, command.CommandException, "owner/package_name"):
command.install(session=session, package="no_user")
command.install(package="no_user")
with assertRaisesRegex(self, command.CommandException, "owner/package_name"):
command.install(session=session, package="a/b/c")
command.install(package="a/b/c")

def test_inspect_invalid_package(self):
with assertRaisesRegex(self, command.CommandException, "owner/package_name"):
Expand All @@ -38,10 +33,8 @@ def test_inspect_invalid_package(self):
command.inspect(package="a/b/c")

def test_push_missing_package(self):
session = requests.Session()

with assertRaisesRegex(self, command.CommandException, "not found"):
command.push(session=session, package="owner/package")
command.push(package="owner/package")

def test_inspect_missing_package(self):
with assertRaisesRegex(self, command.CommandException, "not found"):
Expand Down Expand Up @@ -142,8 +135,7 @@ def test_log(self):
pkg_obj = store.PackageStore.find_package(owner, package)
self._mock_logs_list(owner, package, pkg_obj.get_hash())

session = requests.Session()
command.log(session, "{owner}/{pkg}".format(owner=owner, pkg=package))
command.log("{owner}/{pkg}".format(owner=owner, pkg=package))

def _mock_logs_list(self, owner, package, pkg_hash):
logs_url = "%s/api/log/%s/%s/" % (command.QUILT_PKG_URL, owner, package)
Expand Down
10 changes: 3 additions & 7 deletions quilt/test/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json
import os

import requests
import responses
from six import assertRaisesRegex

Expand Down Expand Up @@ -47,8 +46,7 @@ def test_install_latest(self):
self._mock_s3(table_hash, table_data)
self._mock_s3(file_hash, file_data)

session = requests.Session()
command.install(session, 'foo/bar')
command.install('foo/bar')

with open('quilt_packages/foo/bar.json') as fd:
file_contents = json.load(fd, object_hook=decode_node)
Expand Down Expand Up @@ -81,9 +79,8 @@ def test_bad_contents_hash(self):
self._mock_package('foo/bar', contents_hash, contents, [obj_hash])
self._mock_s3(obj_hash, tabledata)

session = requests.Session()
with assertRaisesRegex(self, command.CommandException, "Mismatched hash"):
command.install(session, 'foo/bar')
command.install('foo/bar')

assert not os.path.exists('quilt_packages/foo/bar.json')

Expand All @@ -106,9 +103,8 @@ def test_bad_object_hash(self):
self._mock_package('foo/bar', contents_hash, contents, [obj_hash])
self._mock_s3(obj_hash, tabledata)

session = requests.Session()
with assertRaisesRegex(self, command.CommandException, "Mismatched hash"):
command.install(session, 'foo/bar')
command.install('foo/bar')

assert not os.path.exists('quilt_packages/foo/bar.json')

Expand Down
4 changes: 1 addition & 3 deletions quilt/test/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import json
import os

import requests
import responses

from quilt.tools import command, store
Expand Down Expand Up @@ -45,8 +44,7 @@ def test_push(self):
self._mock_put_package('foo/bar', pkg_hash, contents)
self._mock_put_tag('foo/bar', 'latest')

session = requests.Session()
command.push(session, 'foo/bar')
command.push('foo/bar')

def _mock_put_package(self, package, pkg_hash, contents):
pkg_url = '%s/api/package/%s/%s' % (command.QUILT_PKG_URL, package, pkg_hash)
Expand Down
6 changes: 6 additions & 0 deletions quilt/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Python2 - external dependency.
from mock import patch

import requests
import responses


Expand All @@ -28,11 +29,16 @@ def setUp(self):
self._test_dir = tempfile.mkdtemp(prefix='quilt-test-')
os.chdir(self._test_dir)

self.session_patcher = patch('quilt.tools.command._get_session', requests.Session)
self.session_patcher.start()

self.requests_mock = responses.RequestsMock(assert_all_requests_are_fired=False)
self.requests_mock.start()

def tearDown(self):
self.requests_mock.stop()

self.session_patcher.stop()

os.chdir(self._old_dir)
shutil.rmtree(self._test_dir)
Loading

0 comments on commit 7797b0d

Please sign in to comment.