예제 #1
0
    def __init__(self):

        object.__init__(self)

        self.__logger = OrcLog("api.batch.bus.batch_def")
        self.__model_batch_det = BatchDetMod()
        self.__bus_case_def = CaseDefBus()
예제 #2
0
    def __init__(self):

        object.__init__(self)

        init_log()

        self.__logger = OrcLog("api.run_time.bus")
        self.__model_run_time = RunTimeMod()
예제 #3
0
    def __init__(self):

        object.__init__(self)

        init_log()

        self.__logger = OrcLog("api.lib.bus.dict")
        self.__model_dict = DictMod()
예제 #4
0
    def __init__(self):

        object.__init__(self)

        init_log()

        self.__logger = OrcLog("api.case.bus.case_det")
        self.__model_case_det = CaseDetMod()
        self.__bus_step_def = StepDefBus()
예제 #5
0
    def __init__(self):

        object.__init__(self)

        init_log()

        self.__logger = OrcLog("api.case.bus.case_def")
        self.__model_case_def = CaseDefMod()
        self.__bus_case_det = CaseDetBus()
예제 #6
0
    def __init__(self, p_flag, p_model):

        object.__init__(self)

        init_log()

        self._flag = p_flag
        self._model = p_model()
        self._logger = OrcLog("resource.%s.bus" % self._flag)
예제 #7
0
class DictBus(object):
    """
    Dict
    """
    def __init__(self):

        object.__init__(self)

        init_log()

        self.__logger = OrcLog("api.lib.bus.dict")
        self.__model_dict = DictMod()

    def bus_delete(self, p_id):
        """
        删除
        :param p_id:
        :return:
        """
        try:
            result = self.__model_dict.mod_search(p_id)
        except Exception:
            self.__logger.error("Delete dict error, input: %s" % p_id)
            raise OrcApiModelFailException

        return result

    def bus_update(self, p_id, p_cond):
        """
        更新
        :param p_id:
        :param p_cond:
        :return:
        """
        print p_cond
        cond = dict(id=p_id)
        cond.update(p_cond)
        print cond
        try:
            self.__model_dict.mod_update(cond)
        except Exception:
            self.__logger.error("Update dict error, input: %s" % cond)
            raise OrcApiModelFailException

        return True

    def bus_search(self, p_id):
        """
        查询
        :param p_id:
        :return:
        """
        try:
            result = self.__model_dict.mod_search(dict(id=p_id))
            result = None if not result else result[0]
        except Exception:
            self.__logger.error("Update dict error, input: %s" % p_id)
            raise OrcApiModelFailException

        return result
예제 #8
0
class DictListBus(object):
    """
    Dict list
    """
    def __init__(self):

        object.__init__(self)

        init_log()

        self.__logger = OrcLog("api.lib.bus.dicts")
        self.__model_dict = DictMod()

    def bus_list_add(self, p_data):
        """
        新增
        :param p_data:
        :return:
        """
        try:
            result = self.__model_dict.mod_add(p_data)
        except Exception:
            self.__logger.error("Add dict error, input: %s" % p_data)
            raise OrcApiModelFailException

        return result

    def bus_list_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        try:
            for _id in p_list:
                self.__model_dict.mod_delete(_id)
        except Exception:
            self.__logger.error("Delete dict error, input: %s" % p_list)
            raise OrcApiModelFailException

        return True

    def bus_list_search(self, p_cond):
        """
        查询
        :param p_cond:
        :return:
        """
        try:
            result = self.__model_dict.mod_search(p_cond)
        except Exception:
            self.__logger.error("Search dict error, input: %s" % p_cond)
            raise OrcApiModelFailException

        return result
