def patch_claim(*claim_response): """Patches a claim & verifies the results. Extracts claim id from the POST response input & updates the claim. If PATCH claim succeeds, verifies that the claim TTL is extended. :param *claim_response: [headers, body] returned for the original claim """ test_result_flag = False headers = claim_response[0] location = headers['Location'] url = functionlib.create_url_from_appender(location) header = functionlib.create_marconi_headers() ttl_value = 300 payload = '{"ttl": ttlvalue }' payload = payload.replace('ttlvalue', str(ttl_value)) patch_response = http.patch(url, header, body=payload) if patch_response.status_code == 204: test_result_flag = verify_patch_claim(url, header, ttl_value) else: print 'Patch HTTP Response code: {}'.format(patch_response.status_code) print patch_response.headers print patch_response.text return test_result_flag
def release_claim(*claim_response): """Deletes claim & verifies the delete was successful. Extracts claim id from the POST response input & deletes the claim. If DELETE claim succeeds, verifies that a GET claim returns 404. :param *claim_response: [header, body] returned for post claim request. """ test_result_flag = False headers = claim_response[0] location = headers['Location'] url = functionlib.create_url_from_appender(location) header = functionlib.create_marconi_headers() release_response = http.delete(url, header) if release_response.status_code == 204: test_result_flag = functionlib.verify_delete(url, header) else: print 'Release Claim HTTP code:{}'.format(release_response.status_code) print release_response.headers print release_response.text assert test_result_flag, 'Release Claim Failed' if not test_result_flag: assert test_result_flag, 'Get claim after the release failed'
def setUp(self): super(TestClaims, self).setUp() self.cfg = config.Config() self.header = functionlib.create_marconi_headers() self.headers_response_with_body = set(['location', 'content-type'])
def delete_msg(*postresponse): """Post DELETE message & verifies that a subsequent GET returns 404. :param *postresponse: [headers, body] returned for post message request. """ test_result_flag = False headers = str(postresponse[0]) headers = headers.replace("'", '"') headers = json.loads(headers) location = headers['location'] url = functionlib.create_url_from_appender(location) header = functionlib.create_marconi_headers() deletemsg = http.delete(url, header) if deletemsg.status_code == 204: test_result_flag = functionlib.verify_delete(url, header) else: print('DELETE message failed') print('URL') print(url) print('headers') print(header) print('Response Body') print(deletemsg.text) print('DELETE Code {}'.format(deletemsg.status_code)) return test_result_flag
def verify_post_msg(msg_headers, posted_body): """Verifies the response of POST Message(s). Retrieves the posted Message(s) & validates the message metadata. :param msg_headers: headers returned for post message request. :param posted_body: message metadata(s) in the post message request. """ test_result_flag = False location = msg_headers['location'] url = functionlib.create_url_from_appender(location) header = functionlib.create_marconi_headers() getmsg = http.get(url, header) if getmsg.status_code == 200: test_result_flag = True else: print('Failed to GET {}'.format(url)) print('Request Header') print(header) print('Response Headers') print(getmsg.headers) print('Response Body') print(getmsg.text) return test_result_flag
def list_queues(href): """Lists queue using the href value. :param href: href returned by a previous list queue request. """ test_result_flag = False url = functionlib.create_url_from_appender(href) header = functionlib.create_marconi_headers() list_queue_response = http.get(url, header) if list_queue_response.status_code == 200: headers = list_queue_response.headers text = list_queue_response.text test_result_flag = verify_list_queues(headers, text) elif list_queue_response.status_code == 204: test_result_flag = True return test_result_flag
def get_next_msgset(responsetext): """Follows the href path & GETs the next batch of messages recursively.""" test_result_flag = False href = get_href(responsetext) url = functionlib.create_url_from_appender(href) header = functionlib.create_marconi_headers() getmsg = http.get(url, header) if getmsg.status_code == 200: return get_next_msgset(getmsg.text) elif getmsg.status_code == 204: test_result_flag = True return test_result_flag else: test_result_flag = False print('Failed to GET {}'.format(url)) print(getmsg.text) assert test_result_flag, 'HTTP code {}'.format(getmsg.status_code)
def get_claimed_msgs(*claim_response): """Does get on all messages returned in the claim. :param *claim_response: [header, body] returned for post claim request. """ test_result_flag = True urllist = create_urllist_fromhref(*claim_response) header = functionlib.create_marconi_headers() for url in urllist: get_response = http.get(url, header) if get_response.status_code != 200: print url print header print 'Get Response Code: {}'.format(get_response.status_code) test_result_flag = False if not test_result_flag: assert test_result_flag, 'Get Claimed message Failed'
def delete_claimed_msgs(*claim_response): """Deletes claimed messages. Verifies that the deletes were successful with a GET on the deleted msg. :param *claim_response: [header, body] returned for post claim request. """ test_result_flag = False urllist = create_urllist_fromhref(*claim_response) header = functionlib.create_marconi_headers() for url in urllist: delete_response = http.delete(url, header) if delete_response.status_code == 204: test_result_flag = functionlib.verify_delete(url, header) else: print 'DELETE message with claim ID: {}'.format(url) print delete_response.status_code print delete_response.headers print delete_response.text print 'Delete Claimed Message Failed' return test_result_flag
def query_claim(headers, *body): """Verifies the response of post claim. Does a Query Claim using the href in post claim. Compares the messages returned in Query claim with the messages returned on Post Claim. :param headers: headers returned in the post claim response. :param *body: message list returned in the post claim response. """ test_result_flag = False msg_list = body[0] msg_list = json.loads(msg_list) location = headers['Location'] url = functionlib.create_url_from_appender(location) header = functionlib.create_marconi_headers() get_msg = http.get(url, header) if get_msg.status_code == 200: query_body = json.loads(get_msg.text) query_msgs = query_body['messages'] test_result_flag = verify_query_msgs(query_msgs, msg_list) if not test_result_flag: print 'URL' print url print 'HEADER' print header print 'Messages returned by Query Claim' print query_msgs print '# of Messages returned by Query Claim', len(query_msgs) print 'Messages returned by Claim Messages' print msg_list print '# of Messages returned by Claim messages', len(msg_list) print 'Query Claim Failed' return test_result_flag
def setUp(self): super(TestQueue, self).setUp() self.cfg = config.Config() self.header = functionlib.create_marconi_headers()