Example #1
0
 def get(self):
     if self.ags['type'] == 'get':
         result = FilesManager().get_list()
         if result:
             return {'message': True, 'data': result}
         else:
             return {'message': False, 'data': None}
     elif self.ags['type'] == 'download':
         basename = FilesManager().get_file_name(self.ags['fileid'])
         file_path = os.path.join(Path().get_current_path(), 'static/filesmanager',
                                  basename)
         dir_path = os.path.join(Path().get_current_path(), 'static/filesmanager')
         if os.path.exists(file_path):
             response = make_response(send_from_directory(dir_path, basename, as_attachment=True))
             # response.headers["Content-Disposition"] = "; filename=%s;" % (str(self.ags['filename']))
             # response.headers["Content-Disposition"] = "attachment;filename*=UTF-8''{}"\
             #     .format(utf_filename=quote(self.ags['filename'].ecode('utf-8')))
             response.headers["Content-Disposition"] = \
                 "attachment;" \
                 "filename*=UTF-8''{utf_filename}".format(
                     utf_filename=quote(basename.encode('utf-8'))
                 )
             return response
         else:
             return None
Example #2
0
 def get(self):
     if self.ags['filepath'] == 'jmeter':
         path = 'jmeter/jmx'
     elif self.ags['filepath'] == 'report':
         path = 'static/report'
         result = FilesManager().get_report(path)
         if result:
             return {'message': True, 'data': result}
         else:
             return {'message': False, 'data': None}
     elif self.ags['filepath'] == 'apitest':
         path = 'com/common/api_test/testcases'
     elif self.ags['filepath'] == 'api_report':
         path = 'static/api_report'
         result = FilesManager().get_api_report(path)
         if result:
             return {'message': True, 'data': result}
         else:
             return {'message': False, 'data': None}
     elif self.ags['filepath'] == 'standard':
         path = 'static/standard'
         result = FilesManager().get_api_report(path)
         if result:
             return {'message': True, 'data': result}
         else:
             return {'message': False, 'data': None}
     else:
         path = 'static/filesmanager'
     if self.ags['type'] == 'get':
         result = FilesManager().get_list(path)
         if result:
             return {'message': True, 'data': result}
         else:
             return {'message': False, 'data': None}
     elif self.ags['type'] == 'download':
         basename = FilesManager().get_file_name(self.ags['fileid'])
         file_path = os.path.join(Path().get_current_path(), path, basename)
         dir_path = os.path.join(Path().get_current_path(), path)
         if os.path.exists(file_path):
             response = make_response(
                 send_from_directory(dir_path, basename,
                                     as_attachment=True))
             response.headers["Content-Disposition"] = \
                 "attachment;" \
                 "filename*=UTF-8''{utf_filename}".format(
                     utf_filename=quote(basename.encode('utf-8'))
                 )
             return response
         else:
             return None
Example #3
0
 def __init__(self):
     global_path = Path().get_current_path()
     conf = configparser.ConfigParser()
     conf.read(global_path + '/config/config.ini', encoding='utf-8')
     self.secret_key = conf.get('aes_key', 'secret_key')
     self.iv = conf.get('aes_key', 'iv')
     self.data = conf.get('aes_key', 'data')
class Redis:
    global_path = Path().get_current_path()
    logging.config.fileConfig(global_path + '/config/logger.conf')
    password = ''

    def get_nodes(self):
        nodes = []
        try:
            conf = configparser.ConfigParser()
            conf.read(self.global_path + '/config/config.ini',
                      encoding='utf-8')
            host_port = conf.get('redis', 'nodes')
            ips = host_port.split(',')
            self.password = conf.get('redis', 'password')
            for item in ips:
                m = {'host': item.split(':')[0], 'port': item.split(':')[1]}
                nodes.append(m)
            logging.info('nodes:%s' % nodes)
        except Exception as e:
            logging.error(str(e))
        return nodes

    def config_redis(self):
        revisions = None
        redis_nodes = self.get_nodes()
        try:
            revisions = StrictRedisCluster(startup_nodes=redis_nodes,
                                           password=self.password)
        except Exception as e:
            logging.error(str(e))
        return revisions

    def get_key(self, key):
        return self.config_redis().get(key)
