Ejemplo n.º 1
0
    def test_get_message(self, url_param):
        """Get Messages."""
        if url_param:
            expected_msg_count = int(url_param.split('&limit=')[1])
        else:
            expected_msg_count = 10

        # Test Setup
        doc = helpers.get_message_body(messagecount=20)
        result = http.post(self.message_url, self.header, doc)
        self.assertEqual(result.status_code, 201)

        url = self.message_url + '?echo=True' + url_param

        #Follow the hrefs & perform GET, till the end of messages i.e. http 204
        while result.status_code in [201, 200]:
            result = http.get(url, self.header)
            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)

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

        self.assertEqual(result.status_code, 204)
Ejemplo n.º 2
0
    def test_get_message(self, url_param):
        """Get Messages."""
        if url_param:
            expected_msg_count = int(url_param.split('&limit=')[1])
        else:
            expected_msg_count = 10

        # Test Setup
        doc = helpers.get_message_body(messagecount=20)
        result = http.post(self.message_url, self.header, doc)
        self.assertEqual(result.status_code, 201)

        url = self.message_url + '?echo=True' + url_param

        #Follow the hrefs & perform GET, till the end of messages i.e. http 204
        while result.status_code in [201, 200]:
            result = http.get(url, self.header)
            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)

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

        self.assertEqual(result.status_code, 204)
Ejemplo n.º 3
0
    def test_message_get_invalid_limit(self, limit):
        """Get Messages with invalid value for limit.

        Allowed values for limit are 0 < limit <= 20(configurable).
        """
        url = self.message_url + '?limit=' + str(limit)
        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 400)
Ejemplo n.º 4
0
    def test_message_get_invalid_limit(self, limit):
        """Get Messages with invalid value for limit.

        Allowed values for limit are 0 < limit <= 20(configurable).
        """
        url = self.message_url + '?limit=' + str(limit)
        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 400)
Ejemplo n.º 5
0
    def test_insert_queue_metadata(self, doc):
        """Insert Queue with empty json."""
        result = http.put(self.queue_metadata_url, self.header,
                          json.dumps(doc))
        self.assertEqual(result.status_code, 204)

        result = http.get(self.queue_metadata_url, self.header)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.json(), doc)
Ejemplo n.º 6
0
    def test_check_queue_exists_negative(self):
        """Checks non-existing queue."""
        url = self.base_url + '/queues/nonexistingqueue'

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 404)

        result = http.head(url, self.header)
        self.assertEqual(result.status_code, 404)
Ejemplo n.º 7
0
    def test_insert_queue_metadata(self, doc):
        """Insert Queue with empty json."""
        result = http.put(self.queue_metadata_url, self.header,
                          json.dumps(doc))
        self.assertEqual(result.status_code, 204)

        result = http.get(self.queue_metadata_url, self.header)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.json(), doc)
Ejemplo n.º 8
0
    def test_check_queue_exists_negative(self):
        """Checks non-existing queue."""
        url = self.base_url + '/queues/nonexistingqueue'

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 404)

        result = http.head(url, self.header)
        self.assertEqual(result.status_code, 404)
Ejemplo n.º 9
0
    def test_check_queue_exists(self):
        """Checks if queue exists."""
        url = self.base_url + '/queues/testqueue'
        http.put(url, self.header)

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 204)

        result = http.head(url, self.header)
        self.assertEqual(result.status_code, 204)
Ejemplo n.º 10
0
    def test_check_queue_exists(self):
        """Checks if queue exists."""
        url = self.base_url + '/queues/testqueue'
        http.put(url, self.header)

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 204)

        result = http.head(url, self.header)
        self.assertEqual(result.status_code, 204)
Ejemplo n.º 11
0
    def test_insert_queue_invalid_name(self, queue_name):
        """Create Queue."""
        self.url = self.base_url + '/queues/' + queue_name

        result = http.put(self.url, self.header)
        self.assertEqual(result.status_code, 400)

        self.url = self.url + '/metadata'
        result = http.get(self.url, self.header)
        self.assertEqual(result.status_code, 404)
Ejemplo n.º 12
0
    def test_insert_queue_invalid_name(self, queue_name):
        """Create Queue."""
        self.url = self.base_url + '/queues/' + queue_name

        result = http.put(self.url, self.header)
        self.assertEqual(result.status_code, 400)

        self.url = self.url + '/metadata'
        result = http.get(self.url, self.header)
        self.assertEqual(result.status_code, 404)
Ejemplo n.º 13
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.get_message_body(messagecount=1)

        result = http.post(self.message_url, self.header, 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.marconi.url + href

        result = http.get(url, self.header)
        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 = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 201)

        url = self.message_url + '?include_claimed=true&echo=true'
        result = http.get(url, self.header)
        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 = http.get(self.message_url, self.header)
        self.assertEqual(result.status_code, 204)
Ejemplo n.º 14
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.get_message_body(messagecount=1)

        result = http.post(self.message_url, self.header, 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.marconi.url + href

        result = http.get(url, self.header)
        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 = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 201)

        url = self.message_url + '?include_claimed=true&echo=true'
        result = http.get(url, self.header)
        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 = http.get(self.message_url, self.header)
        self.assertEqual(result.status_code, 204)
