Esempio n. 1
0
class BatchDetService(object):
    def __init__(self):

        object.__init__(self)

        self.__resource_batch_det = OrcHttpNewResource("BatchDet")
        self.__resource_case_def = OrcHttpNewResource("CaseDef")

    def usr_add(self, p_data):
        """
        增加,将多条记录转换为单条
        :param p_data:
        :return:
        """
        batch_id = p_data["batch_id"]

        for _case_id in p_data["case"]:
            self.__resource_batch_det.post(
                dict(batch_id=batch_id, case_id=_case_id))

        return dict(batch_id=batch_id)

    def usr_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        return self.__resource_batch_det.delete(p_list)

    def usr_update(self, p_data):
        """
        更新
        :param p_data:
        :return:
        """
        self.__resource_batch_det.set_path(p_data["id"])
        return self.__resource_batch_det.put(p_data)

    def usr_search(self, p_cond):
        """
        查询,查询batch及case并连接数据
        :param p_cond:
        :return:
        """
        # 查询 batch_det 列表
        batch_det_list = self.__resource_batch_det.get(p_cond)

        # case_det id 列表
        case_def_id_list = [
            batch_det["case_id"] for batch_det in batch_det_list
        ]

        # case_def 列表
        case_def_list = self.__resource_case_def.get(dict(id=case_def_id_list))

        # 连接 list 并返回
        return connect_list(batch_det_list, case_def_list, "case_id")
Esempio n. 2
0
class CaseDefService(object):
    def __init__(self):

        object.__init__(self)

        self.__resource_case_def = OrcHttpNewResource("CaseDef")
        self.__resource_run_def = OrcHttpNewResource("RunDef")

    def usr_add(self, p_data):
        """
        新增
        :param p_data:
        :return:
        """
        case_def_data = self.__resource_case_def.post(p_data)
        return dict(id=case_def_data["id"])

    def usr_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        return self.__resource_case_def.delete(p_list)

    def usr_update(self, p_data):
        """
        更新
        :param p_data:
        :return:
        """
        self.__resource_case_def.set_path(p_data["id"])
        return self.__resource_case_def.put(p_data)

    def usr_search(self, p_cond):
        """
        查询
        :param p_cond:
        :return:
        """
        cond = dict(type="all")
        cond.update(p_cond)
        return self.__resource_case_def.get(cond)

    def add_to_run(self, p_id):
        """
        加入运行
        :param p_id:
        :return:
        """
        cond = dict(id=p_id, run_def_type="CASE")
        self.__resource_run_def.post(cond)
Esempio n. 3
0
class BatchDefService(object):
    def __init__(self):

        object.__init__(self)

        self.__resource_batch_def = OrcHttpNewResource("BatchDef")
        self.__resource_run_def = OrcHttpNewResource("RunDef")

    def usr_add(self, p_data):
        """
        增加
        :param p_data:
        :return:
        """
        node = self.__resource_batch_def.post(p_data)
        return dict(id=node["id"])

    def usr_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        return self.__resource_batch_def.delete(p_list)

    def usr_update(self, p_data):
        """
        更新
        :param p_data:
        :return:
        """
        self.__resource_batch_def.set_path(p_data["id"])
        return self.__resource_batch_def.put(p_data)

    def usr_search(self, p_cond):
        """
        查询
        :param p_cond:
        :return:
        """
        cond = dict(type="all")
        cond.update(p_cond)
        return self.__resource_batch_def.get(cond)

    def add_to_run(self, p_id):

        cond = dict(id=p_id, run_def_type="BATCH")

        self.__resource_run_def.set_path(p_id)
        self.__resource_run_def.post(cond)
