def __init__(self, cf=ReadConfig('/'.join([os.path.dirname(os.path.abspath(__file__)), 'config.ini']))): """ 1.获取数据库连接 2.初始化文件目录信息 """ # 密码解密 self.pc = Pycryptor() # 文件位置 self.file_dir = cf.get_value('dir_info', 'file_dir') # 日志位置 self.log_dir = cf.get_value('dir_info', 'log_dir') # mysql连接 self.mysqlClient = MySQLDb(host=cf.get_value('mysql_idd', 'host'), port=int(cf.get_value('mysql_idd', 'port')), user=cf.get_value('mysql_idd', 'user'), password=self.pc.decrypt(cf.get_value('mysql_idd', 'password')), dbname=cf.get_value('mysql_idd', 'dbname'), local_infile=1) # orcale连接 self.oracleClient = OracleDb(host=cf.get_value('oracle_iboss', 'host'), port=cf.get_value('oracle_iboss', 'port'), user=cf.get_value('oracle_iboss', 'user'), password=Pycryptor().decrypt(cf.get_value('oracle_iboss', 'password')), dbname=cf.get_value('oracle_iboss', 'dbname')) # hive连接 self.hdfs = cf.get_value('hive_info', 'hdfs') self.env = cf.get_value('hive_info', 'env') self.keytab = cf.get_value('hive_info', 'keytab') self.username = cf.get_value('hive_info', 'user') self.database = cf.get_value('hive_info', 'database') self.file_path = '' self.fresh_table_info = ''
#coding=utf-8 import os from utils.readconfig import ReadConfig # 读取配置文件 config_file_path = os.path.split(os.path.realpath(__file__))[0] read_config = ReadConfig(os.path.join(config_file_path,'config.ini')) # 项目参数设置 prj_path = read_config.getValue('projectConfig','project_path') # 日志路径 log_path = os.path.join(prj_path, 'log') # 截图文件路径 img_path = os.path.join(prj_path, 'image') # 测试报告路径 report_path = os.path.join(prj_path, 'report') # 默认浏览器 browser = 'Chrome' # 测试数据路径 data_path = os.path.join(prj_path, 'data')
''' @Date: 2020-06-24 11:26:50 @Author: ashen23 @LastEditors: ashen_23 @LastEditTime: 2020-07-14 11:15:01 @FilePath: /faker/utils/log_utils.py ''' # 方便后续随时更换或者增加规则 import os import logging import logging.handlers from utils.readconfig import ReadConfig userConfig = ReadConfig() logger = logging.getLogger("fakerlogger") logger.setLevel(logging.DEBUG) # 判断log文件是否存在 logFile = userConfig.logFile() if not os.path.exists(logFile): newDir = os.path.dirname(logFile) if not os.path.exists(newDir): os.makedirs(newDir) open(logFile, 'w') rf_handler = logging.handlers.TimedRotatingFileHandler( filename=userConfig.logFile(), when='D', interval=1, backupCount=10) rf_handler.setFormatter( logging.Formatter(
'.:::::' ':'````.. @Description: 处理 api.ini 配置 @Author: ashen23 @LastEditTime: 2020-07-14 11:04:21 @FilePath: /faker/utils/normal_utils.py @Copyright: © 2020 Ashen23. All rights reserved. ''' import json import socket from flask import jsonify from utils.file_utils import loadJson from utils.log_utils import logDebug, logError, logInfo from utils.readconfig import ReadConfig userConfig = ReadConfig() # 获取本机ip地址 def getLocalIp(): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 80)) ip = s.getsockname()[0] finally: s.close() return 'http://' + ip + ':5000/' def resSuccess(res=None): return jsonify({'code': 1, 'msg': '成功', 'data': res})
from common.getparentpath import GetParentPath from common.sendrequests import SendRequets from utils.log import Logger from utils.readconfig import ReadConfig import os import json from utils.readexcel import ReadExcel baseurl = ReadConfig().get_http('baseurl') cookies = ReadConfig().get_http('cookies') open_file = ReadExcel('os测试用例.xlsx', 'home') headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Cookie': cookies } class PreTest(): def simplePost(self, row=1, col1=2, col2=3, col3=4): path = open_file.read_xls(row, col1) url = baseurl + path method = open_file.read_xls(row, col2) data = open_file.read_xls(row, col3) result = SendRequets().send_requests(method=method, url=url, data=data, headers=headers) return result
from utils.file_utils import jsonPathBy, loadJson, writeJson, renameJson from utils.normal_utils import getLocalIp, groupIcons, resError, resSuccess, resNotFound from utils.log_utils import logDebug, logError, logInfo from utils.models import initData, UrlModel from modules.resource import bpResource app = Flask(__name__) api = Api(app) app.jinja_env.variable_start_string = '{{ ' app.jinja_env.variable_end_string = ' }}' app.config['JSON_AS_ASCII'] = False app.register_blueprint(bpResource, url_prefix='/resource') initData() userConfig = ReadConfig() class FetchRequest(Resource): def get(self): return featchJson(request) def post(self): return featchJson(request) # 根据url 获取json内容 def featchJson(request): logDebug("[fetch]url:{} {}".format(request.path, request.method)) urlModel = Uapi.getUrlByPath(request.path)