# Path: zaqarclient/queues/client.py
# _CLIENTS = {1: cv1.Client,
#             1.1: cv1.Client,
#             2: cv2.Client}
# def Client(url=None, version=None, conf=None, session=None):
# 
# Path: zaqarclient/tests/queues/base.py
# MY_IP = netutils.get_my_ipv4()
# class QueuesTestBase(base.TestBase):
#     def setUp(self):
# 
# Path: zaqarclient/transport/errors.py
# class TransportError(errors.ZaqarError):
# class ResourceNotFound(TransportError):
# class MalformedRequest(TransportError):
# class UnauthorizedError(TransportError):
# class ForbiddenError(TransportError):
# class InternalServerError(TransportError):
# class ServiceUnavailableError(TransportError):
# class ConflictError(TransportError):
#     def __init__(self, title=None, description=None, text=None):
# 
# Path: zaqarclient/transport/http.py
# class HttpTransport(base.Transport):
#     def __init__(self, options):
#     def _prepare(self, request):
#     def send(self, request):


import mock
import ddt
from zaqarclient.queues import client
from zaqarclient.tests.queues import base
from zaqarclient.transport import errors
from zaqarclient.transport import http
VERSIONS = [2]


@ddt.ddt
class TestClient(base.QueuesTestBase):
    transport_cls = http.HttpTransport
    url = 'http://127.0.0.1:8888/v2'
    version = VERSIONS[0]

    @ddt.data(*VERSIONS)
    def test_transport(self, version):
        cli = client.Client('http://example.com',
                            version, {"auth_opts": {'backend': 'noauth'}})
        self.assertIsNotNone(cli.transport())

    @ddt.data(*VERSIONS)
    def test_ping_ok(self, version):
        with mock.patch.object(self.transport, 'send',
                               autospec=True) as send_method:
            send_method.return_value = None
            self.assertTrue(self.client.ping())

    @ddt.data(*VERSIONS)
    def test_ping_bad(self, version):
        def raise_error(*args, **kwargs):
            raise errors.ServiceUnavailableError()

        with mock.patch.object(self.transport, 'send',
                               autospec=True) as send_method:
            send_method.side_effect = raise_error

# Path: zaqarclient/queues/client.py
# _CLIENTS = {1: cv1.Client,
#             1.1: cv1.Client,
#             2: cv2.Client}
# def Client(url=None, version=None, conf=None, session=None):
# 
# Path: zaqarclient/tests/queues/base.py
# MY_IP = netutils.get_my_ipv4()
# class QueuesTestBase(base.TestBase):
#     def setUp(self):
# 
# Path: zaqarclient/transport/errors.py
# class TransportError(errors.ZaqarError):
# class ResourceNotFound(TransportError):
# class MalformedRequest(TransportError):
# class UnauthorizedError(TransportError):
# class ForbiddenError(TransportError):
# class InternalServerError(TransportError):
# class ServiceUnavailableError(TransportError):
# class ConflictError(TransportError):
#     def __init__(self, title=None, description=None, text=None):
# 
# Path: zaqarclient/transport/http.py
# class HttpTransport(base.Transport):
#     def __init__(self, options):
#     def _prepare(self, request):
#     def send(self, request):


# Path: tests/unit/queues/v2/test_client.py
import mock
import ddt
from zaqarclient.queues import client
from zaqarclient.tests.queues import base
from zaqarclient.transport import errors
from zaqarclient.transport import http

VERSIONS = [2]


@ddt.ddt
class TestClient(base.QueuesTestBase):
    transport_cls = http.HttpTransport
    url = 'http://127.0.0.1:8888/v2'
    version = VERSIONS[0]

    @ddt.data(*VERSIONS)
    def test_transport(self, version):
        cli = client.Client('http://example.com',
                            version, {"auth_opts": {'backend': 'noauth'}})
        self.assertIsNotNone(cli.transport())

    @ddt.data(*VERSIONS)
    def test_ping_ok(self, version):
        with mock.patch.object(self.transport, 'send',
                               autospec=True) as send_method:
            send_method.return_value = None
            self.assertTrue(self.client.ping())

    @ddt.data(*VERSIONS)
    def test_ping_bad(self, version):
        def raise_error(*args, **kwargs):
            raise errors.ServiceUnavailableError()

        with mock.patch.object(self.transport, 'send',
                               autospec=True) as send_method:
            send_method.side_effect = raise_error

            self.assertFalse(self.client.ping())