Example #5
0
class Redis:
    global_path = Path().get_current_path()
    password = ''

    def __init__(self):
        self.r = redis.Redis(host='localhost', port=6379,
                             decode_responses=True)  # host是redis主机,需要redis服务端和客户端都启动 redis默认端口是6379

    def get_nodes(self):
        nodes = []
        try:
            conf = configparser.ConfigParser()
            conf.read(self.global_path + '/config/config.ini', encoding='utf-8')
            host_port = conf.get('redis', 'nodes')
            ips = host_port.split(',')
            self.password = conf.get('redis', 'password')
            for item in ips:
                m = {'host': item.split(':')[0], 'port': item.split(':')[1]}
                nodes.append(m)
            logging.info('nodes:%s' % nodes)
        except Exception as e:
            logging.error(str(e))
        return nodes

    def config_redis(self):
        revisions = None
        redis_nodes = self.get_nodes()
        try:
            if self.password == "":
                revisions = StrictRedisCluster(startup_nodes=redis_nodes)
            else:
                revisions = StrictRedisCluster(startup_nodes=redis_nodes, password=self.password)
        except Exception as e:
            logging.error(str(e))
        return revisions

    def get_key(self, key):
        return self.r.get(key)

    def get_key_map(self, key):
        return eval(self.r.get(key))

    def set_key(self, key, value):
        try:
            return self.r.set(key, value)
        except:
            return False

    def delete_key(self, key):
        return self.r.delete(key)

    def add_list_item(self, key, valus):
        self.r.lpush(key, valus)

    def get_list(self, key):
        return self.r.lrange(key, 0, self.r.llen(key))

    def get_r(self):
        return self.r
 def exists_path(self, upload_path, path, file_name):
     if os.path.exists(upload_path):
         upload_path = os.path.join(Path().get_current_path(), path,
                                    'R' + file_name)
         file_name = 'R' + file_name
         return self.exists_path(upload_path, path, file_name)
     else:
         return [upload_path, file_name]
Example #7
0
 def post(self):
     f = request.files['files']
     upload_path = os.path.join(Path().get_current_path(), 'static/uploads',
                                secure_filename(f.filename))
     f.save(upload_path)
     result = ExcelOperate().get_excellist(upload_path)
     os.remove(upload_path)
     result = TestCaseOperate().batch_operate(result, user=self.ags.user)
     return result
Example #8
0
 def __init__(self):
     self.path = Path().get_current_path()
     conf = configparser.ConfigParser()
     conf.read(self.path + '/config/config.ini', encoding='utf-8')
     self.mysql = conf.get('server', 'mysql')
     self.r = Redis().get_r()
     self.engine = create_engine(self.mysql + "/?charset=utf8")
     self.session = sessionmaker(self.engine)
     self.mySession = self.session()
     self.result = self.mySession.query(CoreSysDate)
Example #9
0
 def __init__(self):
     self.mail_host = 'smtp.163.com'
     self.mail_user = '******'
     self.mail_password = '******'
     self.port = 465
     self.sender = '*****@*****.**'
     self.global_path = Path().get_current_path()
     conf = configparser.ConfigParser()
     conf.read(self.global_path + '/config/config.ini')
     self.receivers = eval(conf.get('mail', 'resport_reciver'))
Example #10
0
 def __init__(self):
     self.path = Path().get_current_path()
     conf = configparser.ConfigParser()
     conf.read(self.path + '/config/config.ini', encoding='utf-8')
     self.redis = conf.get('server', 'redis')
     self.r = redis.Redis(host=self.redis,
                          port=6379,
                          decode_responses=True,
                          password="******"
                          )  # host是redis主机,需要redis服务端和客户端都启动 redis默认端口是6379
 def delete_reports(self, *args):
     try:
         for item in args:
             for data in item:
                 file_path = os.path.join(Path().get_current_path(), 'static/report',
                                          data[0])
                 shutil.rmtree(file_path)
         return True
     except Exception as e:
         logging.error(str(e))
         return False
 def delete_files(self, *args):
     try:
         for item in args:
             for data in item:
                 file_path = os.path.join(Path().get_current_path(), data[6],
                                          data[1])
                 os.remove(file_path)
         return True
     except Exception as e:
         logging.error(str(e))
         return False
Example #13
0
 def __init__(self):
     self.cases = ''
     self.get_all_case()
     self.report = []
     self.start_time = datetime.datetime.now()
     self.end_time = datetime.datetime.now()
     self.user = '******'
     self.executetype = 'other'
     self.env = ''
     self.globalpath = Path().get_current_path()
     self.conf = configparser.ConfigParser()
     self.conf.read(self.globalpath + '/config/config.ini')
     self.batch_number = ''
     self.fail = 0
 def __init__(self):
     self.r = Redis()
     self.compare = Compare()
     self.report = TestReport()
     self.certNo = ""
     self.name = ""
     self.mobile = ""
     self.cardNo = ""
     self.bankCard = ""
     self.assetNo = ""
     self.applyAmt = ""
     self.totalTerm = ""
     self.yearRate = ""
     self.path = Path().get_current_path()
