Exemplo n.º 1
0
    def test_order_management_list(self):
        # hand_excel = ExcelUtil("\\Test.xlsx")
        hand_excel = ExcelUtil("\\订单-量管理.xlsx")
        rows = hand_excel.get_rows()
        for i in range(rows - 1):
            data = hand_excel.get_rows_value(
                i + 1)  # 如果是第二个sheet,则加参数 index=1;有几个依次类推
            if data[5] == "yes":
                with self.subTest(i=i):
                    method = data[7]
                    url = self.host + data[8]
                    date = json.loads(data[9])
                    headers = json.loads(data[10])
                    if data[6] == "token":
                        headers["Authorization"] = ""
                    expect_status = json.loads(data[13])

                    # 使用mock数据
                    # mock_method = mock.Mock(return_value=get_value(url, '../config/mock_date.json'))
                    # request.request_main = mock_method
                    # res = request.request_main(method=method, url=url, data=post_data)
                    # 正常请求
                    logger.info("开始请求!!!!!!!!")
                    response = RequestUtil.request_main(
                        method, url, date, headers)
                    logger.info("{0}-{1}-{2}-{3}状态码为:{4}".format(
                        data[0], data[1], data[3], data[2],
                        response.status_code))

                    result = response.json()
                    # logger.info(result)
                    for k in expect_status.keys():
                        # logger.info(str(expect_status[k]) + "," + str(json_search.search_key(result, k)))
                        self.assertIn(expect_status[k],
                                      json_search.search_key(result, k))
Exemplo n.º 2
0
class Data:
    def __init__(self, testcase_file, sheet_name):
        self.reader = ExcelUtil(testcase_file, sheet_name)

# 2、列是否运行内容,y

    def get_run_data(self):
        run_list = list()
        for line in self.reader.data():
            if str(line[ExcelConfig.DataConfig().is_run]).lower() == "y":
                # 3、保存要执行结果,放到新的列表
                run_list.append(line)
        return run_list

# 查出所有用例,并返回

    def get_case_list(self):
        run_list = list()
        for line in self.reader.data(need="all"):
            run_list.append(line)
        return run_list


# 根据用例id查出pre_exec的用例信息,并返回

    def get_case_pre(self, pre):
        run_list = self.get_case_list()
        for line in run_list:
            if pre == line["用例ID"]:
                return line
        return None
Exemplo n.º 3
0
 def tearDownClass(self):
     self.stopTime = datetime.datetime.now()
     duration = str(self.stopTime - self.startTime)
     startTime = str(self.startTime)[:19]
     duration = duration[:duration.find(".")]
     reportUtil = ReportUtil_sort()
     reportUtil.generateReport(startTime, duration, self.all_sort_results)
     excel = ExcelUtil()
     excel.export_price_sort_test_result_to_excel(
         'pricesort_test_result.xls', self.all_sort_results)
     logger.info("---end test suite(%s)---" % __name__)
Exemplo n.º 4
0
 def tearDownClass(self):
     if self.writeExcelFlag:
         self.stopTime = datetime.datetime.now()
         duration = str(self.stopTime - self.startTime)
         startTime = str(self.startTime)[:19]
         duration = duration[:duration.find(".")]
         reportUtil = ReportUtil()
         reportUtil.generateReport(startTime,duration,self.searchresults)
         
         excel = ExcelUtil()
         excel.exportToExcel(startTime.replace(" ", "_").replace(":", "-", 2),self.searchresults)
     
     logger.info("---end test suite(%s)---" % __name__)
    def getKeywordByExcel(self,excelPath):
        """通过excel表格方式输入搜索词"""
        excel = ExcelUtil()
        baseKey = excel.getColumnData(excelPath,"Sheet1",0)
        list1 = (excel.getColumnData(excelPath,"Sheet1",1))
        list1.insert(0,'')
        list2 = excel.getColumnData(excelPath, "Sheet1", 2)
        list2.insert(0, '')
        list3 = excel.getColumnData(excelPath, "Sheet1", 3)
        list3.insert(0, '')
        list4 = excel.getColumnData(excelPath, "Sheet1", 4)
        list4.insert(0, '')
        keywords = []
        for key in baseKey:
            for a in list1:
                Str = key
                Str += a
                for b in list2:
                    Strb = Str[:]
                    Strb += b
                    for c in list3:
                        Strc = Strb[:]
                        Strc += c
                        for d in list4:
                            Strd = Strc[:]
                            Strd += d
                            keywords.append(Strd)

        return keywords
