예제 #1
0
    def __init__(self):
        super(PostData, self).__init__()
        # 创建session
        self.itas_session = requests.Session()
        try:
            if self.login_mode == 'login':
                # 连接数据查询登录用户的密码&组装首次登录post data
                connect_oracle = Oracle(*self.database)
                connect_oracle.first_login_function = self.userneme
                password = connect_oracle.first_login_function
                first_login_data = {
                    'username': self.userneme,
                    'password': password,
                    'language': ''
                }

                # 创建session
                aa = self.itas_session.post(url=(self.url + "/ITAS/login"),
                                            data=first_login_data)
                print(aa.text)
                # 可以对此次传输的cookie进行存放,此方法与cookie方式类似
                self.JSESSIONID = self.itas_session.cookies.get('JSESSIONID')

            # cookie方式,直接将cookie添加到headers
            elif self.login_mode == 'cookie':
                logger.debug('cookie 登录方式')
            else:
                raise ValueError('login Mode方式设置错误')
        except Exception as err:
            logger.error('初始化出现错误:%s' % err)
        else:
            logger.debug('类:PostData,完成初始化')
예제 #2
0
    def __new__(cls, config_file_address=systemConfig):
        try:
            if not hasattr(cls, 'config'):
                # 创建属性&在属性下命名数值
                cls.config = super(Config, cls).__new__(cls)
                open_config = configparser.ConfigParser()
                open_config.read(config_file_address)

                # 通过config获取数据
                cls.config.login_mode = open_config.get(
                    'loginMode', 'loginMode')
                cls.config.cookie = open_config.get('cookie', 'cookie')
                cls.config.environment = open_config.get(
                    'environment', 'environment')

                # 通过判断配置中的环境变量来读取使用环境
                cls.config.database = (open_config.get(cls.config.environment,
                                                       'database')).split(",")
                cls.config.url = open_config.get(cls.config.environment, 'URL')
                cls.config.userneme = open_config.get(cls.config.environment,
                                                      'userneme')
        except Exception as err:
            logger.error('出现错误%s' % err)
        else:
            logger.debug('类:Config,完成初始化')
        return cls.config
예제 #3
0
def replace_data(row_data):
    """
    :param row_data: 输入具体行数据
    :return: 对于2, 3, 4, 5, 8这几行数据进行eval操作,若为空返回相应数据类型
    """
    try:
        if isinstance(row_data, list):
            replace_list = [2, 3, 4, 5, 8]
            for i in replace_list:
                if row_data[i] != '':
                    row_data[i] = eval(row_data[i])
                elif row_data[i] == '' and (i == 2):
                    row_data[i] = list()
                elif row_data[i] == '' and (i == 5):
                    row_data[i] = tuple()
                elif row_data[i] == '' and (i == 3 or i == 4 or i == 8):
                    row_data[i] = dict()
                else:
                    raise ValueError('恢复数据类型存在错误')
        else:
            raise ValueError('row data存在错误')
    except Exception as err:
        logger.error('函数:replace data,存在错误:%s' % err)
    else:
        logger.debug('函数:replace data,完成操作')
    return row_data
예제 #4
0
 def get_sheets(self):
     # 对传入值self.openExcel进行判断
     if not isinstance(self.open_excel,
                       xlrd.book.Book) and self.open_excel is None:
         raise '%s:存在错误' % self.open_excel
     try:
         self.all_sheet = self.open_excel.sheet_names()
     except Exception as err:
         logger.error('函数getSheets,出现错误:%s' % err)
     else:
         logger.debug('class: ReadExcel;function:getSheets. .over')
     return self.all_sheet
예제 #5
0
 def __init__(self, file_name, till_name):
     ReadExcel.__init__(self, file_name=file_name)
     # super(WriteExcel ,self).__init__(fileName=filename)
     ReadExcel.get_sheet_name_number(self)
     ExcelStyle.__init__(self)
     try:
         self.copyExcel = xlutils.copy.copy(self.open_excel)
         sheet_number = self.D1[till_name]
         self.get_sheet = self.copyExcel.get_sheet(sheetnum=sheet_number)
     except Exception as err:
         logger.error('writeData Function 存在问题:%s' % err)
     logger.debug('类:WriteExcel,完成初始化')
예제 #6
0
 def __init__(self, http_response, *assert_data):
     logger.debug('class:AssertRegular,httpResponse:%s ,assertData:%s' % (http_response, assert_data))
     super(AssertRegular, self).__init__()
     try:
         if not isinstance(assert_data, tuple):
             raise ValueError('Assert Regular class ,assertData 存在问题')
         self.code = http_response.status_code
         self.text = http_response.text
         self.header = http_response.headers
         self.regularExp = assert_data
     except Exception as err:
         logger.error('__init__:%s' % err)
예제 #7
0
 def __init__(self, **list_first_data):
     logger.debug("类:Oracle,接收数据list first data:%s" % str(list_first_data))
     self.password = None
     if not isinstance(list_first_data, dict):
         raise ValueError('%s do not a dict.' % list_first_data)
     try:
         dns = cx_Oracle.makedsn(list_first_data['url'], list_first_data['port'], list_first_data['oracle_name'])
         self.oracle_connection = cx_Oracle.Connection(list_first_data['username'], list_first_data['password'], dns)
         self.oracle_cursor = cx_Oracle.Cursor(self.oracle_connection)
     except Exception as err:
         logger.error('Oracle():%s' % err)
     else:
         logger.debug('类:Oracle,完成初始化')