예제 #9
0
class RunTimeBus(object):
    def __init__(self):

        object.__init__(self)

        init_log()

        self.__logger = OrcLog("api.run_time.bus")
        self.__model_run_time = RunTimeMod()

    def bus_list_add(self, p_cond):
        """
        新增
        :param p_cond:
        :return:
        """
        try:
            result = self.__model_run_time.usr_add(p_cond)
        except Exception:
            self.__logger.error("Add run_time error, input: %s" % p_cond)
            raise OrcApiModelFailException

        return result

    def bus_list_delete(self, p_list):
        """
        删除 list, 调用单个删除函数
        :param p_list:
        :return:
        """
        try:
            for _id in p_list:
                self.bus_delete(_id)
        except Exception:
            self.__logger.error("Delete run_time error, input: %s" % p_list)
            raise OrcApiModelFailException

        return True

    def bus_list_search(self, p_cond):
        """
        查询 list
        :param p_cond:
        :return:
        """
        try:
            result = self.__model_run_time.usr_search(p_cond)
        except Exception:
            self.__logger.error("Search run_time error, input: %s" % p_cond)
            raise OrcApiModelFailException

        return result

    def bus_update(self, p_id, p_cond):
        """
        更新一条
        :param p_id:
        :param p_cond:
        :return:
        """
        cond = dict(id=p_id)
        cond.update(p_cond)

        try:
            self.__model_run_time.usr_update(cond)
        except Exception:
            self.__logger.error("Update run_time error, input: %s" % p_cond)
            raise OrcApiModelFailException

        return True

    def bus_delete(self, p_id):
        """
        删除一条
        :param p_id:
        :return:
        """
        try:
            self.__model_run_time.usr_delete(p_id)
        except Exception:
            self.__logger.error("Delete run_time error, input: %s" % p_id)
            raise OrcApiModelFailException

        return True

    def bus_search(self, p_id):
        """
        查询一条
        :param p_id:
        :return:
        """
        try:
            result = self.__model_run_time.usr_search(dict(id=p_id))
            result = None if not result else result[0]
        except Exception:
            self.__logger.error("Search run_time error, input: %s" % p_id)
            raise OrcApiModelFailException

        return result
예제 #10
0
class CaseDefBus(object):
    def __init__(self):

        object.__init__(self)

        init_log()

        self.__logger = OrcLog("api.case.bus.case_def")
        self.__model_case_def = CaseDefMod()
        self.__bus_case_det = CaseDetBus()

    def bus_list_add(self, p_data):
        """
        新增
        :param p_data:
        :return:
        """
        try:
            result = self.__model_case_def.usr_add(p_data)
        except Exception:
            self.__logger.error("Add case error, input: %s" % p_data)
            raise OrcApiModelFailException

        return result

    def bus_list_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        try:
            for _id in p_list:
                self.bus_delete(_id)
        except Exception:
            self.__logger.error("Delete case error, input: %s" % p_list)
            raise OrcApiModelFailException

        return True

    def bus_list_search(self, p_cond):
        """
        查询
        :param p_cond:
        :return:
        """
        result = []

        mode = p_cond["type"] if "type" in p_cond else None
        case_id = p_cond["id"] if "id" in p_cond else None

        try:
            # 查询符合条件的整用例树,至根节点
            if "all" == mode:
                result = self.__model_case_def.usr_search_all(p_cond)

            # 查询用例及子节点
            elif "tree" == mode:
                if case_id is not None:
                    result = self.__model_case_def.usr_search_tree(case_id)

            # 查询用例路径
            elif "path" == mode and case_id:
                if case_id is not None:
                    result = self.__model_case_def.usr_search_path(case_id)

            # 其他情况只查询符合条件的数据
            else:
                result = self.__model_case_def.usr_search(p_cond)

        except OrcApiModelFailException:
            self.__logger.error("Search case error, input: %s" % p_cond)
            raise OrcApiModelFailException

        return result

    def bus_delete(self, p_id):
        """
        删除单个用例
        :param p_id:
        :return:
        """
        # 查询 case 列表, 包含子节点
        case_list = self.bus_list_search(dict(type="tree", id=p_id))
        case_id_list = [item.id for item in case_list]

        # 查询 step 列表
        case_det_list = []
        for _case_id in case_id_list:
            case_det_list.extend(
                self.__bus_case_det.bus_list_search(dict(case_id=_case_id)))
        case_det_id_list = [item.id for item in case_det_list]

        try:
            # 删除 case_det
            self.__bus_case_det.bus_list_delete(case_det_id_list)

            # 删除 case
            for _id in case_id_list:
                self.__model_case_def.usr_delete(_id)

        except Exception:
            self.__logger.error("Delete batch error, input: %s" % p_id)
            raise OrcApiModelFailException

        return True

    def bus_update(self, p_id, p_cond):
        """
        更新
        :param p_id:
        :param p_cond:
        :return:
        """
        cond = dict(id=p_id)
        cond.update(p_cond)

        try:
            self.__model_case_def.usr_update(cond)
        except Exception:
            self.__logger.error("Update batch error, input: %s" % cond)
            raise OrcApiModelFailException

    def bus_search(self, p_id):
        """
        查询单个用例
        :param p_id:
        :return:
        """
        try:
            result = self.__model_case_def.usr_search(dict(id=p_id))
            result = None if not result else result[0]
        except Exception:
            self.__logger.error("Search batch error, input: %s" % p_id)
            raise OrcApiModelFailException

        return result