Esempio n. 4
0
class RunDefService:
    def __init__(self):

        self.__res_run_def = OrcHttpNewResource("RunDef")
        self.__res_run = OrcHttpNewResource("Run")

    def usr_add(self, p_cond):
        """
        :param p_cond: {id, run_def_type, result}
        :return:
        """

        if "pid" not in p_cond:
            return dict()

        cond = dict(id=p_cond["pid"],
                    run_def_type=p_cond["run_def_type"],
                    result=True)

        self.__res_run_def.post(cond)

        return dict()

    def usr_search(self, p_cond):
        """
        查询
        :param p_cond:
        :return:
        """
        return self.__res_run_def.get(p_cond)

    def usr_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        self.__res_run_def.delete(p_list)

    def usr_run(self, p_pid, p_id):
        """
        执行
        :param p_pid:
        :param p_id:
        :return:
        """
        self.__res_run.put(dict(pid=p_pid, id=p_id))
Esempio n. 5
0
    def test_list_add(self):
        """
        Test get root
        :return:
        """
        OrcTest.test_print_begin()

        run_time = OrcHttpNewResource("RunTime")

        data = dict(data_flag="env",
                    data_index=1,
                    data_value="3")
        result = run_time.post(data)

        OrcTest.test_print_result(result)

        OrcTest.test_print_end()
Esempio n. 6
0
class WidgetDefService:
    def __init__(self):

        # Log
        self.__logger = OrcLog("view.driver.web.service.widget_def")
        self.__resource_widget_def = OrcHttpNewResource("WidgetDef")

    def usr_add(self, p_data):
        """
        新增
        :param p_data:
        :return:
        """
        widget_data = self.__resource_widget_def.post(p_data)
        return dict(id=widget_data["id"])

    def usr_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        return self.__resource_widget_def.delete(p_list)

    def usr_update(self, p_data):
        """
        修改
        :param p_data:
        :return:
        """
        self.__resource_widget_def.set_path(p_data["id"])
        return self.__resource_widget_def.put(p_data)

    def usr_search(self, p_cond):
        """
        查询
        :param p_cond:
        :return:
        """
        cond = dict(type="all")
        cond.update(p_cond)

        return self.__resource_widget_def.get(cond)
Esempio n. 7
0
class PageDefService:
    def __init__(self):

        # Log
        self.__logger = OrcLog("view.driver.web.service.page_def")
        self.__resource_page_def = OrcHttpNewResource("PageDef")

    def usr_add(self, p_data):
        """
        新增
        :param p_data:
        :return:
        """
        page_data = self.__resource_page_def.post(p_data)
        return dict(id=page_data["id"])

    def usr_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        return self.__resource_page_def.delete(p_list)

    def usr_update(self, p_data):
        """
        修改
        :param p_data:
        :return:
        """
        self.__resource_case_def.set_path(p_data["id"])
        return self.__resource_page_def.put(p_data)

    def usr_search(self, p_cond):
        """
        查询
        :param p_cond:
        :return:
        """
        return self.__resource_page_def.get(p_cond)
Esempio n. 8
0
class DataService:
    def __init__(self):
        self.__resource_data = OrcHttpNewResource("Data")

    def usr_add(self, p_data):
        """
        新增
        :param p_data:
        :return:
        """
        data_data = self.__resource_data.post(p_data)
        return dict(id=data_data["id"])

    def usr_delete(self, p_cond):
        """
        删除
        :param p_cond:
        :return:
        """
        self.__resource_data.delete(p_cond)

    def usr_update(self, p_data):
        """
        更新
        :param p_cond:
        :return:
        """
        self.__resource_data.set_path(p_data["id"])
        self.__resource_data.put(p_data)

    def usr_search(self, p_cond):
        """
        查询
        :param p_cond:
        :return:
        """
        return self.__resource_data.get(p_cond)