예제 #8
0
    def __init__(self, file_name):
        logger.debug('ReadExcel:(%s)' % file_name)
        self.file_name = file_name
        self.D1 = dict()
        self.all_sheet = None

        # 判定filename是否为空或无值
        try:
            if self.file_name is None:
                raise "fileName:%s 不能为空" % file_name
            self.open_excel = xlrd.open_workbook(filename=file_name,
                                                 formatting_info=True)
        except Exception as err:
            logger.error('ReadExcel初始化,出现错误:%s' % err)
예제 #9
0
 def __init__(self, file_name, result_address):
     ReadSheet.__init__(self, file_name)
     ExcelStyle.__init__(self)
     self.result_address = result_address
     self.resultName = 'result'
     self.currentTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
     try:
         self.excel_workbook = xlwt.Workbook()
         self.add_result_sheet = self.excel_workbook.add_sheet(
             sheetname=self.resultName, cell_overwrite_ok=True)
         # excelWorkbook.save(self.resultAddress)
     except Exception as err:
         logger.error(err)
     else:
         logger.debug('class:ExcelResultStatistics,初始化完毕')
예제 #10
0
 def get_sheet_name_number(self):
     # 对传入值self.openExcel进行判断
     # print(self.open_excel)
     if not isinstance(self.open_excel,
                       xlrd.book.Book) and self.open_excel is None:
         raise '%s:存在错误' % self.open_excel
     try:
         all_sheet = self.open_excel.sheets()
         for i in all_sheet:
             self.D1[i.name] = i.number
     except Exception as err:
         logger.error('函数出现错误:getSheetNameNumber%s' % err)
     else:
         logger.debug('class: ReadExcel;funciton:getSheets. .over;D1=%s' %
                      self.D1)
     return self.D1
예제 #11
0
 def find_tem_function(self, *data, **post_data):
     logger.debug('findTemFunction函数,data:%s ,Post data:%s' % (str(data), str(post_data)))
     try:
         if data == ():
             post_data = post_data
             find_data_dict = data
         else:
             read_tem = open(self.file_address, 'r')
             # print(self.fileAddress)
             read_tem_data = eval(read_tem.read())
             find_data_dict = dict()
             for i in data:
                 post_data[i] = read_tem_data[i]
                 find_data_dict[i] = read_tem_data[i]
                 read_tem.close()
         return post_data, find_data_dict
     except Exception as err:
         logger.error('findTemFunction:', err)
예제 #12
0
 def statistics_function(self, col, start_row):
     self.result_excel_initialization()
     logger.debug('完成统计结果excel初始化')
     for x in range(0, len(self.all_sheet)):
         try:
             open_sheet = self.open_excel.sheet_by_name(self.all_sheet[x])
             pass_or_fail_list = open_sheet.col_values(colx=col,
                                                       start_rowx=start_row)
             pass_sum = pass_or_fail_list.count('Pass')
             fail_sum = pass_or_fail_list.count('Fail')
             pass_rate = str('%.1f' % ((pass_sum /
                                        (pass_sum + fail_sum)) * 100)) + '%'
             sheet_name_statistics_result = [
                 self.all_sheet[x], pass_sum, fail_sum, pass_sum + fail_sum,
                 pass_rate
             ]
             for y in range(0, 5):
                 self.add_result_sheet.write(
                     x + 2, y, sheet_name_statistics_result[y], self.style)
         except Exception as err:
             logger.error(err)
             continue
예제 #13
0
 def oracle_sql_execute_function(self, sql, response=3):
     """
     :param sql:
     :param response: 1为返回单行数据
                       2为返回所有数据
                       3为执行语句,无返回值
     :return:
     """
     oracle_sql_response = None
     if response not in [1, 2, 3]:
         raise ValueError('response 输入错误')
     self.oracle_cursor.execute(sql)
     if response == 1:
         oracle_sql_response = self.oracle_cursor.fetchone()
     elif response == 2:
         oracle_sql_response = self.oracle_cursor.fetchall()
     elif response == 3:
         self.oracle_connection.commit()
         oracle_sql_response = True
     else:
         logger.error('')
     return oracle_sql_response
예제 #14
0
    def post_data_function(self, http_mode, url_path, data, post_header):
        # 组装登录所用
        all_url = self.url + url_path
        update_headers = dict()
        post_data_variable = None
        try:
            if not isinstance(data, dict):
                post_data = eval(data)
            else:
                post_data = data
            # 按照不同的测试Mode进行数据发送
            if self.login_mode == 'cookie':
                update_headers = {'cookie': 'JSESSIONID=' + self.cookie}
                update_headers.update(post_header)
            elif self.login_mode == 'login':
                update_headers = {'cookie': 'JSESSIONID=' + self.JSESSIONID}
                update_headers.update(post_header)
            else:
                logger.error('函数:post_data_function  login mode:%s存在错误' %
                             self.login_mode)
            print(all_url, post_data, update_headers)
            # logger.debug(all_url, str(post_data), str(update_headers))

            if http_mode == 'Post':
                post_data_variable = self.itas_session.post(
                    url=all_url, data=post_data, headers=update_headers)
            elif http_mode == 'Get':
                post_data_variable = self.itas_session.get(
                    url=all_url, data=post_data, headers=update_headers)
            else:
                post_data_variable = None
                raise ValueError('http_mode')
            print(post_data_variable.text)
            logger.debug(post_data_variable.text)
        except Exception as err:
            logger.error(' 出现错误%s' % err)
        else:
            logger.debug('方法:postDataFunction,完成初始化。')
        return post_data_variable