예제 #11
0
class CaseDetBus(object):
    def __init__(self):

        object.__init__(self)

        init_log()

        self.__logger = OrcLog("api.case.bus.case_det")
        self.__model_case_det = CaseDetMod()
        self.__bus_step_def = StepDefBus()

    def bus_list_add(self, p_data):
        """
        查询
        :param p_data:
        :return:
        """
        try:
            result = self.__model_case_det.usr_add(p_data)
        except Exception:
            self.__logger.error("Add batch error, input: %s" % p_data)
            raise OrcApiModelFailException

        return result

    def bus_list_delete(self, p_list):
        """
        删除
        :param p_list:
        :return:
        """
        try:
            for _id in p_list:
                self.bus_delete(_id)
        except Exception:
            self.__logger.error("Delete batch error, input: %s" % p_list)
            raise OrcApiModelFailException

        return True

    def bus_list_search(self, p_cond):
        """
        查询
        :param p_cond:
        :return:
        """
        try:
            result = self.__model_case_det.usr_search(p_cond)
        except Exception:
            self.__logger.error("Search batch error, input: %s" % p_cond)
            raise OrcApiModelFailException

        return result

    def bus_delete(self, p_id):
        """
        删除
        :param p_id:
        :return:
        """
        try:
            # case det
            case_det = self.__model_case_det.usr_search(dict(id=p_id))

            # step ids
            step_ids = [step.step_id for step in case_det]

            # delete steps
            self.__bus_step_def.bus_list_delete(step_ids)

            # delete case det
            self.__model_case_det.usr_delete(p_id)

        except Exception:
            self.__logger.error("Del case from batch error, input: %s" % p_id)
            raise OrcApiModelFailException

        return True

    def bus_update(self, p_id, p_cond):
        """
        更新
        :param p_id:
        :param p_cond:
        :return:
        """
        cond = dict(id=p_id)
        cond.update(p_cond)

        try:
            self.__model_case_det.usr_update(cond)
        except Exception:
            self.__logger.error("Update case error, input: %s" % cond)
            raise OrcApiModelFailException

        return True

    def bus_search(self, p_id):
        """
        查询
        :param p_id:
        :return:
        """
        try:
            result = self.__model_case_det.usr_search(dict(id=p_id))
            result = None if not result else result[0]
        except Exception:
            self.__logger.error("Search case from batch error, input: %s" %
                                p_id)
            raise OrcApiModelFailException

        return result
