コード例 #1
0
ファイル: testLogic.py プロジェクト: Legolas-Li/AutoAPI
def one_case_run(group, apiname, caseid):
	xml = resolveXML.xmlObject()
	apifile = apiname + ".api.xml"
	casefile = apiname + ".case.xml"
	api = xml.get_xml_data(apifile, group)
	allcase = xml.get_xml_data(casefile, group)

	case = {}
	for i in range(len(allcase)):
		for key in allcase[i]:
			if caseid == allcase[i]['cid']:
				case = allcase[i]
			else:
				continue
	if api['protocol'] == 'http':
		conn = httplib.HTTPConnection(api['host'])
	else:
		conn = httplib.HTTPSConnection(api['host'])
	params = urllib.urlencode(case['params'])
	headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}
	apiUrl = api['url']
	conn.request(api['method'], apiUrl, params, headers)
	backinfo = conn.getresponse()
	res = backinfo.read()
	return dealString.re_str(res)
コード例 #2
0
ファイル: testLogic.py プロジェクト: huangzhiyong/AutoAPI
def one_case_run(apiname, caseid):
	xml = xmlObject()

	apifile = apiname + ".api.xml"
	casefile = apiname + ".case.xml"

	api = xml.get_xml_data(apifile, group)
	allcase = xml.get_xml_data(casefile, group)

	case = {}
	for i in range(len(allcase)):
		for key in allcase[i]:
			if caseid == allcase[i]['cid']:
				case = allcase[i]
			else:
				continue
	if api['protocol'] == 'http':
		conn = httplib.HTTPConnection(api['host'])
	else:
		conn = httplib.HTTPSConnection(api['host'])
	apiUrl = api['url'] + "?" + case['all_param']
	conn.request(api['method'], apiUrl)
	backinfo = conn.getresponse()
	res = backinfo.read()
	return dealString.re_str(res)
コード例 #3
0
ファイル: multiThread.py プロジェクト: huangzhiyong/AutoAPI
    def run(self):
        for n in range(len(self.cases)):
            print "\t执行" + self.api["apiname"] + "接口测试用例" + self.cases[n]["cid"]

            # http connection
            # 后期可能会考虑用urllib2替换httplib
            if self.api["protocol"] == "http":
                conn = httplib.HTTPConnection(self.api["host"])
            else:
                conn = httplib.HTTPSConnection(self.api["host"])
            apiUrl = self.api["url"] + "?" + self.cases[n]["all_param"]
            conn.request(self.api["method"], apiUrl)
            backinfo = conn.getresponse()
            ret_res = backinfo.read()

            # 接口返回的JSON数据中,存在python无法识别数据
            # 如: php boolean  false true
            # 如:返回带引号的URL
            # 需要将false true(php常量)转化成python False True
            try:
                now_res = eval(dealString.re_str(ret_res))
            except Exception, e:
                print "tran the RETURN (JSON format) ERROR ."
                print self.api["apiname"] + "接口测试用例" + str(self.cases[n]["cid"]) + "执行失败"
                my_log.logger.error(e)
                exit()

            expect = self.cases[n]["wish"]

            # 检查预期结果格式,是否存在接口依赖
            # 例如接口A的用例1的预期结果,是调用接口B的用例3得到
            if str(expect)[:1] == "a":
                depend_api = eval(expect[3:])
                depend_key = depend_api.keys()
                depend_value = depend_api.values()
                depend_expect = testLogic.one_case_run(depend_key[0], depend_value[0])
            else:
                depend_expect = self.cases[n]["wish"]

                # print "\t预期结果: " + str(depend_expect)
                # print "\t实际结果: " + str(now_res)

                # 默认校验全部,暂不考虑局部校验
                # if self.cases[n]['check'] == 'no':
                #  	if now_res == depend_expect:
                # 		print " " + self.cases[n]['des'] + " test success."
                # 	else:
                # 		print " " + self.cases[n]['des'] + " test failed"
                # else:
                # 	check_param = format_check(cases[n]['check'])
                # 	print " 校验参数:" + str(check_param)
            compare_res = dealString.compare_value(depend_expect, now_res)
            if compare_res:
                print "\t" + self.api["apiname"] + "接口用例" + self.cases[n]["des"] + "测试通过"
            else:
                print "\t" + self.api["apiname"] + "接口用例" + self.cases[n]["des"] + "测试不通过"
