Merge "Makes health return True or False"
This commit is contained in:
@@ -20,7 +20,7 @@ import ddt
|
|||||||
from zaqarclient.queues import client
|
from zaqarclient.queues import client
|
||||||
from zaqarclient.queues.v1 import core
|
from zaqarclient.queues.v1 import core
|
||||||
from zaqarclient.tests import base
|
from zaqarclient.tests import base
|
||||||
from zaqarclient.transport import response
|
from zaqarclient.transport import errors
|
||||||
|
|
||||||
VERSIONS = [1, 1.1]
|
VERSIONS = [1, 1.1]
|
||||||
|
|
||||||
@@ -35,10 +35,21 @@ class TestClient(base.TestBase):
|
|||||||
self.assertIsNotNone(cli.transport())
|
self.assertIsNotNone(cli.transport())
|
||||||
|
|
||||||
@ddt.data(*VERSIONS)
|
@ddt.data(*VERSIONS)
|
||||||
def test_health(self, version):
|
def test_health_ok(self, version):
|
||||||
cli = client.Client('http://example.com',
|
cli = client.Client('http://example.com',
|
||||||
version, {})
|
version, {})
|
||||||
with mock.patch.object(core, 'health', autospec=True) as core_health:
|
with mock.patch.object(core, 'health', autospec=True) as core_health:
|
||||||
resp = response.Response(None, None)
|
core_health.return_value = None
|
||||||
core_health.return_value = resp
|
self.assertTrue(cli.health())
|
||||||
self.assertIsNotNone(cli.health())
|
|
||||||
|
@ddt.data(*VERSIONS)
|
||||||
|
def test_health_bad(self, version):
|
||||||
|
cli = client.Client('http://example.com',
|
||||||
|
version, {})
|
||||||
|
|
||||||
|
def raise_error(*args, **kwargs):
|
||||||
|
raise errors.ServiceUnavailableError()
|
||||||
|
|
||||||
|
with mock.patch.object(core, 'health', autospec=True) as core_health:
|
||||||
|
core_health.side_effect = raise_error
|
||||||
|
self.assertFalse(cli.health())
|
||||||
|
@@ -23,6 +23,7 @@ from zaqarclient.queues.v1 import iterator
|
|||||||
from zaqarclient.queues.v1 import pool
|
from zaqarclient.queues.v1 import pool
|
||||||
from zaqarclient.queues.v1 import queues
|
from zaqarclient.queues.v1 import queues
|
||||||
from zaqarclient import transport
|
from zaqarclient import transport
|
||||||
|
from zaqarclient.transport import errors
|
||||||
from zaqarclient.transport import request
|
from zaqarclient.transport import request
|
||||||
|
|
||||||
|
|
||||||
@@ -160,4 +161,8 @@ class Client(object):
|
|||||||
def health(self):
|
def health(self):
|
||||||
"""Gets the health status of Zaqar server."""
|
"""Gets the health status of Zaqar server."""
|
||||||
req, trans = self._request_and_transport()
|
req, trans = self._request_and_transport()
|
||||||
return core.health(trans, req)
|
try:
|
||||||
|
core.health(trans, req)
|
||||||
|
return True
|
||||||
|
except errors.ServiceUnavailableError:
|
||||||
|
return False
|
||||||
|
Reference in New Issue
Block a user