Beispiel #1
0
def check_test_result(test_name, test_index, response, test_data):
	global test_passed, test_failed
	author = get_author_name(test_index,test_data)
	if response is None:
		print blue(test_name+" ("+str(test_index)+")") + fail(": Test failed ") + ("" if len(author) == 0 else blue(" contact test author: "+author+""))
		print "response is None"
		test_failed += 1
		return

	if response.status_code != 200:
		print blue(test_name+" ("+str(test_index)+")") + fail(": Test failed ") + ("" if len(author) == 0 else blue(" contact test author: "+author+""))
		print "HTTP status code = "+ str(response.status_code)
		test_failed += 1
		return

	message_filler = get_message_filler(test_index,test_data)
	ignore_whitespace = get_ignore_whitespace(test_index,test_data)
	expected_response = replace_with_global_data(get_expected_response(test_index,test_data))

	if((not ignore_whitespace and response_match(response.text.strip(),expected_response, message_filler)) or ( ignore_whitespace and response_match(clean_whitespace(response.text) ,clean_whitespace(expected_response),message_filler))):
		print blue(test_name+" ("+str(test_index)+")") + green(": Test passed")
		test_passed += 1
	else:
		print blue(test_name+" ("+str(test_index)+")") + fail(": Test failed ") + ("" if len(author) == 0 else blue(" contact test author: "+author+""))
		print warn("EXPECTED")+": \n"+ expected_response + "\n\n"+warn("ACTUAL")+":\n" + response.text
		test_failed += 1
Beispiel #2
0
	if(not dir.endswith('/')):
		dir = dir+'/'
	test_file_names = filter ( lambda x : x.endswith(TEST_FILE_EXTENSION), os.listdir(dir))
	test_file_names = map( lambda x : dir+x , test_file_names)

#Start executing test/s in each file
test_file_names.sort()

print header(u'Running Community API Tester!')

for test_file_name in test_file_names:
	test_file = open(test_file_name,'r')
	test_data = json.load(test_file)

	if(not is_list_of_dicts(test_data)):
		print blue(test_file_name) + warn(": Invalid file format")
		test_not_executed += 1
		continue

	if(not test_data[0].has_key(GLOBAL_STORE)):
		test_data[0][GLOBAL_STORE] = []
	test_count += (len(test_data) - 1); #first element is list is configuration and not a test

	for test_index in range(1,len(test_data)):
		if(not min_required_data_present_in(test_index,test_data)):
			print blue(test_name) + warn(": Insuffecient data to run test")
			test_not_executed += 1
			continue

		test_name = replace_with_global_data(get_test_name(test_index,test_data,test_file_name))