Exemple #1
0
    def setUp(self):
        super(TestClaims, self).setUp()

        self.queue_url = self.cfg.base_url + '/queues/{}'.format(uuid.uuid1())
        http.put(self.queue_url, self.header)

        self.claim_url = self.queue_url + '/claims'

        #Post Messages
        url = self.queue_url + '/messages'
        doc = helpers.get_message_body(
            messagecount=self.cfg.message_paging_uplimit)
        for i in range(25):
            http.post(url, self.header, doc)
Exemple #2
0
    def setUp(self):
        super(TestClaims, self).setUp()

        self.queue_url = self.cfg.base_url + '/queues/{}'.format(uuid.uuid1())
        http.put(self.queue_url, self.header)

        self.claim_url = self.queue_url + '/claims'

        #Post Messages
        url = self.queue_url + '/messages'
        doc = helpers.get_message_body(messagecount=
                                       self.cfg.message_paging_uplimit)
        for i in range(25):
            http.post(url, self.header, doc)
Exemple #3
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)
Exemple #4
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)
Exemple #5
0
    def test_message_bulk_insert_60(self):
        """Insert more than max allowed messages.

        Marconi allows  a maximum of 50 message per POST.
        """
        doc = helpers.get_message_body(messagecount=60)

        result = http.post(self.message_url, self.header, doc)
        self.assertEqual(result.status_code, 400)
Exemple #6
0
    def test_message_bulk_insert_60(self):
        """Insert more than max allowed messages.

        Marconi allows  a maximum of 50 message per POST.
        """
        doc = helpers.get_message_body(messagecount=60)

        result = http.post(self.message_url, self.header, doc)
        self.assertEqual(result.status_code, 400)
Exemple #7
0
    def test_claim_invalid_limit(self, grace):
        """Post Claim with invalid limit.

        The request url will have a limit outside the allowed range.
        Allowed limit values are 0 < limit <= 20(default max).
        """
        doc = {"ttl": 100, "grace": grace}

        result = http.post(self.claim_url, self.header, json.dumps(doc))
        self.assertEqual(result.status_code, 400)
Exemple #8
0
    def test_claim_invalid_limit(self, grace):
        """Post Claim with invalid limit.

        The request url will have a limit outside the allowed range.
        Allowed limit values are 0 < limit <= 20(default max).
        """
        doc = {"ttl": 100, "grace": grace}

        result = http.post(self.claim_url, self.header, json.dumps(doc))
        self.assertEqual(result.status_code, 400)
Exemple #9
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)
Exemple #10
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)
Exemple #11
0
    def test_claim_invalid_ttl(self, ttl):
        """Post Claim with invalid TTL.

        The request JSON body will have a TTL value
        outside the allowed range.Allowed ttl values is
        60 <= ttl <= 43200.
        """
        doc = {"ttl": ttl, "grace": 100}

        result = http.post(self.claim_url, self.header, json.dumps(doc))
        self.assertEqual(result.status_code, 400)
Exemple #12
0
    def test_claim_invalid_ttl(self, ttl):
        """Post Claim with invalid TTL.

        The request JSON body will have a TTL value
        outside the allowed range.Allowed ttl values is
        60 <= ttl <= 43200.
        """
        doc = {"ttl": ttl, "grace": 100}

        result = http.post(self.claim_url, self.header, json.dumps(doc))
        self.assertEqual(result.status_code, 400)
Exemple #13
0
    def test_claim_invalid_grace(self, grace):
        """Post Claim with invalid grace.

        The request JSON body will have a grace value
        outside the allowed range.Allowed grace values is
        60 <= grace <= 43200.
        """
        doc = {"ttl": 100, "grace": grace}

        result = http.post(self.claim_url, self.header, json.dumps(doc))
        self.assertEqual(result.status_code, 400)
Exemple #14
0
    def test_claim_more_than_allowed(self):
        """Claim more than max allowed per request.

        Marconi allows a maximum of 20 messages per claim.
        """
        url = self.claim_url + '?limit=' + \
            str(self.cfg.message_paging_uplimit + 1)
        doc = '{"ttl": 300, "grace": 100}'

        result = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 400)
Exemple #15
0
    def test_claim_more_than_allowed(self):
        """Claim more than max allowed per request.

        Marconi allows a maximum of 20 messages per claim.
        """
        url = self.claim_url + '?limit=' + \
            str(self.cfg.message_paging_uplimit + 1)
        doc = '{"ttl": 300, "grace": 100}'

        result = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 400)
