Beispiel #1
0
    def test_011_claim_negative_int(self):
        """Post Claim with negative TTL/ Grace."""
        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": -100, "grace": 100}'

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

        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 100, "grace": -100}'

        result = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 400)
Beispiel #2
0
    def test_002_message_bulk_insert(self):
        """Bulk Insert Messages into the Queue."""
        message_count = 30
        doc = msgfnlib.get_message_body(messagecount=message_count)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'
        result = http.post(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()['messages'][i]['body']
                       for i in range(len(result.json()['messages']))]
        result_body.sort()

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

        self.assertEqual(result_body, posted_metadata)
Beispiel #3
0
    def test_007_claim_expired(self):
        """Update, Get and Release Expired Claim."""
        #Test Setup - Post Claim.
        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 1, "grace": 0}'

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

        time.sleep(2)

        #Extract claim location and construct the claim URL.
        location = result.headers['Location']
        url = self.cfg.base_server + location

        #Update Expired Claim.
        doc = '{"ttl": 300}'
        result = http.patch(url, self.header, doc)
        self.assertEqual(result.status_code, 404)

        #Get Expired Claim.
        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 404)

        #Release Expired Claim.
        result = http.delete(url, self.header)
        self.assertEqual(result.status_code, 204)
Beispiel #4
0
    def test_010_claim_big_int(self):
        """Post Claim with big TTL/ Grace.

        The request JSON body will have an integer
        outside the range -2^63 ~ 2^63-1.
        """
        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 10000000000000000000, "grace": 100}'

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

        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 100, "grace": -10000000000000000000}'

        result = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 400)
Beispiel #5
0
    def test_001_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 = msgfnlib.get_message_body(messagecount=1)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'

        result = http.post(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.cfg.base_url + '/queues/messagetestqueue/claims'
        doc = '{"ttl": 300, "grace": 100}'
        result = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 200)

        url = self.cfg.base_url + '/queues/messagetestqueue/messages' \
                                  '?include_claimed=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
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'
        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 204)
Beispiel #6
0
    def test_007_message_bulk_insert_60(self):
        """Insert more than max allowed messages.

        Marconi allows  a maximum of 50 message per POST.
        """
        doc = msgfnlib.get_message_body(messagecount=60)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'
        result = http.post(url, self.header, doc)

        self.assertEqual(result.status_code, 400)
Beispiel #7
0
    def test_003_claim_15messages(self):
        """Claim 15 messages."""
        message_count = 15
        url = self.cfg.base_url + '/queues/claimtestqueue/claims?limit=15'
        doc = '{"ttl": 300, "grace": 100}'

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

        test_result_flag = claimfnlib.verify_claim_msg(
            message_count, result.headers, result.text)
        self.assertEqual(test_result_flag, True)
Beispiel #8
0
    def test_000_claim_setup(self):
        """Create Queue, Post Messages for Claim Tests."""
        url = self.cfg.base_url + '/queues/claimtestqueue'

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

        #Post Messages
        url = self.cfg.base_url + '/queues/claimtestqueue/messages'
        doc = msgfnlib.get_message_body(messagecount=50)
        for i in range(5):
            result = http.post(url, self.header, doc)
            self.assertEqual(result.status_code, 201)
Beispiel #9
0
    def test_006_claim_delete_message(self):
        """Delete message belonging to a Claim."""
        #Test Setup - Post claim
        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 60, "grace": 10}'

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

        #Delete Claimed Message & Verify the delete
        test_result_flag = claimfnlib.delete_claimed_msgs(
            result.headers, result.text)
        self.assertEqual(test_result_flag, True)
Beispiel #10
0
    def test_005_claim_patch(self):
        """Update Claim."""
        #Test Setup - Post Claim
        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 300, "grace": 100}'

        result = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 200)

        #Update Claim & Verify the patch
        test_result_flag = claimfnlib.patch_claim(
            result.headers, result.text)
        self.assertEqual(test_result_flag, True)
Beispiel #11
0
    def test_009_message_partial_delete(self):
        """Delete Messages will be partially successful."""
        doc = msgfnlib.get_message_body(messagecount=3)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'
        result = http.post(url, self.header, doc)

        self.assertEqual(result.status_code, 201)

        #Delete posted message
        location = result.headers['Location']
        url = self.cfg.base_server + location
        url += ',nonexisting'
        result = http.delete(url, self.header)
        self.assertEqual(result.status_code, 204)
