def get_case_data(self,
                      file_name,
                      sheet_index=0,
                      row_id=0,
                      module_proto='order',
                      module_host='order',
                      dataPool=DataPool,
                      data=None,
                      **kwargs):
        """
        1、获取对应id的行的内容
        5、获取预期结果
        8、获取response
        :param file_name: 测试数据的文件名
        :param sheet_index: sheet表的索引
        :param id: caseId
        :return:exp_resp_dic,act_resp_dic
        """
        excel_handle = excel_module.Read_Excel(file_name)
        sheet = excel_handle.get_sheet_by_index(sheet_index)
        case_data_list = excel_handle.get_row_values(sheet, row_id)

        self.protoFileName = case_data_list[1]
        self.serviceName = case_data_list[2]
        self.methodName = case_data_list[3]
        self.requestClass = case_data_list[4]

        if case_data_list[5] is not None:
            self.data_res = case_data_list[5]
        if case_data_list[6] is not None:
            self.exp_resp = case_data_list[6]

        matches = re.findall('\$\{(.*?)\}', self.data_res)
        mset = set(matches)
        for item in mset:
            itemVal = str(dataPool.get(item)).encode('UTF-8')
            self.data_res = self.data_res.replace("${%s}" % item, itemVal)
            if itemVal == '':
                print('变量{}没有设置值'.format(item))

        self.data = json.loads(self.data_res, encoding="utf-8")
        logging.info(self.data_res)
        if kwargs is not None:
            for i in kwargs:
                for j in self.data:
                    if i == j:
                        self.data[j] = kwargs[i]
        if data is not None:
            self.data = data

        self.data = self.__rewriteData(self.data)

        exp_resp = self.get_case_data_exp()
        act_resp = self.get_case_data_act(module_proto, module_host)

        # print ("exp_resp\n", json.dumps(exp_resp))
        # print("act_resp\n", act_resp)
        return exp_resp, act_resp
Exemplo n.º 2
0
    def get_case_data_crm2(self,
                           file_name,
                           sheet_index=0,
                           row_id=0,
                           data=None,
                           **kwargs):
        # type: (object, object, object, object, object) -> object
        """
        1、获取对应id的行的内容
        2、获取url
        3、获取请求方式
        4、获取请求参数,并进行转码
        5、获取预期结果
        8、获取string类型response
        :param file_name: 测试数据的文件名
        :param sheet_index: sheet表的索引
        :param id: caseId
        :return:exp_resp_dic,act_resp_dic
        """
        excel_handle = excel_module.Read_Excel(file_name)
        sheet = excel_handle.get_sheet_by_index(sheet_index)
        case_data_list = excel_handle.get_row_values(sheet, row_id)
        path = case_data_list[1]
        self.url = self.get_url(path)
        # self.url = env_module.Env_Module().get_env_url(sheet_index) + path
        self.method = case_data_list[2]
        self.data_res = case_data_list[3]
        self.exp_resp = case_data_list[4]
        self.contype = json.loads(case_data_list[5])
        self.data = json.loads(self.data_res, encoding="utf-8")
        logging.info(self.data_res)
        if kwargs is not None:
            for i in kwargs:
                for j in self.data:
                    if i == j:
                        self.data[j] = kwargs[i]
        if data is not None:
            self.data = data
        exp_resp = self.get_case_data_exp()
        access_token = ''
        for i in kwargs:
            if i == 'coo':
                access_token = kwargs[i]

        if (access_token.strip() == ''):
            act_resp = self.get_case_data_act_crm()
        else:
            act_resp = self.get_case_data_act_crm(access_token=access_token)
        print "\n" + "Url:"
        print self.url.encode('utf-8')
        print "\n" + "Input"
        print self.data_res.encode('utf-8')
        print("\n" + "exp_resp:" + "\n" + exp_resp + "\n\n" + "act_resp:" +
              "\n" + act_resp[0] + "\n")
        return exp_resp, act_resp
Exemplo n.º 3
0
 def get_case_data(self, method_name, row_id=0):
     file_name = os.path.abspath('../data/bc_gui.xlsx')
     # print(os.path.abspath('../data'))
     excel_handle = excel_module.Read_Excel(file_name)
     sheet_index = excel_handle.get_sheet_by_index(0)
     if method_name == "id":
         return excel_handle.get_cell_value(sheet_index, row_id, 1)
     elif method_name == "name":
         return excel_handle.get_cell_value(sheet_index, row_id, 2)
     elif method_name == "xpath":
         return excel_handle.get_cell_value(sheet_index, row_id, 3)
Exemplo n.º 4
0
 def get_case_input_url(self, file_name, sheet_index=0, row_id=0):
     """
     真实数据获取
     1、获取实际结果
     2、获取真实结果
     :return:exp_resp_dic,act_resp_dic
     """
     excel_handle = excel_module.Read_Excel(file_name)
     sheet = excel_handle.get_sheet_by_index(sheet_index)
     case_data_list = excel_handle.get_row_values(sheet, row_id)
     self.data = case_data_list[1]
     return self.data
Exemplo n.º 5
0
 def get_case_data(self,
                   file_name,
                   sheet_index=0,
                   row_id=0,
                   data=None,
                   **kwargs):
     """
     1、获取对应id的行的内容
     2、获取url
     3、获取请求方式
     4、获取请求参数,并进行转码
     5、获取预期结果
     8、获取string类型response
     :param file_name: 测试数据的文件名
     :param sheet_index: sheet表的索引
     :param id: caseId
     :return:exp_resp_dic,act_resp_dic
     """
     excel_handle = excel_module.Read_Excel(file_name)
     sheet = excel_handle.get_sheet_by_index(sheet_index)
     case_data_list = excel_handle.get_row_values(sheet, row_id)
     path = case_data_list[1]
     # self.url = env_module.Env_Module().get_env_url(sheet_index) + path
     self.get_url(path)
     self.method = case_data_list[2]
     self.data_res = case_data_list[3]
     self.exp_resp = case_data_list[4]
     self.data = json.loads(self.data_res, encoding="utf-8")
     logging.info(self.data_res)
     if kwargs is not None:
         for i in kwargs:
             for j in self.data:
                 if i == j:
                     self.data[j] = kwargs[i]
     if data is not None:
         self.data = data
     exp_resp = self.get_case_data_exp()
     act_resp = self.get_case_data_act()
     case_url = self.url
     case_input = case_data_list[3]
     print "\n" + "Url:"
     print case_url.encode('utf-8')
     print "\n" + "Input"
     print case_input.encode('utf-8')
     print("\n" + "exp_resp:" + "\n" + exp_resp + "\n\n" + "act_resp:" +
           "\n" + act_resp + "\n")
     return exp_resp, act_resp
Exemplo n.º 6
0
 def setUp(self):
     self.utils = excel_module.Read_Excel('../../data/test_case_saas.xlsx')
     self.sheet = self.utils.get_sheet_by_index(0)
Exemplo n.º 7
0
 def __init__(self, excelPath):
     self.excel_handle = excel_module.Read_Excel(excelPath)