Add RefineServer.url() staticmethod to report the Refine server's url
This commit is contained in:
parent
294f3f2690
commit
316b60b387
|
@ -40,9 +40,17 @@ REFINE_PORT = os.environ.get('GOOGLE_REFINE_PORT', '3333')
|
||||||
class RefineServer(object):
|
class RefineServer(object):
|
||||||
"""Communicate with a Refine server."""
|
"""Communicate with a Refine server."""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def url():
|
||||||
|
"""Return the URL to the Refine server."""
|
||||||
|
server='http://%s' % REFINE_HOST
|
||||||
|
if REFINE_PORT != '80':
|
||||||
|
server += ':' + REFINE_PORT
|
||||||
|
return server
|
||||||
|
|
||||||
def __init__(self, server=None):
|
def __init__(self, server=None):
|
||||||
if server is None:
|
if server is None:
|
||||||
server='http://%s:%s' % (REFINE_HOST, REFINE_PORT)
|
server=self.url()
|
||||||
self.server = server[:-1] if server.endswith('/') else server
|
self.server = server[:-1] if server.endswith('/') else server
|
||||||
|
|
||||||
def urlopen(self, command, data=None, project_id=None):
|
def urlopen(self, command, data=None, project_id=None):
|
||||||
|
|
|
@ -17,8 +17,9 @@ from tests import refinetest
|
||||||
|
|
||||||
class RefineServerTest(refinetest.RefineTestCase):
|
class RefineServerTest(refinetest.RefineTestCase):
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
self.assertEqual(self.server.server,
|
server_url = 'http://%s:%s' % (refine.REFINE_HOST, refine.REFINE_PORT)
|
||||||
'http://%s:%s' % (refine.REFINE_HOST, refine.REFINE_PORT))
|
self.assertEqual(self.server.server, server_url)
|
||||||
|
self.assertEqual(refine.RefineServer.url(), server_url)
|
||||||
# strip trailing /
|
# strip trailing /
|
||||||
server = refine.RefineServer('http://refine.example/')
|
server = refine.RefineServer('http://refine.example/')
|
||||||
self.assertEqual(server.server, 'http://refine.example')
|
self.assertEqual(server.server, 'http://refine.example')
|
||||||
|
|
Loading…
Reference in New Issue