Beispiel #12
0
    def test_002_claim_default_messages(self):
        """Claim messages with no URL parameters.

        By default, Marconi will return 10 messages.
        """
        default_message_count = 10
        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 300, "grace": 100}'

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

        test_result_flag = claimfnlib.verify_claim_msg(
            default_message_count, result.headers, result.text)
        self.assertEqual(test_result_flag, True)
Beispiel #13
0
    def test_001_claim_2messages(self):
        """Claim 2 messages."""
        message_count = 2
        url = self.cfg.base_url + '/queues/claimtestqueue/claims?limit=2'
        doc = '{"ttl": 300, "grace": 100}'

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

        test_result_flag = claimfnlib.verify_claim_msg(
            message_count, result.headers, result.text)
        self.assertEqual(test_result_flag, True)

        response_headers = set(result.headers.keys())
        self.assertIsSubset(self.headers_response_with_body, response_headers)
Beispiel #14
0
    def test_009_claim_release(self):
        """Release Claim."""
        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 300, "grace": 100}'

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

        #Extract claim location and construct the claim URL.
        location = result.headers['Location']
        url = self.cfg.base_server + location

        #Release Claim.
        result = http.delete(url, self.header)
        self.assertEqual(result.status_code, 204)
Beispiel #15
0
    def test_004_claim_55messages(self):
        """Claim more than max allowed per request.

        Marconi allows a maximum of 50 messages per claim.
        """
        message_count = 55
        url = self.cfg.base_url + '/queues/claimtestqueue/claims?limit=55'
        doc = '{"ttl": 300, "grace": 100}'

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

        test_result_flag = claimfnlib.verify_claim_msg(
            message_count, result.headers, result.text)
        self.assertEqual(test_result_flag, True)
Beispiel #16
0
    def test_006_message_delete(self):
        """Delete Message."""
        doc = msgfnlib.get_message_body(messagecount=1)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'
        result = http.post(url, self.header, doc)

        self.assertEqual(result.status_code, 201)

        #Delete posted message
        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, 404)
Beispiel #17
0
    def test_006_message_delete(self):
        """Delete Message."""
        doc = msgfnlib.get_message_body(messagecount=1)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'
        result = http.post(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)
Beispiel #18
0
    def test_008_claim_expired_delete_message(self):
        """Get & Delete Message from an Expired Claim."""
        #Test Setup - Post Claim.
        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 1, "grace": 0}'

        result = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 200)

        time.sleep(2)

        #Create url, using message location from claim response.
        message_location = result.json()[0]['href']
        url = self.cfg.base_server + message_location

        #Delete message with expired claim ID
        result = http.delete(url, self.header)
        self.assertEqual(result.status_code, 403)
Beispiel #19
0
    def test_001_message_single_insert(self):
        """Insert Single Message into the Queue."""
        doc = msgfnlib.get_message_body(messagecount=1)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'
        result = http.post(url, self.header, doc)

        self.assertEqual(result.status_code, 201)

        #GET on posted message
        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()[0]['body']
        posted_metadata = doc[0]['body']
        self.assertEqual(result_body, posted_metadata)
Beispiel #20
0
    def test_005_claim_patch(self):
        """Update Claim."""
        #Test Setup - Post Claim
        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 300, "grace": 400}'

        result = http.post(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)

        test_result_flag = claimfnlib.verify_patch_claim(url,
                                                         self.header, 300)
        self.assertEqual(test_result_flag, True)
Beispiel #21
0
def get_keystone_token():
    """Gets Keystone Auth token."""
    req_json = {
        'auth': {
            'passwordCredentials': {
                'username': CFG.username,
                'password': CFG.password
            },
        },
    }

    header = '{"Host":  "identity.api.rackspacecloud.com",'
    header += '"Content-Type": "application/json","Accept":"application/json"}'
    url = CFG.auth_url

    response = http.post(url=url, header=header, body=req_json)
    response_body = json.loads(response.text)

    auth_token = response_body['access']['token']['id']

    return auth_token
Beispiel #22
0
    def test_008_claim_expired_delete_message(self):
        """Get & Delete Message from an Expired Claim."""
        #Test Setup - Post Claim.
        url = self.cfg.base_url + '/queues/claimtestqueue/claims'
        doc = '{"ttl": 1, "grace": 0}'

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

        time.sleep(2)

        #Get Claim & Message Locations.
        claim_location = result.headers['Location']
        message_location = result.json()[0]['href']

        #Delete message with expired claim ID
        url = self.cfg.base_server + message_location
        result = http.delete(url, self.header)
        self.assertEqual(result.status_code, 403)

        #Delete Expired Claim.
        url = self.cfg.base_server + claim_location
        result = http.delete(url, self.header)
        self.assertEqual(result.status_code, 204)