Ejemplo n.º 15
0
    def test_list_queues(self):
        """List Queues."""
        url = self.base_url + '/queues'
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 200)

        response_keys_actual = result.json().keys()
        response_keys_actual.sort()
        response_keys_expected = ['links', 'queues']
        self.assertEqual(response_keys_actual, response_keys_expected)
Ejemplo n.º 16
0
    def test_list_queues_detailed(self):
        """List Queues with detailed = True."""
        url = self.base_url + '/queues?detailed=True'
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 200)

        response_keys_actual = result.json()['queues'][0].keys()
        response_keys_actual.sort()
        response_keys_expected = ['href', 'metadata', 'name']
        self.assertEqual(response_keys_actual, response_keys_expected)
Ejemplo n.º 17
0
    def test_list_queues_detailed(self):
        """List Queues with detailed = True."""
        url = self.base_url + '/queues?detailed=True'
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 200)

        response_keys_actual = result.json()['queues'][0].keys()
        response_keys_actual.sort()
        response_keys_expected = ['href', 'metadata', 'name']
        self.assertEqual(response_keys_actual, response_keys_expected)
Ejemplo n.º 18
0
    def test_list_queues(self):
        """List Queues."""
        url = self.base_url + '/queues'
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 200)

        response_keys_actual = result.json().keys()
        response_keys_actual.sort()
        response_keys_expected = ['links', 'queues']
        self.assertEqual(response_keys_actual, response_keys_expected)
Ejemplo n.º 19
0
    def test_query_claim(self):
        """Query Claim."""
        url = self.claim_url + '?limit=1'
        doc = '{"ttl": 300, "grace": 100}'

        result = http.post(url, self.header, doc)
        location = result.headers['Location']

        url = self.cfg.marconi.url + location

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 200)
Ejemplo n.º 20
0
    def test_message_bulk_get_negative(self):
        """GET more messages by id than allowed in a single request.

        By default, max messages that can be fetched in a single
        request is 20.
        """
        url = self.message_url + '?ids=' \
            + ','.join(str(i) for i in
                       range(self.limits.message_paging_uplimit + 1))
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 400)
Ejemplo n.º 21
0
    def test_query_claim(self):
        """Query Claim."""
        url = self.claim_url + '?limit=1'
        doc = '{"ttl": 300, "grace": 100}'

        result = http.post(url, self.header, doc)
        location = result.headers['Location']

        url = self.cfg.marconi.url + location

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 200)
Ejemplo n.º 22
0
    def test_message_bulk_get_negative(self):
        """GET more messages by id than allowed in a single request.

        By default, max messages that can be fetched in a single
        request is 20.
        """
        url = self.message_url + '?ids=' \
            + ','.join(str(i) for i in
                       range(self.limits.message_paging_uplimit + 1))
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 400)
Ejemplo n.º 23
0
    def test_message_partial_get(self):
        """Get Messages will be partially successful."""
        doc = helpers.get_message_body(messagecount=3)
        result = http.post(self.message_url, self.header, doc)

        self.assertEqual(result.status_code, 201)

        # Get posted message and a nonexisting message
        location = result.headers['Location']
        url = self.cfg.marconi.url + location
        url += ',nonexisting'
        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 200)
Ejemplo n.º 24
0
    def test_message_partial_get(self):
        """Get Messages will be partially successful."""
        doc = helpers.get_message_body(messagecount=3)
        result = http.post(self.message_url, self.header, doc)

        self.assertEqual(result.status_code, 201)

        # Get posted message and a nonexisting message
        location = result.headers['Location']
        url = self.cfg.marconi.url + location
        url += ',nonexisting'
        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 200)
Ejemplo n.º 25
0
    def test_insert_queue_with_metadata(self):
        """Insert queue with a non-empty request body."""
        self.url = self.base_url + '/queues/hasmetadata'
        doc = '{"queue": "Has Metadata"}'
        result = http.put(self.url, self.header, doc)

        self.assertEqual(result.status_code, 201)

        self.url = self.base_url + '/queues/hasmetadata/metadata'
        result = http.get(self.url, self.header)

        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.json(), {})
Ejemplo n.º 26
0
    def test_insert_queue_with_metadata(self):
        """Insert queue with a non-empty request body."""
        self.url = self.base_url + '/queues/hasmetadata'
        doc = '{"queue": "Has Metadata"}'
        result = http.put(self.url, self.header, doc)

        self.assertEqual(result.status_code, 201)

        self.url = self.base_url + '/queues/hasmetadata/metadata'
        result = http.get(self.url, self.header)

        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.json(), {})
Ejemplo n.º 27
0
    def test_insert_queue(self, queue_name):
        """Create Queue."""
        self.url = self.base_url + '/queues/' + queue_name

        result = http.put(self.url, self.header)
        self.assertEqual(result.status_code, 201)

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

        self.url = self.url + '/metadata'
        result = http.get(self.url, self.header)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.json(), {})