コード例 #4
0
ファイル: multiThread.py プロジェクト: Legolas-Li/AutoAPI
	def run(self):
		for n in range(len(self.cases)):
			global RUN_SUCCESS
			global RUN_FAILED
			#print "\t执行" + self.api['apiname'] + "接口测试用例" + self.cases[n]['cid']

			# http connection
			# 后期可能会考虑用urllib2替换httplib
			if self.api['protocol'] == 'http':
				conn = httplib.HTTPConnection(self.api['host'])
			else:
				conn = httplib.HTTPSConnection(self.api['host'])
			params = urllib.urlencode(self.cases[n]['params'])
			apiUrl = self.api['url']
			headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}
			apiUrl = self.api['url'] + "?" + self.cases[n]['all_param']
			conn.request(self.api['method'], apiUrl, params, headers)
			backinfo = conn.getresponse()
			ret_res = backinfo.read()

			# 接口返回的JSON数据中,存在python无法识别数据
			# 如: php boolean - false true
			# 如:返回带引号的URL
			# 需要将false true(php常量)转化成python False True
			try:
				now_res = eval(dealString.re_str(ret_res))
			except Exception, e:
				print "tran the RETURN (JSON format) ERROR ."
				print self.api['apiname'] + "接口测试用例" + str(self.cases[n]['cid']) + "执行失败"
				my_log.logger.error(e)
				sys.exit()

			expect = self.cases[n]['wish']

			# 检查预期结果格式,是否存在接口依赖
			# 例如接口A的用例1的预期结果,是调用接口B的用例3得到
			if str(expect)[:1] == 'a':
				depend_api = eval(expect[3:])
				depend_key = depend_api.keys()
				depend_value = depend_api.values()
				depend_expect = testLogic.one_case_run(depend_key[0], depend_value[0])
			elif str(expect)[:1] == 'p':
				depend_api = eval(expect[3:])
				depend_expect = depend_api
			else:
				depend_expect = self.cases[n]['wish']

			#print "\t预期结果: " + str(depend_expect)
			#print "\t实际结果: " + str(now_res)

			# 默认校验全部,暂不考虑局部校验
			# if self.cases[n]['check'] == 'no':
			#  	if now_res == depend_expect:
			#		print " " + self.cases[n]['des'] + " test success."
			#	else:
			#		print " " + self.cases[n]['des'] + " test failed"
			# else:
			#	check_param = format_check(cases[n]['check'])
			#	print " 校验参数:" + str(check_param)
			compare_res = dealString.compare_value(depend_expect, now_res)
			if compare_res:
				RUN_SUCCESS += 1
				print "\t" + self.api['apiname'] + "接口用例" + self.cases[n]['des'] + "测试通过"
			else:
				RUN_FAILED += 1
				print "\t" + self.api['apiname'] + "接口用例" + self.cases[n]['des'] + "测试不通过"
コード例 #5
0
                else:
                    change_value = after_apilist[0].split(",")
                    cha_key = change_value[len(change_value) - 1]
                    if cha_key[9:] in iParam.keys():
                        cha_key = iParam[cha_key]
                        after_api_l = dealString.com_string(change_value)
                    else:
                        after_api_l = ""

                case_des_v = self.get_nodevalue(case_des[0]).encode('utf-8')
                case_wish_v = self.get_nodevalue(case_wish[0])
                case_run_v = self.get_nodevalue(case_run[0])
                case_cid_v = self.get_nodevalue(case_cid[0])

                if case_wish_v[:1] == '{':
                    b = dealString.re_str(case_wish_v)
                    a = eval(b)
                elif case_wish_v[:1] == 'p':
                    keylist = eval(case_wish_v[3:])
                    for i in keylist:
                        if keylist[i] in iParam.keys():
                            keywd = keylist[i]
                            keylist[i] = iParam[keywd]
                        else:
                            a = case_wish_v
                    a = "par" + str(keylist)
                else:
                    a = case_wish_v
                case_check_v = self.get_attrvalue(case_wish[0], 'check')
                p_nodes = self.get_xmlnode(c, 'p')
                p_list = {}