Esempio n. 9
0
class ItemService(object):
    def __init__(self):

        object.__init__(self)

        self.__resource_case_def = OrcHttpNewResource("CaseDef")
        self.__resource_step_det = OrcHttpNewResource("StepDet")
        self.__resource_item = OrcHttpNewResource("Item")

    def usr_add(self, p_data):
        """
        增加
        :param p_data:
        :return:
        """
        step_type = p_data["type"]
        step_id = p_data["step_id"]
        step_data = p_data["data"]

        if "ITEM" == step_type:

            # 增加 item
            item = self.__resource_item.post(step_data)

            # 增加 step det
            step_id = step_id
            item_id = item["id"]
            step_det_data = dict(step_id=step_id, item_id=item_id)

            self.__resource_step_det.post(step_det_data)

        elif "FUNC" == step_type:

            # 增加 step det
            step_id = step_id
            func_id = step_data
            step_det_data = dict(step_id=step_id, item_id=func_id)

            self.__resource_step_det.post(step_det_data)

        return dict(step_id=step_id)

    def usr_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        return self.__resource_step_det.delete(p_list)

    def usr_update(self, p_data):
        """
        更新
        :param p_data:
        :return:
        """
        # 获取 item id
        self.__resource_step_det.set_path(p_data["id"])
        item_id = self.__resource_step_det.get()["item_id"]

        # 更新数据
        data = p_data.copy()
        data["id"] = item_id
        self.__resource_item.set_path(item_id)

        return self.__resource_item.put(p_data)

    def usr_search(self, p_cond):
        """
        删除
        :param p_cond:
        :return:
        """
        # 查询 step det 列表
        step_det_list = self.__resource_step_det.get(p_cond)

        # 查询 item id 列表
        item_id_list = [step_det["item_id"] for step_det in step_det_list]

        # 查询 item 列表
        item_list = self.__resource_item.get(dict(id=item_id_list))

        # 查询 func
        case_list = self.__resource_case_def.get(dict(id=item_id_list))

        # func 转成 item 结构
        func_list = [
            dict(id=case["id"],
                 item_no=case["case_no"],
                 item_mode="",
                 item_type="",
                 item_operate=case["case_path"],
                 item_desc=case["case_desc"],
                 comment=case["comment"],
                 create_time=case["create_time"],
                 modify_time=case["modify_time"]) for case in case_list
        ]

        # 连接 list
        print func_list
        item_list.extend(func_list)
        print item_list
        # 连接数据
        return connect_list(step_det_list, item_list, "item_id")
Esempio n. 10
0
class RunCoreService:
    """
    运行核心模块,负责目录管理,list 管理和执行三部分
    """
    def __init__(self):

        self.__resource_web_driver = OrcHttpNewResource("Driver")
        self.__resource_item = OrcHttpNewResource("Item")
        self.__resource_data = OrcHttpNewResource("Data")
        self.__resource_view = OrcSocketResource("View")

    def launch_web_step(self, p_step_info):
        """
        WEB 类型用例执行项
        :param p_step_info:
        :return:
        """
        return self.__resource_web_driver.post(p_step_info)

    def check_web_step(self, p_step_info):
        """
        WEB 类型步骤检查项
        :param p_step_info:
        :return:
        """
        if "DATA" in p_step_info:
            step_data = p_step_info["DATA"]
            return self.__resource_web_driver.post(p_step_info) == step_data
        else:
            return self.__resource_web_driver.post(p_step_info)

    def get_item(self, p_item_id):
        """
        :param p_item_id:
        :return:
        :rtype: TabItem
        """
        self.__resource_item.set_path(p_item_id)
        item_data = self.__resource_item.get()

        if not item_data:
            return None
        else:
            return TabItem(item_data)

    def get_data(self, p_def_list, p_object_id):
        """tab_data
        :param p_object_id:
        :param p_def_list:
        :type p_def_list: list
        :return:
        """
        p_def_list.reverse()

        for _node in p_def_list:

            _id = _node["id"]
            _type = _node["run_det_type"]

            if _type in ("CASE", "CASE_GROUP"):
                _type = "CASE"
            elif _type in ("BATCH", "BATCH_GROUP"):
                _type = "BATCH"
            else:
                pass

            _data = self.__resource_data.get(
                dict(src_id=_id, src_type=_type, data_flag=p_object_id))

            if _data:
                break
        else:
            return None

        p_def_list.reverse()

        return _data[0]["data_value"]

    def update_status(self, p_data):
        """
        更新界面状态
        :param p_data:
        :return:
        """
        import json
        self.__resource_view.get(json.dumps(p_data))
