def test_005_message_get_echo_false(self): """Get Messages with echo=false.""" url = self.cfg.base_url + \ '/queues/messagetestqueue/messages?echo=false' result = http.get(url, self.header) self.assertEqual(result.status_code, 204)
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)
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 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)
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)
def test_025_check_queue_exists(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)
def test_012_queue_insert_nonASCII_metadata(self): """Insert Queue with non ASCII name.""" url = self.cfg.base_url + '/queues/nonASCIImetadata' doc = '{"汉字": "non ASCII metadata"}' result = http.put(url, self.header, doc) self.assertEqual(result.status_code, 400) result = http.get(url, self.header) self.assertEqual(result.status_code, 404)
def test_011_queue_insert_nonASCII_name(self): """Insert Queue with non ASCII name.""" url = self.cfg.base_url + '/queues/汉字/漢字' doc = '{"queue": "non ASCII name"}' result = http.put(url, self.header, doc) self.assertEqual(result.status_code, 400) result = http.get(url, self.header) self.assertEqual(result.status_code, 404)
def test_020_queue_stats(self): """Insert queue with name > 64 bytes.""" url = self.cfg.base_url + '/queues/qtestqueue/stats' result = http.get(url, self.header) self.assertEqual(result.status_code, 200) test_result_flag = queuefnlib.verify_queue_stats(result.headers, result.text) self.assertEqual(test_result_flag, True)
def test_022_queue_list_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) test_result_flag = queuefnlib.verify_list_queues(result.headers, result.text) self.assertEqual(test_result_flag, True)
def test_008_queue_insert_toplevel_underscore(self): """Insert Queue with underscore in toplevel field.""" url = self.cfg.base_url + '/queues/toplevel' doc = '{"_queue": "Top Level field with _"}' result = http.put(url, self.header, doc) self.assertEqual(result.status_code, 400) result = http.get(url, self.header) self.assertEqual(result.status_code, 404)
def test_024_check_queue_exists(self): """Checks if queue exists.""" url = self.cfg.base_url + '/queues/qtestqueue' 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)
def test_004_queue_update_empty_json(self): """Update Queue with empty json.""" url = self.cfg.base_url + '/queues/qtestqueue' doc = '{}' result = http.put(url, self.header, doc) self.assertEqual(result.status_code, 204) result = http.get(url, self.header) self.assertEqual(result.status_code, 200) self.assertEqual(result.json(), json.loads(doc))
def test_017_queue_insert_metadata_size65536(self): """Updates Queue with metadata_size = 65536.""" url = self.cfg.base_url + '/queues/qtestqueue/metadata' doc = functionlib.get_custom_body({"metadatasize": 65536}) result = http.put(url, self.header, doc) self.assertEqual(result.status_code, 204) result = http.get(url, self.header) self.assertEqual(result.status_code, 200) self.assertEqual(result.json(), json.loads(doc))
def test_009_queue_insert_header_plaintext(self): """Insert Queue with 'Accept': 'plain/text'.""" url = self.cfg.base_url + '/queues/plaintextheader' header = functionlib.plain_text_in_header() doc = '{"queue": "text/plain in header"}' result = http.put(url, header, doc) self.assertEqual(result.status_code, 406) result = http.get(url, self.header) self.assertEqual(result.status_code, 404)
def test_005_queue_insert_invalid_authtoken(self): """Insert Queue with invalid authtoken.""" url = self.cfg.base_url + '/queues/invalidauthtoken' header = functionlib.invalid_auth_token_header() doc = '{"queue": "invalid auth token"}' result = http.put(url, header, doc) self.assertEqual(result.status_code, 401) result = http.get(url, self.header) self.assertEqual(result.status_code, 404)
def test_003_queue_update_empty_metadata(self): """Update Queue with empty metadata.""" url = self.cfg.base_url + '/queues/qtestqueue' doc_original = '{"queue": "Apple"}' doc = '' result = http.put(url, self.header, doc) self.assertEqual(result.status_code, 400) result = http.get(url, self.header) self.assertEqual(result.status_code, 200) self.assertEqual(result.json(), json.loads(doc_original))
def test_999_delete_queue(self): """Delete Queue. Deletes Queue & performs GET to confirm 404. """ url = self.cfg.base_url + '/queues/qtestqueue' result = http.delete(url, self.header) self.assertEqual(result.status_code, 204) result = http.get(url, self.header) self.assertEqual(result.status_code, 404)
def test_003_message_get_no_params(self): """Get Messages with no params.""" default_msg_count = 10 url = self.cfg.base_url + '/queues/messagetestqueue/messages' result = http.get(url, self.header) self.assertEqual(result.status_code, 200) test_result_flag = msgfnlib.verify_get_msgs(default_msg_count, result.headers, result.text) self.assertEqual(test_result_flag, True)
def test_010_queue_insert_header_asterisk(self): """Insert Queue with 'Accept': '*/*'.""" url = self.cfg.base_url + '/queues/asteriskinheader' header = functionlib.asterisk_in_header() doc = '{"queue": "*/* in header"}' result = http.put(url, header, doc) self.assertEqual(result.status_code, 201) result = http.get(url, self.header) self.assertEqual(result.status_code, 200) http.delete(url, self.header)
def test_006_queue_update_invalid_authtoken(self): """Update Queue with invalid authtoken.""" url = self.cfg.base_url + '/queues/qtestqueue' header = functionlib.invalid_auth_token_header() doc = '{"queue": "invalid auth token"}' doc_original = '{}' result = http.put(url, header, doc) self.assertEqual(result.status_code, 401) result = http.get(url, self.header) self.assertEqual(result.status_code, 200) self.assertEqual(result.json(), json.loads(doc_original))
def test_002_queue_insert_case_insensitive(self): """Insert Queue with same name, different case.""" url = self.cfg.base_url + '/queues/QteStquEue' doc = '{"queue": "Orange"}' result = http.put(url, self.header, doc) self.assertEqual(result.status_code, 201) result = http.get(url, self.header) self.assertEqual(result.status_code, 200) self.assertEqual(result.json(), json.loads(doc)) http.delete(url, self.header)
def test_007_queue_insert_missing_header(self): """Insert Queue with missing header field. Request has no USER_AGENT & X-Project-Id headers. """ url = self.cfg.base_url + '/queues/missingheader' header = functionlib.missing_header_fields() doc = '{"queue": "USER_AGENT header is missing"}' result = http.put(url, header, doc) self.assertEqual(result.status_code, 400) result = http.get(url, self.header) self.assertEqual(result.status_code, 404)
def test_001_queue_insert(self): """Insert Queue. Creates Queue, does a get & verifies data. """ url = self.cfg.base_url + '/queues/qtestqueue' doc = '{"queue": "Apple"}' result = http.put(url, self.header, doc) self.assertEqual(result.status_code, 201) result = http.get(url, self.header) self.assertEqual(result.status_code, 200) self.assertEqual(result.json(), json.loads(doc))
def test_012_insert_queue_with_metadata(self): """Insert queue with a non-empty request body.""" url = self.cfg.base_url + '/queues/hasmetadata' doc = '{"queue": "Has Metadata"}' result = http.put(url, self.header, doc) self.assertEqual(result.status_code, 201) url = self.cfg.base_url + '/queues/hasmetadata/metadata' result = http.get(url, self.header) self.assertEqual(result.status_code, 200) self.assertEqual(result.json(), {}) url = self.cfg.base_url + '/queues/hasmetadata' http.delete(url, self.header)
def test_001_insert_queue(self): """Create Queue.""" url = self.cfg.base_url + '/queues/qtestqueue' result = http.put(url, self.header) self.assertEqual(result.status_code, 201) response_headers = set(result.headers.keys()) self.assertIsSubset(self.headers_response_empty, response_headers) url = self.cfg.base_url + '/queues/qtestqueue/metadata' result = http.get(url, self.header) self.assertEqual(result.status_code, 200) self.assertEqual(result.json(), {}) http.delete(url, self.header)
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)
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)
def test_014_queue_metadata_toplevel_underscore(self): """Insert Queue with underscore in toplevel field.""" url = self.cfg.base_url + '/queues/toplevel' result = http.put(url, self.header) url = self.cfg.base_url + '/queues/toplevel/metadata' doc = '{"_queue": "Top Level field with _"}' result = http.put(url, self.header, doc) self.assertEqual(result.status_code, 204) result = http.get(url, self.header) self.assertEqual(result.status_code, 200) self.assertEqual(result.json(), json.loads(doc)) url = self.cfg.base_url + '/queues/toplevel' http.delete(url, self.header)
def verify_delete(url, header): """Verifies the DELETE was successful, with a GET on the deleted item.""" test_result_flag = False getmsg = http.get(url, header) if getmsg.status_code == 404: test_result_flag = True else: print('GET after DELETE failed') print('URL') print url print('headers') print header print('Response Body') print getmsg.text print 'GET Code {}'.format(getmsg.status_code) return test_result_flag