# Path: zaqarclient/queues/v1/iterator.py
# class _Iterator(object):
#     def __init__(self, client, listing_response, iter_key, create_function):
#     def __iter__(self):
#     def get_iterables(self, iterables):
#     def stream(self, enabled=True):
#     def _next_page(self):
#     def __next__(self):
# 
# Path: zaqarclient/queues/v2/message.py
# class Message(message.Message):
#     def __init__(self, queue, ttl, age, body, href=None, id=None,
#                  claim_id=None, claim_count=0, checksum=None):
#     def __repr__(self):
#     def claim_id(self):
#     def delete(self):
# def create_object(parent):
# 
# Path: zaqarclient/tests/queues/base.py
# MY_IP = netutils.get_my_ipv4()
# class QueuesTestBase(base.TestBase):
#     def setUp(self):
# 
# Path: zaqarclient/tests/queues/messages.py
# class QueuesV1MessageUnitTest(base.QueuesTestBase):
# class QueuesV2MessageUnitTest(QueuesV1MessageUnitTest):
#     def test_message_delete(self):
#     def test_message_delete_with_claim(self):
#     def test_message_delete_with_claim(self):
#     def test_message_delete(self):
# 
# Path: zaqarclient/transport/http.py
# class HttpTransport(base.Transport):
#     def __init__(self, options):
#     def _prepare(self, request):
#     def send(self, request):
# 
# 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.queues.v1 import iterator as iterate
from zaqarclient.queues.v2 import message
from zaqarclient.tests.queues import base
from zaqarclient.tests.queues import messages as test_message
from zaqarclient.transport import http
from zaqarclient.transport import response
                                         messages,
                                         'messages',
                                         message.create_object(self.queue))
            iterated = [msg for msg in iterator.stream()]
            self.assertEqual(len(iterated), 2)

    def test_iterator_respect_paging(self):
        messages = {'links': [],
                    'messages': [{
                        'href': '/v2/queues/mine/messages/123123423',
                        'ttl': 800,
                        'age': 790,
                        'body': {'event': 'ActivateAccount',
                                 'mode': 'active'}
                    }]
                    }

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

            resp = response.Response(None, json.dumps(messages))
            send_method.return_value = resp

            link = {'rel': 'next',
                    'href': "/v2/queues/mine/messages?marker=6244-244224-783"}
            messages['links'].append(link)

            iterator = iterate._Iterator(self.queue.client,
                                         messages,
                                         'messages',

# Path: zaqarclient/queues/v1/iterator.py
# class _Iterator(object):
#     def __init__(self, client, listing_response, iter_key, create_function):
#     def __iter__(self):
#     def get_iterables(self, iterables):
#     def stream(self, enabled=True):
#     def _next_page(self):
#     def __next__(self):
# 
# Path: zaqarclient/queues/v2/message.py
# class Message(message.Message):
#     def __init__(self, queue, ttl, age, body, href=None, id=None,
#                  claim_id=None, claim_count=0, checksum=None):
#     def __repr__(self):
#     def claim_id(self):
#     def delete(self):
# def create_object(parent):
# 
# Path: zaqarclient/tests/queues/base.py
# MY_IP = netutils.get_my_ipv4()
# class QueuesTestBase(base.TestBase):
#     def setUp(self):
# 
# Path: zaqarclient/tests/queues/messages.py
# class QueuesV1MessageUnitTest(base.QueuesTestBase):
# class QueuesV2MessageUnitTest(QueuesV1MessageUnitTest):
#     def test_message_delete(self):
#     def test_message_delete_with_claim(self):
#     def test_message_delete_with_claim(self):
#     def test_message_delete(self):
# 
# Path: zaqarclient/transport/http.py
# class HttpTransport(base.Transport):
#     def __init__(self, options):
#     def _prepare(self, request):
#     def send(self, request):
# 
# Path: zaqarclient/transport/response.py
# class Response(object):
#     def __init__(self, request, content, headers=None, status_code=None):
#     def deserialized_content(self):


# Path: tests/unit/queues/v2/test_message.py
import json
import mock
from zaqarclient.queues.v1 import iterator as iterate
from zaqarclient.queues.v2 import message
from zaqarclient.tests.queues import base
from zaqarclient.tests.queues import messages as test_message
from zaqarclient.transport import http
from zaqarclient.transport import response

                                         messages,
                                         'messages',
                                         message.create_object(self.queue))
            iterated = [msg for msg in iterator.stream()]
            self.assertEqual(len(iterated), 2)

    def test_iterator_respect_paging(self):
        messages = {'links': [],
                    'messages': [{
                        'href': '/v2/queues/mine/messages/123123423',
                        'ttl': 800,
                        'age': 790,
                        'body': {'event': 'ActivateAccount',
                                 'mode': 'active'}
                    }]
                    }

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

            resp = response.Response(None, json.dumps(messages))
            send_method.return_value = resp

            link = {'rel': 'next',
                    'href': "/v2/queues/mine/messages?marker=6244-244224-783"}
            messages['links'].append(link)

            iterator = iterate._Iterator(self.queue.client,
                                         messages,
                                         'messages',

                                         message.create_object(self.queue))