# Path: zaqarclient/tests/base.py
# _USE_AUTHENTICATION = os.environ.get('ZAQARCLIENT_AUTH_FUNCTIONAL', False)
# _RUN_FUNCTIONAL = os.environ.get('ZAQARCLIENT_TEST_FUNCTIONAL',
#                                  _USE_AUTHENTICATION)
# class TestBase(testtools.TestCase):
#     def setUp(self):
#     def _credentials(self, cloud='devstack-admin'):
#     def _setup_auth_params(self):
#     def config(self, group=None, **kw):
# 
# Path: zaqarclient/transport/request.py
# def prepare_request(auth_opts=None, data=None, **kwargs):
#     def __init__(self, endpoint='', operation='',
#                  ref='', content=None, params=None,
#                  headers=None, api=None, verify=True, cert=None, session=None):
#     def api(self):
#     def validate(self):
# class Request(object):
# 
# Path: zaqarclient/transport/ws.py
# LOG = logging.getLogger(__name__)
# class WebsocketTransport(base.Transport):
#     def __init__(self, options):
#     def _init_client(self, endpoint):
#     def _create_connection(self, endpoint):
#     def send(self, request):
#     def recv(self):
#     def cleanup(self):
#     def __enter__(self):
#     def __exit__(self, *exc):


import json
import mock
from zaqarclient.tests import base
from zaqarclient.transport import request
from zaqarclient.transport import ws


class TestWsTransport(base.TestBase):

    def setUp(self):
        super(TestWsTransport, self).setUp()
        os_opts = {
            'os_auth_token': 'FAKE_TOKEN',
            'os_auth_url': 'http://127.0.0.0:5000/v3',
            'os_project_id': 'admin',
            'os_service_type': 'messaging-websocket',
        }
        auth_opts = {'backend': 'keystone',
                     'options': os_opts}
        self.options = {'auth_opts': auth_opts}
        self.endpoint = 'ws://127.0.0.1:9000'

    @mock.patch.object(ws.WebsocketTransport, "_create_connection")
    def test_make_client(self, ws_create_connection):
        ws_create_connection.return_value.recv.return_value = json.dumps({
            "headers": {
                "status": 200
            }
        })

        transport = ws.WebsocketTransport(self.options)
        req = request.Request(self.endpoint)
        transport.send(req)
        ws_create_connection.assert_called_with("ws://127.0.0.1:9000")


# Path: zaqarclient/tests/base.py
# _USE_AUTHENTICATION = os.environ.get('ZAQARCLIENT_AUTH_FUNCTIONAL', False)
# _RUN_FUNCTIONAL = os.environ.get('ZAQARCLIENT_TEST_FUNCTIONAL',
#                                  _USE_AUTHENTICATION)
# class TestBase(testtools.TestCase):
#     def setUp(self):
#     def _credentials(self, cloud='devstack-admin'):
#     def _setup_auth_params(self):
#     def config(self, group=None, **kw):
# 
# Path: zaqarclient/transport/request.py
# def prepare_request(auth_opts=None, data=None, **kwargs):
#     def __init__(self, endpoint='', operation='',
#                  ref='', content=None, params=None,
#                  headers=None, api=None, verify=True, cert=None, session=None):
#     def api(self):
#     def validate(self):
# class Request(object):
# 
# Path: zaqarclient/transport/ws.py
# LOG = logging.getLogger(__name__)
# class WebsocketTransport(base.Transport):
#     def __init__(self, options):
#     def _init_client(self, endpoint):
#     def _create_connection(self, endpoint):
#     def send(self, request):
#     def recv(self):
#     def cleanup(self):
#     def __enter__(self):
#     def __exit__(self, *exc):


# Path: tests/unit/transport/test_ws.py
import json
import mock
from zaqarclient.tests import base
from zaqarclient.transport import request
from zaqarclient.transport import ws



class TestWsTransport(base.TestBase):

    def setUp(self):
        super(TestWsTransport, self).setUp()
        os_opts = {
            'os_auth_token': 'FAKE_TOKEN',
            'os_auth_url': 'http://127.0.0.0:5000/v3',
            'os_project_id': 'admin',
            'os_service_type': 'messaging-websocket',
        }
        auth_opts = {'backend': 'keystone',
                     'options': os_opts}
        self.options = {'auth_opts': auth_opts}
        self.endpoint = 'ws://127.0.0.1:9000'

    @mock.patch.object(ws.WebsocketTransport, "_create_connection")
    def test_make_client(self, ws_create_connection):
        ws_create_connection.return_value.recv.return_value = json.dumps({
            "headers": {
                "status": 200
            }
        })

        transport = ws.WebsocketTransport(self.options)
        req = request.Request(self.endpoint)
        transport.send(req)
        ws_create_connection.assert_called_with("ws://127.0.0.1:9000")


    @mock.patch.object(ws.WebsocketTransport, "recv")