def import_base_handler(self):
        json_file = request.files.get('json-import')
        mimetype = json_file.content_type
        # 判断是不是json格式的文件
        if mimetype == 'application/json':
            # 读取文件流,注意文件流只能read一次
            bytes_obj = json_file.read()
            try:
                check_result = BaseDataHandler().check_base(json.loads(bytes_obj))
                if check_result:
                    return check_result

                self.write_wb(DEFAULT_BASE, bytes_obj)
                # 读取json文件
                json_obj = json.loads(codecs.open(DEFAULT_BASE, 'r', 'utf-8').read())
                # 获取文件的sha1
                app_context.base_sha1 = self.get_sha1(bytes_obj)
                # 初次处理,切换后的result
                mergeAlgorithm.first_result_handler(json_obj)
                mergeAlgorithm.coverage_arithmetic(json_obj)
                resp = context.make_ok_response()
                lyrebird.publish('api_coverage', 'operation', name='import_base')
            except Exception as e:
                resp = context.make_fail_response('导入文件内容格式有误:' + str(e))
                lyrebird.publish('api_coverage', 'error', name='import_base')
        else:
            resp = context.make_fail_response("Error.The selected non - JSON file.")
            lyrebird.publish('api_coverage', 'error', name='import_base')
        return resp
Пример #2
0
 def clear_result(self):
     ResultHandler().clear_cache_result()
     # 获取基准文件
     base_dict = BaseDataHandler().get_base_source()
     # 初始化正常会进行数据的处理:覆盖率初始化 & API LIST初始化
     if not isinstance(base_dict, Response):
         mergeAlgorithm.first_result_handler(base_dict)
         mergeAlgorithm.coverage_arithmetic(base_dict)
     lyrebird.publish('api_coverage', 'operation', name='clear_result')
     return context.make_ok_response()
Пример #3
0
    def on_create(self):

        # 获取base_data_config文件信息
        base_dict = BaseDataHandler().get_base_source()
        # 如果import的文件异常
        if not isinstance(base_dict, Response):
            mergeAlgorithm.first_result_handler(base_dict)
            mergeAlgorithm.coverage_arithmetic(base_dict)

        # 设置模板目录(可选,设置模板文件目录。默认值templates)
        self.set_template_root('lyrebird_api_coverage')
        # 设置静态文件目录(可选,设置静态文件目录。默认值static)
        self.set_static_root('lyrebird_api_coverage')
        # 设置跟路径(必选,需要提供跟路径用于显示插件首页的内容)
        self.add_url_rule('/', view_func=self.index)

        # 总线消息订阅
        event_subscribe()

        # 获取内存里保存的测试结果API
        self.add_url_rule('/getTest', view_func=self.get_test_data)
        # 获取内存里保存的测试覆盖率信息
        self.add_url_rule('/getCoverage', view_func=self.get_coverage)
        # 保存测试数据在本地
        self.add_url_rule('/saveResult',
                          view_func=self.save_result,
                          methods=['POST'])
        # 续传测试结果
        self.add_url_rule('/resumeTest',
                          view_func=self.resume_test,
                          methods=['POST'])
        # 清空测试缓存结果
        self.add_url_rule('/clearResult', view_func=self.clear_result)
        # 导入base json文件
        self.add_url_rule('/importBase',
                          view_func=self.import_base,
                          methods=['POST'])
        # 获取filter的conf文件
        self.add_url_rule('/getFilterConf', view_func=self.get_filter_conf)
        # 覆盖配置filter conf文件
        self.add_url_rule('/setFilterConf',
                          view_func=self.set_filter_conf,
                          methods=['POST'])
        # overbridge dump 信息用的API
        self.add_url_rule('/api/dump', view_func=self.dump)
        # base info
        self.add_url_rule('/baseInfo', view_func=self.get_base_info)
Пример #4
0
 def get_coverage(self):
     # 获取app_context里面缓存的测试数据
     # 如果内存为空,则视为首次进入该页面
     data = app_context.coverage
     if not data:
         # 获取base_data_config文件信息
         base_dict = BaseDataHandler().get_base_source()
         # 如果import的文件异常
         if isinstance(base_dict, Response):
             resp = base_dict
         else:
             mergeAlgorithm.coverage_arithmetic(base_dict)
             resp = jsonify(app_context.coverage)
     # 若不为空,则视为有测试缓存
     else:
         resp = jsonify(app_context.coverage)
     return resp
Пример #5
0
 def get_coverage_data(self):
     # 获取app_context里面缓存的测试数据
     # 如果内存为空,则视为首次进入该页面
     data = app_context.merge_list
     if not data:
         # 获取base_data_config文件信息
         base_dict = BaseDataHandler().get_base_source()
         # 如果import的文件异常
         if isinstance(base_dict, Response):
             resp = base_dict
         else:
             mergeAlgorithm.first_result_handler(base_dict)
             mergeAlgorithm.coverage_arithmetic(base_dict)
             resp = jsonify({
                 'test_data': app_context.merge_list,
                 'coverage': app_context.coverage
             })
     # 若不为空,则视为有测试缓存
     else:
         resp = jsonify({
             'test_data': app_context.merge_list,
             'coverage': app_context.coverage
         })
     return resp
Пример #6
0
from lyrebird.plugins import manifest
from . import api
from . import interceptor
from flask import Response
from lyrebird_api_coverage.handlers.base_source_handler import BaseDataHandler
from lyrebird_api_coverage.client.merge_algorithm import mergeAlgorithm
from lyrebird_api_coverage.client.event_subscibe import event_subscribe

# 执行插件初始化操作
# 获取base_data_config文件信息
base_dict = BaseDataHandler().get_base_source()
# 如果import的文件异常
if not isinstance(base_dict, Response):
    mergeAlgorithm.first_result_handler(base_dict)
    mergeAlgorithm.coverage_arithmetic(base_dict)
# 总线消息订阅
event_subscribe()

manifest(
    id='api_coverage',
    name='APICoverage',
    api=[
        # 获取内存里保存的测试结果API
        ('/api/getTest', api.get_test_data),
        # 获取内存里保存的测试覆盖率信息
        ('/api/getCoverage', api.get_coverage),
        # 保存测试数据在本地
        ('/api/saveResult', api.save_result, ['POST']),
        # 续传测试结果
        ('/api/resumeTest', api.resume_test, ['POST']),
        # 清空测试缓存结果