class TriggerTest(unittest.TestCase): def setUp(self): self.interval = IntervalTrigger() self.cron = CronTrigger() self.date = DateTrigger(run_date=datetime.now()) def test_scheduler_kwargs_interval(self): expected = { "weeks": 0, "days": 0, "hours": 0, "minutes": 0, "seconds": 0, "start_date": None, "end_date": None, "timezone": pytz.utc, "jitter": None, "reschedule_on_finish": False, } self.assertEqual(self.interval.get_scheduler_kwargs(), expected) self.interval.start_date = datetime.now() start_date = self.interval.get_scheduler_kwargs()["start_date"] self.assertEqual(start_date.tzinfo, pytz.utc) def test_scheduler_kwargs_cron(self): expected = { "year": "*", "month": "1", "day": "1", "week": "*", "day_of_week": "*", "hour": "0", "minute": "0", "second": "0", "start_date": None, "end_date": None, "timezone": pytz.utc, "jitter": None, } self.assertEqual(self.cron.get_scheduler_kwargs(), expected) self.cron.start_date = datetime.now() start_date = self.cron.get_scheduler_kwargs()["start_date"] self.assertEqual(start_date.tzinfo, pytz.utc) def test_scheduler_kwargs_date(self): expected = { "run_date": pytz.utc.localize(self.date.run_date), "timezone": pytz.utc, } self.assertEqual(self.date.get_scheduler_kwargs(), expected) self.date.run_date = datetime.now() start_date = self.date.get_scheduler_kwargs()["run_date"] self.assertEqual(start_date.tzinfo, pytz.utc)
def setUp(self): self.request_mock = Mock() self.ts_epoch = 1451606400000 self.ts_dt = datetime.datetime(2016, 1, 1) self.request_dict = { "children": [], "parent": None, "system": "system_name", "system_version": "0.0.1", "instance_name": "default", "command": "say", "id": "58542eb571afd47ead90d25f", "parameters": {}, "comment": "bye!", "output": "nested output", "output_type": "STRING", "status": "IN_PROGRESS", "command_type": "ACTION", "created_at": self.ts_epoch, "updated_at": self.ts_epoch, "error_class": None, "metadata": {}, "has_parent": True, "requester": None, } self.job_dict = { "name": "job_name", "trigger_type": "date", "trigger": {"run_date": self.ts_epoch, "timezone": "utc"}, "request_template": { "system": "system", "system_version": "1.0.0", "instance_name": "default", "command": "speak", "parameters": {"message": "hey!"}, "comment": "hi!", "metadata": {"request": "stuff"}, }, "misfire_grace_time": 3, "coalesce": True, "next_run_time": self.ts_epoch, "success_count": 0, "error_count": 0, } db_dict = copy.deepcopy(self.job_dict) db_dict["request_template"] = RequestTemplate(**db_dict["request_template"]) db_dict["trigger"]["run_date"] = self.ts_dt db_dict["trigger"] = DateTrigger(**db_dict["trigger"]) db_dict["next_run_time"] = self.ts_dt self.job = Job(**db_dict) db_dict = copy.deepcopy(self.request_dict) db_dict["created_at"] = self.ts_dt db_dict["updated_at"] = self.ts_dt self.request = Request(**db_dict) super(RequestAPITest, self).setUp()
def setUp(self): self.ts_epoch = 1451606400000 self.ts_dt = datetime(2016, 1, 1) self.job_dict = { "name": "job_name", "trigger_type": "date", "trigger": { "run_date": self.ts_epoch, "timezone": "utc" }, "request_template": { "system": "system", "system_version": "1.0.0", "instance_name": "default", "command": "speak", "parameters": { "message": "hey!" }, "comment": "hi!", "metadata": { "request": "stuff" }, }, "misfire_grace_time": 3, "coalesce": True, "next_run_time": self.ts_epoch, "success_count": 0, "error_count": 0, "status": "RUNNING", "max_instances": 3, } db_dict = copy.deepcopy(self.job_dict) db_dict["request_template"] = RequestTemplate( **db_dict["request_template"]) db_dict["trigger"]["run_date"] = self.ts_dt db_dict["trigger"] = DateTrigger(**db_dict["trigger"]) db_dict["next_run_time"] = self.ts_dt self.job = Job(**db_dict) super(JobListAPITest, self).setUp()
def bg_trigger(trigger_dict, ts_dt): """A beer-garden trigger object.""" dict_copy = copy.deepcopy(trigger_dict) dict_copy["run_date"] = ts_dt return DateTrigger(**dict_copy)
def setUp(self): self.interval = IntervalTrigger() self.cron = CronTrigger() self.date = DateTrigger(run_date=datetime.now())
def test_trigger_mismatch(self): date_trigger = DateTrigger() job = Job(trigger_type="cron", trigger=date_trigger) with self.assertRaises(ModelValidationError): job.clean()