Ejemplo n.º 1
0
def schedule_debug_suite(*args, **kwargs):
    """定时任务
    """

    project = kwargs["project"]
    suite = []
    test_sets = []
    config_list = []
    for pk in args:
        try:
            name = models.Case.objects.get(id=pk).name
            suite.append({"name": name, "id": pk})
        except ObjectDoesNotExist:
            pass

    for content in suite:
        test_list = models.CaseStep.objects. \
            filter(case__id=content["id"]).order_by("step").values("body")

        testcase_list = []
        config = None
        for content in test_list:
            body = eval(content["body"])
            if "base_url" in body["request"].keys():
                config = eval(
                    models.Config.objects.get(name=body["name"],
                                              project__id=project).body)
                continue
            testcase_list.append(body)
        config_list.append(config)
        test_sets.append(testcase_list)

    summary = debug_suite(test_sets, project, suite, config_list, save=False)
    save_summary("", summary, project, type=3)
Ejemplo n.º 2
0
def schedule_debug_suite(*args, **kwargs):
    """定时任务
    """

    project = kwargs["project"]
    suite = []
    test_sets = []
    config_list = []
    for pk in args:
        try:
            name = models.Case.objects.get(id=pk).name
            suite.append({"name": name, "id": pk})
        except ObjectDoesNotExist:
            pass

    for content in suite:
        test_list = models.CaseStep.objects. \
            filter(case__id=content["id"]).order_by("step").values("body")

        testcase_list = []
        config = None
        for content in test_list:
            body = eval(content["body"])
            if "base_url" in body["request"].keys():
                config = eval(
                    models.Config.objects.get(name=body["name"],
                                              project__id=project).body)
                continue
            testcase_list.append(body)
        config_list.append(config)
        test_sets.append(testcase_list)

    summary, _ = debug_suite(test_sets,
                             project,
                             suite,
                             config_list,
                             save=False)
    task_name = kwargs["task_name"]

    if kwargs.get('run_type') == 'deploy':
        task_name = '部署_' + task_name
        report_type = 4
    else:
        report_type = 3

    save_summary(task_name,
                 summary,
                 project,
                 type=report_type,
                 user=kwargs.get('user', ''))

    strategy = kwargs["strategy"]
    if strategy == '始终发送' or (strategy == '仅失败发送'
                              and summary['stat']['failures'] > 0):
        # ding_message = DingMessage(run_type)
        # ding_message.send_ding_msg(summary, report_name=task_name)
        webhook = kwargs.get("webhook", "")
        if webhook:
            summary["task_name"] = task_name
            lark_message.send_message(summary=summary, webhook=webhook)
Ejemplo n.º 3
0
def run_suite_tree(request):
    """run suite by tree
    {
        project: int
        relation: list
        name: str
        async: bool
        host: str
    }
    """
    # order by id default
    project = request.data['project']
    relation = request.data["relation"]
    back_async = request.data["async"]
    report = request.data["name"]
    host = request.data["host"]

    if host != "请选择":
        host = models.HostIP.objects.get(name=host,
                                         project=project).value.splitlines()

    test_sets = []
    suite_list = []
    config_list = []
    for relation_id in relation:
        suite = list(
            models.Case.objects.filter(
                project__id=project,
                relation=relation_id).order_by('id').values('id', 'name'))
        for content in suite:
            test_list = models.CaseStep.objects. \
                filter(case__id=content["id"]).order_by("step").values("body")

            testcase_list = []
            config = None
            for content in test_list:
                body = eval(content["body"])
                if "base_url" in body["request"].keys():
                    config = eval(
                        models.Config.objects.get(name=body["name"],
                                                  project__id=project).body)
                    continue
                testcase_list.append(parse_host(host, body))
            # [[{scripts}, {scripts}], [{scripts}, {scripts}]]
            config_list.append(parse_host(host, config))
            test_sets.append(testcase_list)
            suite_list = suite_list + suite

    if back_async:
        tasks.async_debug_suite.delay(test_sets, project, suite_list, report,
                                      config_list)
        summary = loader.TEST_NOT_EXISTS
        summary["msg"] = "用例运行中,请稍后查看报告"
    else:
        summary = loader.debug_suite(test_sets, project, suite_list,
                                     config_list)

    return Response(summary)
Ejemplo n.º 4
0
def run_suite_tree(request):
    """run suite by tree
    {
        project: int
        relation: list
        name: str
        async: bool
    }
    """
    # order by id default
    project = request.data['project']
    relation = request.data["relation"]
    back_async = request.data["async"]
    report = request.data["name"]

    config = None
    testcase = []
    for relation_id in relation:
        suite = models.Case.objects.filter(
            project__id=project,
            relation=relation_id).order_by('id').values('id', 'name')

        for content in suite:
            test_list = models.CaseStep.objects. \
                filter(case__id=content["id"]).order_by("step").values("body")
            # [{scripts}, {scripts}]
            testcase_list = []

            for content in test_list:
                body = eval(content["body"])
                if "base_url" in body["request"].keys():
                    config = eval(
                        models.Config.objects.get(name=body["name"],
                                                  project__id=project).body)
                    continue
                testcase_list.append(body)
            # [[{scripts}, {scripts}], [{scripts}, {scripts}]]
            testcase.append(testcase_list)

    if back_async:
        loader.async_debug_suite(testcase,
                                 project,
                                 report,
                                 suite,
                                 config=config)
        summary = loader.TEST_NOT_EXISTS
        summary["msg"] = "用例运行中,请稍后查看报告"
    else:
        summary = loader.debug_suite(testcase, project, suite, config=config)

    return Response(summary)
Ejemplo n.º 5
0
def run_suite_tree(request):
    """run suite by tree
    {
        project: int
        relation: list
        config: int
        name: str
        async: bool
    }
    """
    # order by id default
    project = request.data['project']
    relation = request.data["relation"]
    back_async = request.data["async"]
    name = request.data["name"]
    config = request.data["config"]

    testcase = []
    for relation_id in relation:
        suite = models.Case.objects.filter(project__id=project, relation=relation_id).order_by('id').values('id')

        for content in suite:
            test_list = models.CaseStep.objects. \
                filter(case__id=content["id"]).order_by("step").values("body")
            # [{scripts}, {scripts}]
            testcase_list = []

            for content in test_list:
                testcase_list.append(eval(content["body"]))
            # [[{scripts}, {scripts}], [{scripts}, {scripts}]]
            testcase.append(testcase_list)

    if back_async:
        loader.async_debug_suite(testcase, config, project, name)
        summary = loader.TEST_NOT_EXISTS
        summary["msg"] = "用例运行中,请稍后查看报告"
    else:
        summary = loader.debug_suite(testcase, config, project)

    return Response(summary)
Ejemplo n.º 6
0
def async_debug_suite(suite, project, obj, report, config):
    """异步执行suite
    """
    summary = debug_suite(suite, project, obj, config=config, save=False)
    save_summary(report, summary, project)
Ejemplo n.º 7
0
def async_debug_suite(suite, project, obj, report, config):
    """异步执行suite
    """
    logger.info("async_debug_suite start!!!")
    summary = debug_suite(suite, project, obj, config=config, save=False)
    save_summary(report, summary, project)