예제 #12
0
class OrcBus(object):
    def __init__(self, p_flag, p_model):

        object.__init__(self)

        init_log()

        self._flag = p_flag
        self._model = p_model()
        self._logger = OrcLog("resource.%s.bus" % self._flag)

    def bus_list_add(self, p_cond):
        """
        新增
        :param p_cond:
        :return:
        """
        try:
            result = self._model.usr_add(p_cond)
        except Exception:
            self._logger.error("Add %s error, input: %s" %
                               (self._flag, p_cond))
            raise OrcApiModelFailException

        return result

    def bus_list_delete(self, p_list):
        """
        删除 list, 调用单个删除函数
        :param p_list:
        :return:
        """
        try:
            for _id in p_list:
                self.bus_delete(_id)
        except Exception:
            self._logger.error("Delete %s error, input: %s" %
                               (self._flag, p_list))
            raise OrcApiModelFailException

        return True

    def bus_list_search(self, p_cond):
        """
        查询 list
        :param p_cond:
        :return:
        """
        try:
            result = self._model.usr_search(p_cond)
        except Exception:
            self._logger.error("Search %s error, input: %s" %
                               (self._flag, p_cond))
            raise OrcApiModelFailException

        return result

    def bus_update(self, p_id, p_cond):
        """
        更新一条
        :param p_id:
        :param p_cond:
        :return:
        """
        cond = dict(id=p_id)
        cond.update(p_cond)

        try:
            self._model.usr_update(cond)
        except Exception:
            self._logger.error("Update %s error, input: %s" %
                               (self._flag, p_cond))
            raise OrcApiModelFailException

        return True

    def bus_delete(self, p_id):
        """
        删除一条
        :param p_id:
        :return:
        """
        try:
            self._model.usr_delete(p_id)
        except Exception:
            self._logger.error("Delete %s error, input: %s" %
                               (self._flag, p_id))
            raise OrcApiModelFailException

        return True

    def bus_search(self, p_id):
        """
        查询一条
        :param p_id:
        :return:
        """
        try:
            result = self._model.usr_search(dict(id=p_id))
            result = None if not result else result[0]
        except Exception:
            self._logger.error("Search %s error, input: %s" %
                               (self._flag, p_id))
            raise OrcApiModelFailException

        return result
예제 #13
0
class BatchDetBus(object):
    def __init__(self):

        object.__init__(self)

        self.__logger = OrcLog("api.batch.bus.batch_def")
        self.__model_batch_det = BatchDetMod()
        self.__bus_case_def = CaseDefBus()

    def bus_list_add(self, p_cond):
        """
        新增
        :param p_cond:
        :return:
        """
        try:
            result = self.__model_batch_det.usr_add(p_cond)
        except Exception:
            self.__logger.error("Add case to batch error, input: %s" % p_cond)
            raise OrcApiModelFailException

        return result

    def bus_list_delete(self, p_cond):
        """
        删除 list
        :param p_cond:
        :return:
        """
        try:
            for _id in p_cond:
                self.__model_batch_det.usr_delete(_id)
        except Exception:
            self.__logger.error("Del case from batch error, input: %s" %
                                p_cond)
            raise OrcApiModelFailException

        return True

    def bus_list_search(self, p_cond):
        """
        查询 list
        :param p_cond:
        :return:
        """
        try:
            result = self.__model_batch_det.usr_search(p_cond)
        except Exception:
            self.__logger.error("Search batch's case error, input: %s" %
                                p_cond)
            raise OrcApiModelFailException

        return result

    def bus_update(self, p_id, p_cond):
        """
        更新一条
        :param p_id:
        :param p_cond:
        :return:
        """
        cond = dict(id=p_id)
        cond.update(p_cond)

        try:
            self.__model_batch_det.usr_update(cond)
        except Exception:
            self.__logger.error("Update case of batch error, input: %s" %
                                p_cond)
            raise OrcApiModelFailException

        return True

    def bus_delete(self, p_id):
        """
        删除一条
        :param p_id:
        :return:
        """
        try:
            self.__model_batch_det.usr_delete(p_id)
        except Exception:
            self.__logger.error("Del case from batch error, input: %s" % p_id)
            raise OrcApiModelFailException

        return True

    def bus_search(self, p_id):
        """
        查询一条
        :param p_id:
        :return:
        """
        try:
            result = self.__model_batch_det.usr_search(dict(id=p_id))
            result = None if not result else result[0]
        except Exception:
            self.__logger.error("Search batch's case error, input: %s" % p_id)
            raise OrcApiModelFailException

        return result