Ejemplo n.º 28
0
    def test_insert_queue(self, queue_name):
        """Create Queue."""
        self.url = self.base_url + '/queues/' + queue_name

        result = http.put(self.url, self.header)
        self.assertEqual(result.status_code, 201)

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

        self.url = self.url + '/metadata'
        result = http.get(self.url, self.header)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.json(), {})
Ejemplo n.º 29
0
    def test_message_bulk_delete(self):
        """Bulk Delete Messages."""
        doc = helpers.get_message_body(messagecount=10)
        result = http.post(self.message_url, self.header, doc)

        self.assertEqual(result.status_code, 201)

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

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

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 204)
Ejemplo n.º 30
0
    def test_message_delete(self):
        """Delete Message."""
        # Test Setup
        doc = helpers.get_message_body(messagecount=1)
        result = http.post(self.message_url, self.header, doc)
        self.assertEqual(result.status_code, 201)

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

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

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 404)
Ejemplo n.º 31
0
    def test_message_delete(self):
        """Delete Message."""
        # Test Setup
        doc = helpers.get_message_body(messagecount=1)
        result = http.post(self.message_url, self.header, doc)
        self.assertEqual(result.status_code, 201)

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

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

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 404)
Ejemplo n.º 32
0
    def test_message_bulk_delete(self):
        """Bulk Delete Messages."""
        doc = helpers.get_message_body(messagecount=10)
        result = http.post(self.message_url, self.header, doc)

        self.assertEqual(result.status_code, 201)

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

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

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 204)
Ejemplo n.º 33
0
    def test_claim_patch(self):
        """Update Claim."""
        #Test Setup - Post Claim
        doc = '{"ttl": 300, "grace": 400}'

        result = http.post(self.claim_url, self.header, doc)
        self.assertEqual(result.status_code, 201)

        #Patch Claim
        claim_location = result.headers['Location']
        url = self.cfg.marconi.url + claim_location
        doc_updated = '{"ttl": 300}'

        result = http.patch(url, self.header, doc_updated)
        self.assertEqual(result.status_code, 204)

        #verify that the claim TTL is updated
        result = http.get(url, self.header)
        new_ttl = result.json()['ttl']
        self.assertEqual(new_ttl, 300)
Ejemplo n.º 34
0
    def test_claim_patch(self):
        """Update Claim."""
        #Test Setup - Post Claim
        doc = '{"ttl": 300, "grace": 400}'

        result = http.post(self.claim_url, self.header, doc)
        self.assertEqual(result.status_code, 201)

        #Patch Claim
        claim_location = result.headers['Location']
        url = self.cfg.marconi.url + claim_location
        doc_updated = '{"ttl": 300}'

        result = http.patch(url, self.header, doc_updated)
        self.assertEqual(result.status_code, 204)

        #verify that the claim TTL is updated
        result = http.get(url, self.header)
        new_ttl = result.json()['ttl']
        self.assertEqual(new_ttl, 300)
Ejemplo n.º 35
0
    def test_message_bulk_insert(self):
        """Bulk Insert Messages into the Queue."""
        message_count = 10
        doc = helpers.get_message_body(messagecount=message_count)

        result = http.post(self.message_url, self.header, doc)
        self.assertEqual(result.status_code, 201)

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

        # 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)
Ejemplo n.º 36
0
    def test_message_bulk_insert(self):
        """Bulk Insert Messages into the Queue."""
        message_count = 10
        doc = helpers.get_message_body(messagecount=message_count)

        result = http.post(self.message_url, self.header, doc)
        self.assertEqual(result.status_code, 201)

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

        # 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)
Ejemplo n.º 37
0
    def test_check_health(self):
        """Test health endpoint."""
        url = self.base_url + '/health'
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 204)
Ejemplo n.º 38
0
    def test_get_queue_malformed_marker(self):
        """List queues with invalid marker."""
        url = self.base_url + '/queues?marker=invalid'

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 204)
Ejemplo n.º 39
0
    def test_get_messages_malformed_marker(self):
        """Get messages with non-existing marker."""
        url = self.message_url + '?marker=invalid'

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 204)
Ejemplo n.º 40
0
    def test_get_messages_malformed_marker(self):
        """Get messages with non-existing marker."""
        url = self.message_url + '?marker=invalid'

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 204)
Ejemplo n.º 41
0
    def test_get_queue_malformed_marker(self):
        """List queues with invalid marker."""
        url = self.base_url + '/queues?marker=invalid'

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 204)
Ejemplo n.º 42
0
    def test_check_health(self):
        """Test health endpoint."""
        url = self.base_url + '/health'
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 204)
Ejemplo n.º 43
0
    def test_list_queue_invalid_limit(self, limit):
        """List Queues with a limit value that is not allowed."""
        url = self.base_url + '/queues?limit=' + str(limit)
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 400)
Ejemplo n.º 44
0
    def test_list_queue_invalid_limit(self, limit):
        """List Queues with a limit value that is not allowed."""
        url = self.base_url + '/queues?limit=' + str(limit)
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 400)