Esempio n. 11
0
class Runtime(object):
    """

    """
    def __init__(self, p_mod):

        object.__init__(self)

        self.__mod = p_mod
        self.__resource = OrcHttpNewResource("RunTime")

    def add_value(self, p_data):
        """
        新增
        :param p_data:
        :return:
        """
        data = dict(module=self.__mod)
        data.update(p_data)
        return self.__resource.post(data)

    def get_value(self, p_flag):
        """
        获取数据
        :param p_flag:
        :return:
        """
        cond = dict(module=self.__mod, data_flag=p_flag)
        result = self.__resource.get(cond)

        return None if not result else result[0]["data_value"]

    def get_values(self, p_flag):
        """
        获取多条数据
        :param p_flag:
        :return:
        """
        cond = dict(module=self.__mod, data_flag=p_flag)
        result = self.__resource.get(cond)

        return None if not result else [item["data_value"] for item in result]

    def set_value(self, p_flag, p_value, p_index=None):
        """
        设置数据,如果不存在就新增一个,数据有多个时只入第一个
        :param p_index:
        :param p_flag:
        :param p_value:
        :return:
        """
        # 生成查询条件
        cond = dict(module=self.__mod, data_flag=p_flag)
        if p_index is not None:
            cond["data_index"] = p_index

        # 判断数据存在,如果存在找到 id
        data_item = self.__resource.get(cond)
        data_id = None if data_item is None else data_item[0]["id"]

        # 设置值
        if data_id is not None:
            self.__resource.set_path(data_id)
            result = self.__resource.put(dict(data_value=p_value))
        else:
            cond["data_value"] = p_value
            result = self.__resource.post(cond)

        return result

    def del_value(self, p_flag, p_index=None):
        """
        删除数据
        :param p_index:
        :type p_index: int
        :param p_flag:
        :return:
        """
        # 查找数据
        cond = dict(module=self.__mod, data_flag=p_flag)
        data_list = self.__resource.get(cond)

        # 获取 id list
        data_id_list = None if data_list is None else [
            item["id"] for item in data_list
        ]

        # 不存在合适的对象
        if data_id_list is None:
            return False

        # 只删除一条的情况
        if p_index is not None:

            # index 超出范围
            if p_index < len(data_id_list):
                data_id = data_id_list[p_index]
                self.__resource.set_path(data_id)
                return self.__resource.delete()
            else:
                return False

        # 删除符合条件全部数据
        else:
            return self.__resource.delete(data_id_list)
Esempio n. 12
0
class WindowDefService:
    """
    Window service
    """
    def __init__(self):

        # Log
        self.__logger = OrcLog("view.driver.web.service.window_def")

        self.__resource_widget_def = OrcHttpNewResource("WidgetDef")
        self.__resource_widow_def = OrcHttpNewResource("WindowDef")

    def usr_add(self, p_data):
        """
        把存在于 widget 表但在 window 表中不存在的 window 增加到 window 表
        :param p_data:
        :return:
        """
        windows_all = [
            item["id"] for item in self.__resource_widget_def.get(
                dict(widget_type="WINDOW"))
        ]
        windows_exist = [
            item["id"] for item in self.__resource_widow_def.get()
        ]

        if not windows_all:
            return

        for _id in windows_all:
            if (not windows_exist) or (_id not in windows_exist):
                self.__resource_widow_def.post(dict(id=_id))

        return dict()

    def usr_delete(self, p_list):
        """
        :param p_list:
        :return:
        """
        return self.__resource_widow_def.delete(p_list)

    def usr_update(self, p_data):
        """
        :param p_data:
        :return:
        """
        self.__resource_widow_def.set_path(p_data["id"])
        return self.__resource_widow_def.put(p_data)

    def usr_search(self, p_cond):
        """
        :param p_cond:
        :return:
        """
        _cond = p_cond

        # 有 window_flag 条件先查 widget
        if "window_flag" in _cond:
            _ids = [
                item["id"] for item in self.__resource_widget_def.get(
                    dict(widget_flag=_cond["window_flag"]))
            ]
            _cond["id"] = _ids

        # 查询
        _data = self.__resource_widow_def.get(_cond)
        _window_list = self.__resource_widget_def.get(
            dict(widget_type="WINDOW"))

        def _get_widget(p_id):
            for _item in _window_list:
                if _item["id"] == p_id:
                    return _item
            return None

        if _data is None:
            return []
        else:
            for _window in _data:

                _widget = _get_widget(_window["id"])

                if _widget is not None:

                    _window["window_flag"] = _widget["widget_flag"]

            return _data
