Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring to help testing

  • Loading branch information...
commit 0cbff8d5c8c847635170cbc069cce23fbcde7697 1 parent 2f2c299
@dvarrazzo authored
View
6 pgxnclient/api.py
@@ -10,9 +10,9 @@
from urllib import urlencode
+from pgxnclient import network
from pgxnclient.utils import load_json
from pgxnclient.errors import NetworkError, NotFound, ResourceNotFound
-from pgxnclient.network import get_file
from pgxnclient.utils.uri import expand_template
@@ -78,7 +78,7 @@ def user(self, username):
def call(self, meth, args=None, query=None):
url = self.get_url(meth, args, query)
- return get_file(url)
+ return network.get_file(url)
def get_url(self, meth, args=None, query=None):
tmpl = self.get_template(meth)
@@ -98,7 +98,7 @@ def get_index(self):
if self._api_index is None:
url = self.mirror.rstrip('/') + '/index.json'
try:
- with get_file(url) as f:
+ with network.get_file(url) as f:
self._api_index = load_json(f)
except ResourceNotFound:
raise NetworkError("API index not found at '%s'" % url)
View
4 pgxnclient/commands/install.py
@@ -17,10 +17,10 @@
from subprocess import PIPE
from pgxnclient import SemVer
+from pgxnclient import network
from pgxnclient.i18n import _, N_
from pgxnclient.utils import sha1, b
from pgxnclient.errors import BadChecksum, PgxnClientException, InsufficientPrivileges
-from pgxnclient.network import download
from pgxnclient.commands import Command, WithDatabase, WithMake, WithPgConfig
from pgxnclient.commands import WithSpec, WithSpecLocal, WithSudo
from pgxnclient.utils.zip import unpack
@@ -54,7 +54,7 @@ def run(self):
"sha1 missing from the distribution meta")
with self.api.download(data['name'], SemVer(data['version'])) as fin:
- fn = download(fin, self.opts.target)
+ fn = network.download(fin, self.opts.target)
self.verify_checksum(fn, chk)
return fn
View
26 pgxnclient/tests/test_commands.py
@@ -44,7 +44,7 @@ def f(what):
class InfoTestCase(unittest.TestCase):
def _get_output(self, cmdline):
@patch('sys.stdout')
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def do(mock, stdout):
mock.side_effect = fake_get_file
from pgxnclient.cli import main
@@ -120,7 +120,7 @@ def test_popen_raises(self):
class DownloadTestCase(unittest.TestCase):
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def test_download_latest(self, mock):
mock.side_effect = fake_get_file
@@ -134,7 +134,7 @@ def test_download_latest(self, mock):
finally:
ifunlink(fn)
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def test_download_testing(self, mock):
mock.side_effect = fake_get_file
@@ -148,7 +148,7 @@ def test_download_testing(self, mock):
finally:
ifunlink(fn)
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def test_download_ext(self, mock):
mock.side_effect = fake_get_file
@@ -162,7 +162,7 @@ def test_download_ext(self, mock):
finally:
ifunlink(fn)
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def test_download_rename(self, mock):
mock.side_effect = fake_get_file
@@ -195,7 +195,7 @@ def test_download_rename(self, mock):
ifunlink(fn1)
ifunlink(fn2)
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def test_download_bad_sha1(self, mock):
def fakefake(url):
return fake_get_file(url, urlmap = {
@@ -218,7 +218,7 @@ def fakefake(url):
finally:
ifunlink(fn)
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def test_download_case_insensitive(self, mock):
mock.side_effect = fake_get_file
@@ -325,7 +325,7 @@ def assertCallArgs(self, pattern, args):
class InstallTestCase(unittest.TestCase, Assertions):
def setUp(self):
- self._p1 = patch('pgxnclient.api.get_file')
+ self._p1 = patch('pgxnclient.network.get_file')
self.mock_get = self._p1.start()
self.mock_get.side_effect = fake_get_file
@@ -452,7 +452,7 @@ def test_install_local_dir(self):
class CheckTestCase(unittest.TestCase, Assertions):
def setUp(self):
- self._p1 = patch('pgxnclient.api.get_file')
+ self._p1 = patch('pgxnclient.network.get_file')
self.mock_get = self._p1.start()
self.mock_get.side_effect = fake_get_file
@@ -558,7 +558,7 @@ def test_parse_version(self):
'PostgreSQL 9.1alpha5 on i686-pc-linux-gnu, compiled by GCC gcc'
' (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5, 32-bit '))
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def test_check_psql_options(self, mock_get):
mock_get.side_effect = fake_get_file
@@ -581,7 +581,7 @@ def test_check_psql_options(self, mock_get):
self.assertEqual('somewhere', args[args.index('--host') + 1])
@patch('pgxnclient.commands.install.unpack')
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def test_load_local_zip(self, mock_get, mock_unpack):
mock_get.side_effect = lambda *args: self.fail('network invoked')
from pgxnclient.utils.zip import unpack
@@ -597,7 +597,7 @@ def test_load_local_zip(self, mock_get, mock_unpack):
self.assertEquals(communicate.call_args[0][0],
'CREATE EXTENSION foobar;')
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def test_load_local_dir(self, mock_get):
mock_get.side_effect = lambda *args: self.fail('network invoked')
@@ -757,7 +757,7 @@ def test_unload_missing(self):
class SearchTestCase(unittest.TestCase):
@patch('sys.stdout')
- @patch('pgxnclient.api.get_file')
+ @patch('pgxnclient.network.get_file')
def test_search_quoting(self, mock_get, stdout):
mock_get.side_effect = fake_get_file
from pgxnclient.cli import main
Please sign in to comment.
Something went wrong with that request. Please try again.