Exemple #1
0
    def test_get_message(self, params):
        """Get Messages."""

        expected_msg_count = params.get('limit', 10)

        # Test Setup
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        url = ''
        params['echo'] = True

        # Follow the hrefs & perform GET, till the end of messages i.e. http
        # 204
        while result.status_code in [201, 200]:
            result = self.client.get(url, params=params)
            self.assertIn(result.status_code, [200, 204])

            if result.status_code == 200:
                actual_msg_count = len(result.json()['messages'])
                self.assertMessageCount(actual_msg_count, expected_msg_count)

                self.assertSchema(result.json(), 'message_list')

                href = result.json()['links'][0]['href']
                url = self.cfg.zaqar.url + href

        self.assertEqual(result.status_code, 204)
Exemple #2
0
    def test_message_bulk_insert(self):
        """Bulk Insert Messages into the Queue."""
        message_count = self.limits.max_messages_per_page
        doc = helpers.create_message_body(messagecount=message_count)

        result = self.client.post(data=doc)
        self.assertEqual(201, result.status_code)

        # GET on posted messages
        location = result.headers['location']
        url = self.cfg.zaqar.url + location
        result = self.client.get(url)
        self.assertEqual(200, result.status_code)

        self.skipTest('Bug #1273335 - Get set of messages returns wrong hrefs '
                      '(happens randomly)')

        # Verify that the response json schema matches the expected schema
        self.assertSchema(result.json(), 'message_get_many')

        # Compare message metadata
        result_body = [result.json()[i]['body']
                       for i in range(len(result.json()))]
        result_body.sort()

        posted_metadata = [doc[i]['body']
                           for i in range(message_count)]
        posted_metadata.sort()

        self.assertEqual(posted_metadata, result_body)
Exemple #3
0
    def test_get_message(self, params):
        """Get Messages."""

        expected_msg_count = params.get('limit', 10)

        # Test Setup
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)

        result = self.client.post(data=doc)
        self.assertEqual(201, result.status_code)

        url = ''
        params['echo'] = True

        # Follow the hrefs & perform GET, till the end of messages i.e. http
        # 204
        while result.status_code in [201, 200]:
            result = self.client.get(url, params=params)
            self.assertIn(result.status_code, [200, 204])

            if result.status_code == 200:
                actual_msg_count = len(result.json()['messages'])
                self.assertMessageCount(actual_msg_count, expected_msg_count)

                self.assertSchema(result.json(), 'message_list')

                href = result.json()['links'][0]['href']
                url = self.cfg.zaqar.url + href

        self.assertEqual(204, result.status_code)
Exemple #4
0
    def test_get_queue_stats_claimed(self, claimed):
        """Get stats on a queue."""
        result = self.client.put(self.queue_url)
        self.addCleanup(self.client.delete, self.queue_url)
        self.assertEqual(result.status_code, 201)

        # Post Messages to the test queue
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_claim_or_pop)

        message_url = self.queue_url + '/messages'
        result = self.client.post(message_url, data=doc)
        self.assertEqual(result.status_code, 201)

        if claimed > 0:
            claim_url = self.queue_url + '/claims?limit=' + str(claimed)
            doc = {'ttl': 300, 'grace': 300}
            result = self.client.post(claim_url, data=doc)
            self.assertEqual(result.status_code, 201)

        # Get stats on the queue.
        stats_url = self.queue_url + '/stats'
        result = self.client.get(stats_url)
        self.assertEqual(result.status_code, 200)

        self.assertQueueStats(result.json(), claimed)
    def test_get_queue_stats_claimed(self, claimed):
        """Get stats on a queue."""
        result = self.client.put(self.queue_url)
        self.addCleanup(self.client.delete, self.queue_url)
        self.assertEqual(result.status_code, 201)

        # Post Messages to the test queue
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_claim_or_pop)

        message_url = self.queue_url + '/messages'
        result = self.client.post(message_url, data=doc)
        self.assertEqual(result.status_code, 201)

        if claimed > 0:
            claim_url = self.queue_url + '/claims?limit=' + str(claimed)
            doc = {'ttl': 300, 'grace': 300}
            result = self.client.post(claim_url, data=doc)
            self.assertEqual(result.status_code, 201)

        # Get stats on the queue.
        stats_url = self.queue_url + '/stats'
        result = self.client.get(stats_url)
        self.assertEqual(result.status_code, 200)

        self.assertQueueStats(result.json(), claimed)