Esempio n. 13
0
class CaseDetService(object):
    def __init__(self):

        object.__init__(self)

        self.__resource_case_det = OrcHttpNewResource("CaseDet")
        self.__resource_step = OrcHttpNewResource("StepDef")

    def usr_add(self, p_data):
        """
        新增
        :param p_data:
        :return:
        """
        # 增加步骤
        step_info = p_data["step"]
        step_det = self.__resource_step.post(step_info)

        # 增加 case
        case_info = p_data["case_det"]
        case_info["step_id"] = step_det["id"]

        case_det = self.__resource_case_det.post(case_info)

        return dict(case_id=case_det["case_id"])

    def usr_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        return self.__resource_case_det.delete(p_list)

    def usr_update(self, p_data):
        """
        更新
        :param p_data:
        :return:
        """
        # 获取 step id
        self.__resource_case_det.set_path(p_data["id"])
        step_id = self.__resource_case_det.get()["step_id"]

        # 更新数据
        data = p_data.copy()
        data["id"] = step_id
        self.__resource_step.set_path(step_id)

        return self.__resource_step.put(data)

    def usr_search(self, p_cond):
        """
        查询
        :param p_cond:
        :return:
        """
        # 查询 case_det 列表
        case_det_list = self.__resource_case_det.get(p_cond)

        # 查询 step id 列表
        step_id_list = [item["step_id"] for item in case_det_list]

        # 查询 step_def 列表
        step_def_list = self.__resource_step.get(dict(id=step_id_list))

        # 连接数据
        return connect_list(case_det_list, step_def_list, "step_id")
Esempio n. 14
0
class StepService(object):
    def __init__(self):

        object.__init__(self)

        self.__resource_step_det = OrcHttpNewResource("StepDet")
        self.__resource_item = OrcHttpNewResource("Item")

    def usr_add(self, p_data):
        """
        增加
        :param p_data:
        :return:
        """
        # 增加 item
        item = self.__resource_item.post(p_data)

        # 增加 step det
        step_id = p_data["step_id"]
        item_id = item["id"]
        step_data = dict(step_id=step_id, item_id=item_id)
        self.__resource_step_det.post(step_data)

        return dict(step_id=step_id)

    def usr_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        return self.__resource_step_det.delete(p_list)

    def usr_update(self, p_data):
        """
        更新
        :param p_data:
        :return:
        """
        # 获取 item id
        self.__resource_step_det.set_path(p_data["id"])
        item_id = self.__resource_step_det.get()["item_id"]

        # 更新数据
        data = p_data.copy()
        data["id"] = item_id
        self.__resource_item.set_path(item_id)

        return self.__resource_item.put(p_data)

    def usr_search(self, p_cond):
        """
        删除
        :param p_cond:
        :return:
        """
        # 查询 step det 列表
        step_det_list = self.__resource_step_det.get(p_cond)

        # 查询 item id 列表
        item_id_list = [step_det["item_id"] for step_det in step_det_list]

        # 查询 item 列表
        item_list = self.__resource_item.get(dict(id=item_id_list))

        # 连接数据
        return connect_list(step_det_list, item_list, "item_id")