# 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/response.py
# class Response(object):
#     def __init__(self, request, content, headers=None, status_code=None):
#     def deserialized_content(self):


import json
import mock
from zaqarclient.tests.queues import base
from zaqarclient.transport import errors
from zaqarclient.transport import response
    def test_subscription_create_duplicate_throws_conflicterror(self):
        subscription_data = {'subscriber': 'http://trigger.me',
                             'ttl': 3600}

        with mock.patch.object(self.transport.client, 'request',
                               autospec=True) as request_method:

            class FakeRawResponse(object):
                def __init__(self):
                    self.text = ''
                    self.headers = {}
                    self.status_code = 409
            request_method.return_value = FakeRawResponse()

            self.assertRaises(errors.ConflictError, self.client.subscription,
                              'beijing', **subscription_data)

    def test_subscription_update(self):
        subscription_data = {'subscriber': 'http://trigger.me',
                             'ttl': 3600}

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

            create_resp = response.Response(None,
                                            '{"subscription_id": "fake_id"}')
            get_content = ('{"subscriber": "http://trigger.me","ttl": 3600, '
                           '"id": "fake_id"}')
            get_resp = response.Response(None, get_content)
            update_content = json.dumps({'subscriber': 'fake_subscriber'})

# 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/response.py
# class Response(object):
#     def __init__(self, request, content, headers=None, status_code=None):
#     def deserialized_content(self):


# Path: zaqarclient/tests/queues/subscriptions.py
import json
import mock
from zaqarclient.tests.queues import base
from zaqarclient.transport import errors
from zaqarclient.transport import response

    def test_subscription_create_duplicate_throws_conflicterror(self):
        subscription_data = {'subscriber': 'http://trigger.me',
                             'ttl': 3600}

        with mock.patch.object(self.transport.client, 'request',
                               autospec=True) as request_method:

            class FakeRawResponse(object):
                def __init__(self):
                    self.text = ''
                    self.headers = {}
                    self.status_code = 409
            request_method.return_value = FakeRawResponse()

            self.assertRaises(errors.ConflictError, self.client.subscription,
                              'beijing', **subscription_data)

    def test_subscription_update(self):
        subscription_data = {'subscriber': 'http://trigger.me',
                             'ttl': 3600}

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

            create_resp = response.Response(None,
                                            '{"subscription_id": "fake_id"}')
            get_content = ('{"subscriber": "http://trigger.me","ttl": 3600, '
                           '"id": "fake_id"}')
            get_resp = response.Response(None, get_content)
            update_content = json.dumps({'subscriber': 'fake_subscriber'})

            update_resp = response.Response(None, update_content)