Move get_version() to RefineServer & add RefineServer.version lazy property

This commit is contained in:
Paul Makepeace 2011-06-10 17:49:06 +00:00
parent bd44e16b07
commit 5e544bb827
2 changed files with 17 additions and 8 deletions

View File

@ -52,6 +52,7 @@ class RefineServer(object):
if server is None: if server is None:
server=self.url() server=self.url()
self.server = server[:-1] if server.endswith('/') else server self.server = server[:-1] if server.endswith('/') else server
self.__version = None # see version @property below
def urlopen(self, command, data=None, params=None, project_id=None): def urlopen(self, command, data=None, params=None, project_id=None):
"""Open a Refine URL and with optional query params and POST data. """Open a Refine URL and with optional query params and POST data.
@ -100,6 +101,18 @@ class RefineServer(object):
response.get('message', response.get('stack', response))) response.get('message', response.get('stack', response)))
return response return response
def get_version(self):
"""Return version data.
{"revision":"r1836","full_version":"2.0 [r1836]",
"full_name":"Google Refine 2.0 [r1836]","version":"2.0"}"""
return self.urlopen_json('get-version')
@property
def version(self):
if self.__version is None:
self.__version = self.get_version()['version']
return self.__version
class Refine: class Refine:
"""Class representing a connection to a Refine server.""" """Class representing a connection to a Refine server."""
@ -109,13 +122,6 @@ class Refine:
else: else:
self.server = RefineServer(server) self.server = RefineServer(server)
def get_version(self):
"""Return version data.
{"revision":"r1836","full_version":"2.0 [r1836]",
"full_name":"Google Refine 2.0 [r1836]","version":"2.0"}"""
return self.server.urlopen_json('get-version')
def list_projects(self): def list_projects(self):
"""Return a dict of projects indexed by id. """Return a dict of projects indexed by id.

View File

@ -29,10 +29,13 @@ class RefineServerTest(refinetest.RefineTestCase):
self.assertTrue(isinstance(projects, dict)) self.assertTrue(isinstance(projects, dict))
def test_get_version(self): def test_get_version(self):
version_info = self.refine.get_version() version_info = self.server.get_version()
for item in ('revision', 'version', 'full_version', 'full_name'): for item in ('revision', 'version', 'full_version', 'full_name'):
self.assertTrue(item in version_info) self.assertTrue(item in version_info)
def test_version(self):
self.assertTrue(self.server.version in ('2.0', '2.1'))
class RefineTest(refinetest.RefineTestCase): class RefineTest(refinetest.RefineTestCase):
project_file = 'duplicates.csv' project_file = 'duplicates.csv'