示例#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.base_server + href

        self.assertEqual(result.status_code, 204)
示例#2
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)
示例#3
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)
示例#4
0
    def test_check_queue_exists_negative(self):
        """Checks non-existing queue."""
        url = self.cfg.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)
示例#5
0
    def test_insert_queue_invalid_name(self, queue_name):
        """Create Queue."""
        self.url = self.cfg.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)
示例#6
0
    def test_check_queue_exists(self):
        """Checks if queue exists."""
        url = self.cfg.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)
示例#7
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.base_server + 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)
示例#8
0
    def test_list_queues_detailed(self):
        """List Queues with detailed = True."""
        url = self.cfg.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)
示例#9
0
    def test_list_queues(self):
        """List Queues."""
        url = self.cfg.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)
示例#10
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.base_server + location

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 200)
示例#11
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.cfg.message_paging_uplimit + 1))
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 400)
示例#12
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.base_server + location
        url += ',nonexisting'
        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 200)
示例#13
0
    def test_insert_queue_with_metadata(self):
        """Insert queue with a non-empty request body."""
        self.url = self.cfg.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.cfg.base_url + '/queues/hasmetadata/metadata'
        result = http.get(self.url, self.header)

        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.json(), {})
示例#14
0
    def test_insert_queue(self, queue_name):
        """Create Queue."""
        self.url = self.cfg.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(), {})
示例#15
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.base_server + 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)
示例#16
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.base_server + 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)
示例#17
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.base_server + 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)
示例#18
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.base_server + 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)
示例#19
0
    def test_list_queue_invalid_limit(self, limit):
        """List Queues with a limit value that is not allowed."""
        url = self.cfg.base_url + '/queues?limit=' + str(limit)
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 400)
示例#20
0
    def test_check_health(self):
        """Test health endpoint."""
        url = self.cfg.base_url + '/health'
        result = http.get(url, self.header)

        self.assertEqual(result.status_code, 204)
示例#21
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)
示例#22
0
    def test_get_queue_malformed_marker(self):
        """List queues with invalid marker."""
        url = self.cfg.base_url + '/queues?marker=invalid'

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