Exemple #6
0
    def test_message_bulk_insert(self):
        """Bulk Insert Messages into the Queue."""
        message_count = self.limits.max_messages_per_page
        doc = helpers.create_message_body(messagecount=message_count)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        # GET on posted messages
        location = result.headers['location']
        url = self.cfg.zaqar.url + location
        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)

        self.skipTest('Bug #1273335 - Get set of messages returns wrong hrefs '
                      '(happens randomly)')

        # Verify that the response json schema matches the expected schema
        self.assertSchema(result.json(), 'message_get_many')

        # Compare message metadata
        result_body = [
            result.json()[i]['body'] for i in range(len(result.json()))
        ]
        result_body.sort()

        posted_metadata = [doc[i]['body'] for i in range(message_count)]
        posted_metadata.sort()

        self.assertEqual(result_body, posted_metadata)
Exemple #7
0
    def test_message_partial_delete(self):
        """Delete Messages will be partially successful."""
        doc = helpers.create_message_body(messagecount=3)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Delete posted message
        location = result.headers['Location']
        url = self.cfg.zaqar.url + location
        url += ',nonexisting'
        result = self.client.delete(url)
        self.assertEqual(result.status_code, 204)
Exemple #8
0
    def test_message_partial_delete(self):
        """Delete Messages will be partially successful."""
        doc = helpers.create_message_body(messagecount=3)
        result = self.client.post(data=doc)

        self.assertEqual(201, result.status_code)

        # Delete posted message
        location = result.headers['Location']
        url = self.cfg.zaqar.url + location
        url += ',nonexisting'
        result = self.client.delete(url)
        self.assertEqual(204, result.status_code)
Exemple #9
0
    def test_message_partial_get(self):
        """Get Messages will be partially successful."""
        doc = helpers.create_message_body(messagecount=3)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Get posted message and a nonexisting message
        location = result.headers['Location']
        url = self.cfg.zaqar.url + location
        url += ',nonexisting'
        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)

        self.assertSchema(result.json(), "message_get_many")
Exemple #10
0
    def test_message_partial_get(self):
        """Get Messages will be partially successful."""
        doc = helpers.create_message_body(messagecount=3)
        result = self.client.post(data=doc)

        self.assertEqual(201, result.status_code)

        # Get posted message and a nonexisting message
        location = result.headers['Location']
        url = self.cfg.zaqar.url + location
        url += ',nonexisting'
        result = self.client.get(url)
        self.assertEqual(200, result.status_code)

        self.assertSchema(result.json(), "message_get_many")
Exemple #11
0
    def test_message_bulk_delete(self):
        """Bulk Delete Messages."""
        doc = helpers.create_message_body(messagecount=10)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Delete posted messages
        location = result.headers['Location']
        url = self.cfg.zaqar.url + location

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 204)

        result = self.client.get(url)
        self.assertEqual(result.status_code, 204)
Exemple #12
0
    def test_message_delete(self):
        """Delete Message."""
        # Test Setup
        doc = helpers.create_message_body(messagecount=1)
        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        # Delete posted message
        href = result.json()['resources'][0]
        url = self.cfg.zaqar.url + href

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 204)

        result = self.client.get(url)
        self.assertEqual(result.status_code, 404)
Exemple #13
0
    def test_message_delete(self):
        """Delete Message."""
        # Test Setup
        doc = helpers.create_message_body(messagecount=1)
        result = self.client.post(data=doc)
        self.assertEqual(201, result.status_code)

        # Delete posted message
        href = result.json()['resources'][0]
        url = self.cfg.zaqar.url + href

        result = self.client.delete(url)
        self.assertEqual(204, result.status_code)

        result = self.client.get(url)
        self.assertEqual(404, result.status_code)