コード例 #6
0
ファイル: resolveXML.py プロジェクト: Legolas-Li/AutoAPI
				else:
					change_value = after_apilist[0].split(",")
					cha_key = change_value[len(change_value)-1]
					if cha_key[9:] in iParam.keys():
						cha_key = iParam[cha_key]
						after_api_l = dealString.com_string(change_value)
					else:
						after_api_l = ""

				case_des_v = self.get_nodevalue(case_des[0]).encode('utf-8')
				case_wish_v = self.get_nodevalue(case_wish[0])
				case_run_v = self.get_nodevalue(case_run[0])
				case_cid_v = self.get_nodevalue(case_cid[0])

				if case_wish_v[:1] == '{':
					b = dealString.re_str(case_wish_v)
					a = eval(b)
				elif case_wish_v[:1] == 'p':
					keylist = eval(case_wish_v[3:])
					for i in keylist:
						if keylist[i] in iParam.keys():
							keywd = keylist[i]
							keylist[i] = iParam[keywd]
						else:
							a = case_wish_v
					a = "par" + str(keylist)
				else:
					a = case_wish_v
				case_check_v = self.get_attrvalue(case_wish[0], 'check')
				p_nodes = self.get_xmlnode(c, 'p')
				p_list = {}
コード例 #7
0
ファイル: multiThread.py プロジェクト: zhaoxiaojun/AutoAPI
    def run(self):
        for n in range(len(self.cases)):
            global RUN_SUCCESS
            global RUN_FAILED
            #print "\t执行" + self.api['apiname'] + "接口测试用例" + self.cases[n]['cid']

            # http connection
            # 后期可能会考虑用urllib2替换httplib
            if self.api['protocol'] == 'http':
                conn = httplib.HTTPConnection(self.api['host'])
            else:
                conn = httplib.HTTPSConnection(self.api['host'])
            params = urllib.urlencode(self.cases[n]['params'])
            apiUrl = self.api['url']
            headers = {
                "Content-type":
                "application/x-www-form-urlencoded",
                "Accept":
                "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
            }
            apiUrl = self.api['url'] + "?" + self.cases[n]['all_param']
            conn.request(self.api['method'], apiUrl, params, headers)
            backinfo = conn.getresponse()
            ret_res = backinfo.read()

            # 接口返回的JSON数据中,存在python无法识别数据
            # 如: php boolean - false true
            # 如:返回带引号的URL
            # 需要将false true(php常量)转化成python False True
            try:
                now_res = eval(dealString.re_str(ret_res))
            except Exception, e:
                print "tran the RETURN (JSON format) ERROR ."
                print self.api['apiname'] + "接口测试用例" + str(
                    self.cases[n]['cid']) + "执行失败"
                my_log.logger.error(e)
                sys.exit()

            expect = self.cases[n]['wish']

            # 检查预期结果格式,是否存在接口依赖
            # 例如接口A的用例1的预期结果,是调用接口B的用例3得到
            if str(expect)[:1] == 'a':
                depend_api = eval(expect[3:])
                depend_key = depend_api.keys()
                depend_value = depend_api.values()
                depend_expect = testLogic.one_case_run(depend_key[0],
                                                       depend_value[0])
            elif str(expect)[:1] == 'p':
                depend_api = eval(expect[3:])
                depend_expect = depend_api
            else:
                depend_expect = self.cases[n]['wish']

            #print "\t预期结果: " + str(depend_expect)
            #print "\t实际结果: " + str(now_res)

            # 默认校验全部,暂不考虑局部校验
            # if self.cases[n]['check'] == 'no':
            #  	if now_res == depend_expect:
            #		print " " + self.cases[n]['des'] + " test success."
            #	else:
            #		print " " + self.cases[n]['des'] + " test failed"
            # else:
            #	check_param = format_check(cases[n]['check'])
            #	print " 校验参数:" + str(check_param)
            compare_res = dealString.compare_value(depend_expect, now_res)
            if compare_res:
                RUN_SUCCESS += 1
                print "\t" + self.api['apiname'] + "接口用例" + self.cases[n][
                    'des'] + "测试通过"
            else:
                RUN_FAILED += 1
                print "\t" + self.api['apiname'] + "接口用例" + self.cases[n][
                    'des'] + "测试不通过"
コード例 #8
0
ファイル: testLogic.py プロジェクト: zhaoxiaojun/AutoAPI
                continue
    if api['protocol'] == 'http':
        conn = httplib.HTTPConnection(api['host'])
    else:
        conn = httplib.HTTPSConnection(api['host'])
    params = urllib.urlencode(case['params'])
    headers = {
        "Content-type": "application/x-www-form-urlencoded",
        "Accept":
        "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
    }
    apiUrl = api['url']
    conn.request(api['method'], apiUrl, params, headers)
    backinfo = conn.getresponse()
    res = backinfo.read()
    return dealString.re_str(res)


# pick up all the running case.
def select_run_case(case):
    ''' pick up the running case while run = 1 '''
    run_case = []
    for n in range(len(case)):
        if case[n]['run'] == '1':
            run_case.append(case[n])
        else:
            continue
    return run_case


# testing report