Example #15
0
 def delete_reports(self, *args, path):
     try:
         for item in args:
             for data in item:
                 file_path = os.path.join(Path().get_current_path(), path,
                                          str(data[1]))
                 if os.path.isdir(file_path):
                     shutil.rmtree(file_path)
                 else:
                     os.remove(file_path)
         return True
     except Exception as e:
         logging.error(str(e))
         return False
 def save_file(self, request_file, path):
     try:
         file = request_file
         file_name = file.filename
         upload_path = os.path.join(Path().get_current_path(), path,
                                    file_name)
         result = self.exists_path(upload_path, path, file_name)
         if result:
             upload_path = result[0]
             file_name = result[1]
         file.save(upload_path)
         file_size = os.path.getsize(upload_path)
         file_type = file.filename[file.filename.rfind('.') + 1:]
         return {'file_size': file_size, 'file_type': file_type, 'file_name': file_name, 'file_path': path}
     except Exception as e:
         logging.error(str(e))
         return None
Example #17
0
class BaseApi:
    path = Path().get_current_path()
    conf = configparser.ConfigParser()
    conf.read(path + '/config/config.ini', encoding='utf-8')
    server = conf.get('server', 'server')
    param = None
    url = ""
    base_url = "http://" + server + ":8012"
    project_code = "xy"

    def set_project(self, project_code):
        self.project_code = project_code

    def set_base(self):
        self.base_param = {"system": "auto_test",
                           "projectCode": self.project_code,
                           "reqId": datetime.now().strftime("%Y%m%d%H%M%S") + str(random.randint(100000, 999999)),
                           "timestamp": datetime.timestamp(datetime.now())
                           }

    def set_base_url(self, url):
        self.base_url = url

    def set_data(self):
        if self.param:
            self.base_param["data"] = self.param

    def set_url(self, url):
        self.base_url = url

    def post(self):
        try:
            self.set_base()
            self.set_data()
            b = datetime.now()
            self.r = requests.post(url=self.base_url + self.url, json=self.base_param)
            a = datetime.now()
            self.use_time = (a - b).microseconds / 1000
            logging.info("请求地址:%s\n请求参数:%s\n响应参数:%s", self.url, self.base_param, self.r.json())
            return {"param": self.base_param, "response": self.r.json(), "status": self.r.status_code,
                    "url": self.r.url, "use_time": self.use_time}
        except Exception as e:
            logging.error("请求报错:%s \n %s", repr(e), self.r.json())
            return {"param": self.base_param, "response": self.r.json(), "status": self.r.status_code,
                    "url": self.r.url, "use_time": self.use_time}
Example #18
0
    def __init__(self):
        self.app = app
        self.globalspath = Path().get_current_path()
        self.app.config['SECRET_KEY'] = '123456'
        self.app.config[
            'SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + self.globalspath + '/static/sqlite.db'
        self.app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
        self.app.config['SQLALCHEMY_COMMIT_TEARDOWN'] = True
        self.app.config['SCHEDULER_API_ENABLED'] = True

        logging.config.fileConfig(self.globalspath + '/config/logger.conf')
        conf = configparser.ConfigParser()
        conf.read(self.globalspath + '/config/config.ini', encoding='utf-8')

        # 注册admin管理模块
        self.db = SQLAlchemy(self.app)
        self.bootstrap = Bootstrap(self.app)
        self.admin = Admin(self.app, name='YPSH', template_mode='bootstrap3')

        # 注册定时任务
        self.scheduler = APScheduler()
        self.scheduler.init_app(self.app)
        self.scheduler.start()
Example #19
0
# -*- coding: UTF-8 -*-
import configparser
import json

from flask import Blueprint, send_from_directory
from flask import render_template
from flask import request

from com.common.getPath import Path
from com.service.moker import ServiceOperate
from config.extendlink import get_titles

view = Blueprint('view', __name__)

conf = configparser.ConfigParser()
conf.read(Path().get_current_path() + '/config/config.ini', encoding='utf-8')


@view.route('/')
def start():
    return render_template('index.html')


@view.route('/dashboard')
def dashboard():
    return render_template('subtemplates/dashboard/dashboard.html')


@view.route('/extendlink')
def extendlink():
    titles = get_titles()
Example #20
0
 def __init__(self):
     self.tasks = self.get_alltask()
     global_path = Path().get_current_path()
     self.url = 'sqlite:///' + global_path + '/static/sqlite.db'
class TestCases:
    global_path = Path().get_current_path()
    logging.config.fileConfig(global_path + '/config/logger.conf')
    conf = configparser.ConfigParser()
    conf.read(global_path + '/config/config.ini', encoding='utf-8')
    project_code = "xy"

    def __init__(self):
        self.r = Redis()
        self.compare = Compare()
        self.report = TestReport()
        self.certNo = ""
        self.name = ""
        self.mobile = ""
        self.cardNo = ""
        self.bankCard = ""
        self.assetNo = ""
        self.applyAmt = ""
        self.totalTerm = ""
        self.yearRate = ""
        self.path = Path().get_current_path()

    def read_file(self, path):
        try:
            with open(path, 'r', encoding='utf-8') as file:
                file_lines = file.readlines()
                return file_lines
        except Exception as e:
            logging.error(repr(e))

    def output_report(self, report):
        try:
            table_data = []
            detail_data = []
            pass_case = 0
            fail_case = 0
            use_time = "10"
            create_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            report_bass_path = self.path + '/com/testcommon/standard/common/report_base.html'
            report_path = self.path + ('/static/standard/report_' + self.project_code + "_" + datetime.now().strftime(
                '%Y%m%d%H%M%S') + '.html')
            i = 1
            for case in report:
                case = eval(case)
                table_data.append(
                    [i, case["name"], str(case["expect"]), str(case["actual"]), str(case["result"]),
                     str(case["use_time"])]
                )
                detail_data.append(
                    [i, case["name"], str(case["expect"]), str(case["actual"]), str(case["result"]),
                     str(case["use_time"]), str(case["param"]), str(case["response"]), str(case["url"])])
                if case['result']:
                    pass_case += 1
                else:
                    fail_case += 1
                i += 1

            lines = self.read_file(report_bass_path)
            for i in range(0, len(lines)):
                lines[i] = str(lines[i]).replace('"{{tabledata}}"', str(table_data)).replace('"{{details}}"',
                                                                                             str(detail_data)).replace(
                    '"{{pass}}"', str(pass_case)).replace('"{{fail}}"', str(fail_case)).replace('"{{use_time}}"',
                                                                                                str(use_time)).replace(
                    '"{{create_time}}"', str(create_time))

            with open(report_path, 'w', encoding='utf-8') as f:
                for line in lines:
                    f.write(line)
            logging.info('测试报告生成路径:' + report_path)
        except Exception as e:
            logging.error("生成报告错误:%s", repr(e))
Example #22
0
 def __init__(self):
     self.path = Path().get_current_path()
     conf = configparser.ConfigParser()
     conf.read(self.path + '/config/config.ini', encoding='utf-8')
     self.server = conf.get('server', 'server')
Example #23
0
# -*- coding: UTF-8 -*-
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship

from com.common.getPath import Path

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + Path().get_current_path(
) + '/static/sqlite.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SQLALCHEMY_COMMIT_TEARDOWN'] = True