Exemplo n.º 6
0
 def tearDownClass(self):
     excel = ExcelUtil()
     excel.export_commodity_type_judgment_results_to_excel('NumberOfEvaluation0.xls', self.all_results)
     logger.info("---end test suite(%s)---" % __name__)
Exemplo n.º 7
0
    def test_run(self, case):
        # excel中取得用例数据
        case_num = case[data_key.case_num]
        host = case[data_key.host]
        case_id = case[data_key.case_id]
        case_model = case[data_key.case_model]
        case_name = case[data_key.case_name]
        pre_exec = case[data_key.pre_exec]
        method = case[data_key.method]
        note = case[data_key.note]
        params_type = case[data_key.params_type]
        params = case[data_key.params]
        body = case[data_key.body]
        expect_result = case[data_key.expect_result]
        headers = case[data_key.headers]
        cookies = case[data_key.cookies]
        code = case[data_key.code]
        last_result = case[data_key.last_result]
        exclude_regex_paths = case[data_key.exclude_regex_paths]
        db_verify = case[data_key.db_verify]

        # 如果是预设的常用参数就替换下
        if headers in global_params.keys():
            headers = global_params[headers]
        if host in global_params.keys():
            host = global_params[host]
        url = host + case[data_key.url]

        # 如果有参数中有需要执行前置用例的,就执行前置用例并替换参数
        if pre_exec:
            pre_case = Data_init.get_case_pre(pre_exec)
            print("前置条件信息为:%s" % pre_case)
            pre_res = self.run_pre(pre_case)
            headers, cookies, params, body, url \
                = Base.get_pre_exec_correlation(headers, cookies, params, body, url, pre_res)

        headers = Base.json_parse(headers)
        cookies = Base.json_parse(cookies)
        params = Base.json_parse(params)
        body = Base.json_parse(body)

        # 上面把数据都准备完成了,真正发请求
        res = Base.run_api(url, method, params, body, headers, cookies)

        # allure报告信息
        allure.dynamic.feature(sheet_name_keys)
        allure.dynamic.story(case_model)
        allure.dynamic.title(case_id + case_name)
        desc = "<font color='red'>请求URL:</font>{0}<BR/>" \
               "<font color='red'>请求方法:</font>{1}<BR/>" \
               "<font color='red'>预期结果:</font>{2}<BR/>" \
               "<font color='red'>实际结果:</font>{3}".format(url, method, expect_result, res)
        allure.dynamic.description(desc)

        # log记录
        log.info("=====接口【%s】的用例【%s%s】已执行!=====" % (case_name, case_id, note))
        log.debug("\n测试用例预期:%s \n测试用例执行结果:%s" % (str(expect_result), str(res)))

        # 响应状态码及响应体字符串包含断言
        assert_util = AssertUtil()
        assert_util.assert_code(res["code"], code)
        assert_util.assert_in_body(str(res["body"]), str(expect_result))

        # 响应体的diff断言
        if exclude_regex_paths != "skip_diff":
            if last_result:
                expect_result_for_diff = json.loads(
                    json.dumps(eval(last_result)))
                if len(exclude_regex_paths) > 5:
                    exclude_regex_paths = eval(exclude_regex_paths)
                else:
                    exclude_regex_paths = None
                assert_util.assert_diff(
                    expect_result_for_diff,
                    res,
                    exclude_regex_paths=exclude_regex_paths)
            else:
                from utils.ExcelUtil import ExcelUtil
                sheet_by = getattr(Const.GetConst(), (case_num[0:1]).upper())
                excel_util = ExcelUtil(excel_file=case_file, sheet_by=sheet_by)
                case_row = excel_util.get_row_num_by_case_num(case_num)
                excel_util.write_back(case_row, 16, str(res))

        # 数据库断言
        if db_verify:
            assert_util.assert_db(db_verify)
Exemplo n.º 8
0
 def __init__(self, testcase_file, sheet_name):
     self.reader = ExcelUtil(testcase_file, sheet_name)