Exemple #16
0
    def test_claim_invalid_grace(self, grace):
        """Post Claim with invalid grace.

        The request JSON body will have a grace value
        outside the allowed range.Allowed grace values is
        60 <= grace <= 43200.
        """
        doc = {"ttl": 100, "grace": grace}

        result = http.post(self.claim_url, self.header, json.dumps(doc))
        self.assertEqual(result.status_code, 400)
Exemple #17
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)
Exemple #18
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)
Exemple #19
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)
Exemple #20
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)
Exemple #21
0
def get_keystone_token(conf):
    """Gets Keystone Auth token."""
    req_json = {"auth": {"passwordCredentials": {"username": conf.auth.username, "password": conf.auth.password}}}

    header = {"Content-Type": "application/json", "Accept": "application/json"}

    url = conf.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
Exemple #22
0
    def test_claim_release(self):
        """Release Claim."""
        doc = '{"ttl": 300, "grace": 100}'

        result = http.post(self.claim_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)
Exemple #23
0
    def test_claim_release(self):
        """Release Claim."""
        doc = '{"ttl": 300, "grace": 100}'

        result = http.post(self.claim_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)
Exemple #24
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)
Exemple #25
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)
Exemple #26
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)
Exemple #27
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)
Exemple #28
0
    def test_delete_claimed_message(self):
        """Delete message belonging to a Claim."""
        #Test Setup - Post claim
        doc = '{"ttl": 60, "grace": 60}'

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

        href_list = [result.json()[i]['href']
                     for i in range(len(result.json()))]
        url_list = [self.cfg.base_server + href
                    for href in href_list]

        #Delete Claimed Messages
        for url in url_list:
            result = http.delete(url, self.header)
            self.assertEqual(result.status_code, 204)
Exemple #29
0
    def test_delete_claimed_message(self):
        """Delete message belonging to a Claim."""
        #Test Setup - Post claim
        doc = '{"ttl": 60, "grace": 60}'

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

        href_list = [
            result.json()[i]['href'] for i in range(len(result.json()))
        ]
        url_list = [self.cfg.base_server + href for href in href_list]

        #Delete Claimed Messages
        for url in url_list:
            result = http.delete(url, self.header)
            self.assertEqual(result.status_code, 204)
Exemple #30
0
    def test_claim_messages(self, url_appender):
        """Claim messages."""
        if url_appender:
            message_count = int(url_appender.split('?limit=')[1])
        else:
            message_count = 10

        url = self.claim_url + url_appender
        doc = '{"ttl": 300, "grace": 100}'

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

        actual_message_count = len(result.json())
        self.assertMessageCount(message_count, actual_message_count)

        response_headers = set(result.headers.keys())
        self.assertIsSubset(self.headers_response_with_body, response_headers)
Exemple #31
0
    def test_claim_messages(self, url_appender):
        """Claim messages."""
        if url_appender:
            message_count = int(url_appender.split('?limit=')[1])
        else:
            message_count = 10

        url = self.claim_url + url_appender
        doc = '{"ttl": 300, "grace": 100}'

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

        actual_message_count = len(result.json())
        self.assertMessageCount(message_count, actual_message_count)

        response_headers = set(result.headers.keys())
        self.assertIsSubset(self.headers_response_with_body, response_headers)
Exemple #32
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)
Exemple #33
0
    def test_patch_claim_invalid_ttl(self, ttl):
        """Patch Claim with invalid TTL.

        The request JSON body will have a TTL value
        outside the allowed range.Allowed ttl values is
        60 <= ttl <= 43200.
        """
        doc = '{"ttl": 100, "grace": 100}'

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

        #Patch Claim.
        doc = {"ttl": ttl}
        result = http.patch(url, self.header, json.dumps(doc))
        self.assertEqual(result.status_code, 400)
Exemple #34
0
    def test_patch_claim_invalid_ttl(self, ttl):
        """Patch Claim with invalid TTL.

        The request JSON body will have a TTL value
        outside the allowed range.Allowed ttl values is
        60 <= ttl <= 43200.
        """
        doc = '{"ttl": 100, "grace": 100}'

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

        #Patch Claim.
        doc = {"ttl": ttl}
        result = http.patch(url, self.header, json.dumps(doc))
        self.assertEqual(result.status_code, 400)
Exemple #35
0
def get_keystone_token():
    """Gets Keystone Auth token."""
    req_json = {
        'auth': {
            'passwordCredentials': {
                'username': CFG.username,
                'password': CFG.password
            },
        },
    }

    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
Exemple #36
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)
Exemple #37
0
def get_keystone_token():
    """Gets Keystone Auth token."""
    req_json = {
        'auth': {
            'passwordCredentials': {
                'username': CFG.username,
                'password': CFG.password
            },
        },
    }

    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
Exemple #38
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)
Exemple #39
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)