db = SQLAlchemy(app)


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user = db.Column(db.String(80), unique=True)
    password = db.Column(db.String(120))
    image = db.Column(db.String)
    role = db.Column(db.String)
    email = db.Column(db.String)
    mobile = db.Column(db.String)
    is_active = db.Column(db.String)

    # create_time = db.Column(db.String)

    def __init__(self, *args):
        self.user = args
Example #24
0
            path = os.path.join(path, 'report')
            dir_path = os.path.join(path, dir_name)
            if os.path.exists(dir_path) is not True:
                os.mkdir(dir_path)
                return dir_path
            else:
                return None
        except Exception as e:
            logging.error("创建报告目录失败" + str(e))

    def execute_jmx(self, jmx):
        try:
            path = os.path.join(self.globalpath, 'jmeter')
            reportpath = self.make_dir(jmx)
            jmxpath = os.path.join(path, 'jmx', jmx)
            jtlpath = os.path.join(reportpath, 'result.jtl')
            resultpath = os.path.join(reportpath, 'result')
            logpath = os.path.join(reportpath, 'jmeter.log')
            command = self.find_jmeter(
                path
            ) + " -n -t " + jmxpath + ' -l ' + jtlpath + " -e -o " + resultpath + " -j " + logpath
            os.popen(command)
            return {'message': True}
        except Exception as e:
            return {'message': False}


if __name__ == '__main__':
    path = Path().get_current_path() + '/jmeter'
    Jmeter().execute_jmx('秦农-查询.jmx')
 def __init__(self):
     self.path = Path().get_current_path()
 def __init__(self):
     self.global_path = Path().get_current_path()
     self.district_code = self.get_district_code()
     self.min_age = 1919
     self.max_age = 2018
     self.sex = 2
Example #27
0
 def __init__(self):
     self.conf = configparser.ConfigParser()
     self.globalpath = Path().get_current_path()
     self.conf.read(self.globalpath + '/config/config.ini',
                    encoding='utf-8')
Example #28
0
# -*- coding: UTF-8 -*-
import configparser
import json

from flask import Blueprint
from flask import render_template
from flask import request

from com.common.getPath import Path
from com.service.moker import ServiceOperate
from config.extendlink import get_titles

view = Blueprint('view', __name__)

conf = configparser.ConfigParser()
conf.read(Path().get_current_path() + '/config/config.ini')


@view.route('/')
def start():
    return render_template('index.html')


@view.route('/dashboard')
def dashboard():
    return render_template('subtemplates/dashboard/dashboard.html')


@view.route('/extendlink')
def extendlink():
    titles = get_titles()