예제 #14
0
class BatchDefBus(object):
    def __init__(self):

        object.__init__(self)

        init_log()

        self.__logger = OrcLog("api.batch.bus.batch_def")

        self.__model_batch_def = BatchDefMod()
        self.__bus_batch_det = BatchDetBus()
        self.__bus_case_def = CaseDefBus()

    def bus_list_add(self, p_cond):
        """
        新增
        :param p_cond:
        :return:
        """
        try:
            result = self.__model_batch_def.usr_add(p_cond)
        except Exception:
            self.__logger.error("Add batch error, input: %s" % p_cond)
            raise OrcApiModelFailException

        return result

    def bus_list_delete(self, p_list):
        """
        删除 list, 调用单个删除函数
        :param p_list:
        :return:
        """
        try:
            for _id in p_list:
                self.bus_delete(_id)
        except Exception:
            self.__logger.error("Delete batch error, input: %s" % p_list)
            raise OrcApiModelFailException

        return True

    def bus_list_search(self, p_cond):
        """
        查询 list
        :param p_cond:
        :return:
        """
        result = []

        mode = p_cond["type"] if "type" in p_cond else None
        batch_id = p_cond["id"] if "id" in p_cond else None

        try:
            # 查询符合条件的整用例树,至根节点
            if "all" == mode:
                result = self.__model_batch_def.usr_search_all(p_cond)

            # 查询节点及子节点
            elif "tree" == mode:
                if batch_id is not None:
                    result = self.__model_batch_def.usr_search_tree(batch_id)

            # 查询节点路径
            elif "path" == mode:
                if batch_id is not None:
                    result = self.__model_batch_def.usr_search_path(batch_id)

            # 其他情况只查询符合条件的数据
            else:
                result = self.__model_batch_def.usr_search(p_cond)
        except Exception:
            self.__logger.error("Search batch error, input: %s" % p_cond)
            raise OrcApiModelFailException

        return result

    def bus_update(self, p_id, p_cond):
        """
        更新一条
        :param p_id:
        :param p_cond:
        :return:
        """
        cond = dict(id=p_id)
        cond.update(p_cond)

        try:
            self.__model_batch_def.usr_update(cond)
        except Exception:
            self.__logger.error("Update batch error, input: %s" % p_cond)
            raise OrcApiModelFailException

        return True

    def bus_delete(self, p_id):
        """
        删除一条
        :param p_id:
        :return:
        """
        # 查询 batch 列表, 包含子节点
        batch_list = self.bus_list_search(dict(type="tree", id=p_id))
        batch_id_list = [item.id for item in batch_list]

        # 查询 batch_det 列表
        batch_det_list = []
        for _batch_id in batch_id_list:
            batch_det_list.extend(
                self.__bus_batch_det.bus_list_search(dict(batch_id=_batch_id)))
        batch_det_id_list = [item.id for item in batch_det_list]

        try:
            # 删除 batch_det
            self.__bus_batch_det.bus_list_delete(batch_det_id_list)

            # 删除 batch
            for _id in batch_id_list:
                self.__model_batch_def.usr_delete(_id)

        except Exception:
            self.__logger.error("Delete batch error, input: %s" % p_id)
            raise OrcApiModelFailException

        return True

    def bus_search(self, p_id):
        """
        查询一条
        :param p_id:
        :return:
        """
        try:
            result = self.__model_batch_def.usr_search(dict(id=p_id))
            result = None if not result else result[0]
        except Exception:
            self.__logger.error("Search batch error, input: %s" % p_id)
            raise OrcApiModelFailException

        return result