def handler(self, bot, update, *args, **kwargs): self.validate_context(kwargs["args"]) auth_data = kwargs.get('auth_data') cmd_name = " ".join(kwargs["args"]) if not cmd_name.startswith("/"): cmd_name = "/" + cmd_name # get user timezone from JIRA tz = self.app.jira.get_jira_tz(**kwargs) # parse command and options m = re.match(command_re, cmd_name) if not m: raise ScheduleValidationError("Entered value is not correct") data = m.groupdict(None) command, context = command_parser(data.get("callback"), self.app, auth_data) interval = cron_parser(data.get("type"), data.get("opt") or "") # create schedule command ScheduleTask.create(update, cmd_name, tz, interval, command, context) self.app.send(bot, update, text="Schedule command was created successfully!")
def test_default_daily(self): cron = cron_parser('daily', '') assert cron == DAILY_DEFAULT
def test_default_monthly(self): cron = cron_parser('monthly', '') assert cron == MONTHLY_DEFAULT
def test_default_weekly(self): cron = cron_parser('weekly', '') assert cron == WEEKLY_DEFAULT
def test_parser_daily_failed(self, opt): with pytest.raises(ScheduleValidationError): cron_parser("daily", opt)
def test_parser_daily_success(self, opt): cron = cron_parser("daily", opt) hour, minute = cron_parser.match_time(opt) expected_cron = f"{minute} {hour} * * *" assert cron == expected_cron
def test_parser_monthly_failed(self, day): opt = f"{day} 12:30" with pytest.raises(ScheduleValidationError): cron_parser("monthly", opt)
def test_parser_monthly_success(self, day): opt = f"{day} 12:30" cron = cron_parser("monthly", opt) expected_cron = f"30 12 {day} * *" assert cron == expected_cron
def test_parser_weekly_failed(self, day_name): day_name = day_name + "test" opt = f"{day_name} 12:30" with pytest.raises(ScheduleValidationError): cron_parser("weekly", opt)
def test_parser_weekly_success(self, day_name): day_name, day = day_name, WEEKDAYS[day_name] opt = f"{day_name} 12:30" cron = cron_parser("weekly", opt) expected_cron = f"30 12 * * {day}" assert cron == expected_cron
def test_parser_incorect_options(self): with pytest.raises(ScheduleValidationError): cron_parser(TYPES[0], "test_options")
def test_parser_method_exception(self): with pytest.raises(AttributeError): cron_parser("not_implemented", "test_options")
def test_parser_method(self, name): with pytest.raises(ScheduleValidationError): cron_parser(name, "test_options")