Exemple #14
0
    def test_message_bulk_delete(self):
        """Bulk Delete Messages."""
        doc = helpers.create_message_body(messagecount=10)
        result = self.client.post(data=doc)

        self.assertEqual(201, result.status_code)

        # Delete posted messages
        location = result.headers['Location']
        url = self.cfg.zaqar.url + location

        result = self.client.delete(url)
        self.assertEqual(204, result.status_code)

        result = self.client.get(url)
        self.assertEqual(204, result.status_code)
Exemple #15
0
    def test_message_single_insert(self):
        """Insert Single Message into the Queue.

        This test also verifies that claimed messages are
        retuned (or not) depending on the include_claimed flag.
        """
        doc = helpers.create_message_body(messagecount=1)

        result = self.client.post(data=doc)
        self.assertEqual(201, result.status_code)

        response_headers = set(result.headers.keys())
        self.assertIsSubset(self.headers_response_with_body, response_headers)

        # GET on posted message
        href = result.json()['resources'][0]
        url = self.cfg.zaqar.url + href

        result = self.client.get(url)
        self.assertEqual(200, result.status_code)

        # Compare message metadata
        result_body = result.json()['body']
        posted_metadata = doc[0]['body']
        self.assertEqual(posted_metadata, result_body)

        # Post a claim & verify the include_claimed flag.
        url = self.queue_url + '/claims'
        doc = {"ttl": 300, "grace": 100}
        result = self.client.post(url, data=doc)
        self.assertEqual(201, result.status_code)

        params = {'include_claimed': True,
                  'echo': True}
        result = self.client.get(params=params)
        self.assertEqual(200, result.status_code)

        response_message_body = result.json()["messages"][0]["body"]
        self.assertEqual(posted_metadata, response_message_body)

        # By default, include_claimed = false
        result = self.client.get(self.message_url)
        self.assertEqual(204, result.status_code)
Exemple #16
0
    def test_message_single_insert(self):
        """Insert Single Message into the Queue.

        This test also verifies that claimed messages are
        retuned (or not) depending on the include_claimed flag.
        """
        doc = helpers.create_message_body(messagecount=1)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        response_headers = set(result.headers.keys())
        self.assertIsSubset(self.headers_response_with_body, response_headers)

        # GET on posted message
        href = result.json()['resources'][0]
        url = self.cfg.zaqar.url + href

        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)

        # Compare message metadata
        result_body = result.json()['body']
        posted_metadata = doc[0]['body']
        self.assertEqual(result_body, posted_metadata)

        # Post a claim & verify the include_claimed flag.
        url = self.queue_url + '/claims'
        doc = {"ttl": 300, "grace": 100}
        result = self.client.post(url, data=doc)
        self.assertEqual(result.status_code, 201)

        params = {'include_claimed': True,
                  'echo': True}
        result = self.client.get(params=params)
        self.assertEqual(result.status_code, 200)

        response_message_body = result.json()["messages"][0]["body"]
        self.assertEqual(response_message_body, posted_metadata)

        # By default, include_claimed = false
        result = self.client.get(self.message_url)
        self.assertEqual(result.status_code, 204)
Exemple #17
0
    def setUp(self):
        super(TestClaims, self).setUp()

        self.queue = uuid.uuid1()
        self.queue_url = ("{url}/{version}/queues/{queue}".format(
            url=self.cfg.zaqar.url, version="v1", queue=self.queue))

        self.client.put(self.queue_url)

        self.claim_url = self.queue_url + '/claims'
        self.client.set_base_url(self.claim_url)

        # Post Messages
        url = self.queue_url + '/messages'

        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)

        for i in range(10):
            result = self.client.post(url, data=doc)
            self.assertEqual(201, result.status_code)
Exemple #18
0
    def setUp(self):
        super(TestClaims, self).setUp()

        self.queue = uuid.uuid1()
        self.queue_url = ("{url}/{version}/queues/{queue}".format(
                          url=self.cfg.zaqar.url,
                          version="v1",
                          queue=self.queue))

        self.client.put(self.queue_url)

        self.claim_url = self.queue_url + '/claims'
        self.client.set_base_url(self.claim_url)

        # Post Messages
        url = self.queue_url + '/messages'

        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)

        for i in range(10):
            result = self.client.post(url, data=doc)
            self.assertEqual(result.status_code, 201)