Exemplo n.º 1
0
    def __init__(self, test_case_suite_id_list, test_domain, trigger_type, is_execute_forbiddened_case=False,
                 test_case_id_list=None, alarm_mail_list=None, is_ding_ding_notify=False, ding_ding_access_token=None,
                 ding_ding_notify_strategy=None, is_enterprise_wechat_notify=False, enterprise_wechat_access_token=None,
                 enterprise_wechat_notify_strategy=None, is_web_hook=False, **trigger_args):

        if test_case_id_list is None:
            test_case_id_list = []

        if isinstance(test_case_suite_id_list, list) and isinstance(test_case_id_list, list):
            self.test_case_suite_id_list = list(set(test_case_suite_id_list))
            self.test_case_id_list = list(set(test_case_id_list))
        else:
            raise TypeError('test_case_suite_id_list and test_case_id_list must be list!')

        if isinstance(test_domain, str):
            self.test_domain = test_domain
        else:
            raise TypeError('test_domain must be string!')

        if isinstance(trigger_type, str) and trigger_type in ["interval", "date", "cron"]:
            self.trigger_type = trigger_type
        else:
            raise TypeError('trigger_type is invalid!')

        self.trigger_args = trigger_args
        self.is_execute_forbiddened_case = is_execute_forbiddened_case
        self.status_history = {}

        self.ding_ding_access_token = ding_ding_access_token if is_ding_ding_notify else None
        self.ding_ding_notify_strategy = {'success': True, 'fail': True} \
            if is_ding_ding_notify and ding_ding_notify_strategy is None else ding_ding_notify_strategy

        self.enterprise_wechat_access_token = enterprise_wechat_access_token if enterprise_wechat_access_token else None
        self.enterprise_wechat_notify_strategy = {'success': True, 'fail': True} \
            if is_enterprise_wechat_notify and enterprise_wechat_notify_strategy is None \
            else enterprise_wechat_notify_strategy

        self._id = str(common.get_object_id())
        self.alarm_mail_list = []

        if alarm_mail_list:
            if isinstance(alarm_mail_list, list):
                for alarm_mail in alarm_mail_list:
                    if isinstance(alarm_mail, str) and common.is_valid_email(alarm_mail):
                        self.alarm_mail_list.append(alarm_mail)
                    else:
                        raise TypeError('<%s> is invalid mail!' % alarm_mail)
            else:
                raise TypeError('mail_list must be list')

        self.is_web_hook = is_web_hook

        self.report_id = None  # 告警时发送测试报告生成_id
        self.report_created_time = None  # 告警时发送测试报告生成时间
        self.failed_count = 0  # 用于判断是否邮件发送告警
Exemplo n.º 2
0
    def __init__(self,
                 test_suite_id_list,
                 project_id,
                 test_env_id,
                 trigger_type,
                 include_forbidden=False,
                 alarm_mail_list=None,
                 is_web_hook=False,
                 **trigger_args):

        if not isinstance(test_suite_id_list,
                          list) or len(test_suite_id_list) < 1:
            raise TypeError('test_suite_id_list must be list and not empty!')

        if not test_env_id:
            raise ValueError('test_env_id should not be empty.')

        if not isinstance(trigger_type, str) or trigger_type not in [
                "interval", "date", "cron"
        ]:
            raise TypeError('trigger_type is invalid!')

        # cronJob ID
        self._id = str(common.get_object_id())
        self.test_suite_id_list = test_suite_id_list
        self.project_id = project_id
        self.test_env_id = test_env_id
        self.trigger_type = trigger_type
        self.include_forbidden = include_forbidden
        self.trigger_args = trigger_args
        self.status_history = {}

        self.alarm_mail_list = []
        if alarm_mail_list:
            if isinstance(alarm_mail_list, list):
                for alarm_mail in alarm_mail_list:
                    if isinstance(alarm_mail,
                                  str) and common.is_valid_email(alarm_mail):
                        self.alarm_mail_list.append(alarm_mail)
                    else:
                        raise TypeError('<%s> is invalid mail!' % alarm_mail)
            else:
                raise TypeError('mail_list must be list')

        self.is_web_hook = is_web_hook
        self.execution_mode = 'cronJob'