def check_ctx(self, ctx, job, interval_in_seconds, max_repeats, idx, cb_kwargs, len_runs_ctx, job_type=SCHEDULER.JOB_TYPE.INTERVAL_BASED): self.assertEquals(ctx['name'], job.name) self.assertEquals(ctx['max_repeats'], job.max_repeats) self.assertDictEqual(ctx['cb_kwargs'], job.cb_kwargs) if job_type == SCHEDULER.JOB_TYPE.INTERVAL_BASED: self.assertEquals(ctx['interval_in_seconds'], interval_in_seconds) else: self.assertEquals(ctx['cron_definition'], DEFAULT_CRON_DEFINITION) self.assertEquals(ctx['max_repeats'], max_repeats) self.assertEquals(ctx['current_run'], idx) self.assertDictEqual(ctx['cb_kwargs'], cb_kwargs) func = self.assertFalse if idx < len_runs_ctx else self.assertTrue func(ctx['max_repeats_reached']) # Don't check an exact time. Simply parse it out and confirm it's in the past. start_time = parse_datetime(ctx['start_time']) now = datetime.utcnow() self.assertTrue(start_time < now, 'start_time:`{}` is not less than now:`{}`'.format(start_time, now)) self.assertTrue(is_like_cid(ctx['cid']))
def check_ctx(self, ctx, job, interval_in_seconds, max_repeats, idx, cb_kwargs, len_runs_ctx, job_type=SCHEDULER.JOB_TYPE.INTERVAL_BASED): self.assertEquals(ctx['name'], job.name) self.assertEquals(ctx['max_repeats'], job.max_repeats) self.assertDictEqual(ctx['cb_kwargs'], job.cb_kwargs) if job_type == SCHEDULER.JOB_TYPE.INTERVAL_BASED: self.assertEquals(ctx['interval_in_seconds'], interval_in_seconds) else: self.assertEquals(ctx['cron_definition'], DEFAULT_CRON_DEFINITION) self.assertEquals(ctx['max_repeats'], max_repeats) self.assertEquals(ctx['current_run'], idx) self.assertDictEqual(ctx['cb_kwargs'], cb_kwargs) func = self.assertFalse if idx < len_runs_ctx else self.assertTrue func(ctx['max_repeats_reached']) # Don't check an exact time. Simply parse it out and confirm it's in the past. start_time = parse(ctx['start_time']) now = datetime.utcnow() self.assertTrue(start_time < now, 'start_time:`{}` is not less than now:`{}`'.format(start_time, now)) self.assertTrue(is_like_cid(ctx['cid']))
def test_get_context(self): id = rand_int() name = rand_string() start_time = rand_date_utc() interval_in_seconds = rand_int() max_repeats_reached = rand_bool() current_run, max_repeats = rand_int(count=2) cb_kwargs = {rand_string(): rand_string()} for job_type in SCHEDULER.JOB_TYPE.INTERVAL_BASED, SCHEDULER.JOB_TYPE.CRON_STYLE: interval=Interval(in_seconds=interval_in_seconds) if \ job_type == SCHEDULER.JOB_TYPE.INTERVAL_BASED else CronTab(DEFAULT_CRON_DEFINITION) job = Job(id, name, job_type, cb_kwargs=cb_kwargs, interval=interval) job.start_time = start_time job.current_run = current_run job.max_repeats = max_repeats job.max_repeats_reached = max_repeats_reached if job_type == SCHEDULER.JOB_TYPE.CRON_STYLE: job.cron_definition = DEFAULT_CRON_DEFINITION ctx = job.get_context() cid = ctx.pop('cid') self.assertTrue(is_like_cid(cid)) expected = { 'current_run': current_run, 'id': id, 'name': name, 'start_time': start_time.isoformat(), 'max_repeats': max_repeats, 'max_repeats_reached': max_repeats_reached, 'cb_kwargs': cb_kwargs, 'type': job_type, } if job_type == SCHEDULER.JOB_TYPE.CRON_STYLE: expected['cron_definition'] = job.cron_definition else: expected['interval_in_seconds'] = job.interval.in_seconds self.assertDictEqual(ctx, expected)
def test_get_context(self): id = rand_int() name = rand_string() start_time = rand_date_utc() interval_in_seconds = rand_int() max_repeats_reached = rand_bool() current_run, max_repeats = rand_int(count=2) cb_kwargs = {rand_string():rand_string()} for job_type in SCHEDULER.JOB_TYPE.INTERVAL_BASED, SCHEDULER.JOB_TYPE.CRON_STYLE: interval=Interval(in_seconds=interval_in_seconds) if \ job_type == SCHEDULER.JOB_TYPE.INTERVAL_BASED else CronTab(DEFAULT_CRON_DEFINITION) job = Job(id, name, job_type, cb_kwargs=cb_kwargs, interval=interval) job.start_time = start_time job.current_run = current_run job.max_repeats = max_repeats job.max_repeats_reached = max_repeats_reached if job_type == SCHEDULER.JOB_TYPE.CRON_STYLE: job.cron_definition = DEFAULT_CRON_DEFINITION ctx = job.get_context() cid = ctx.pop('cid') self.assertTrue(is_like_cid(cid)) expected = { 'current_run': current_run, 'id': id, 'name': name, 'start_time': start_time.isoformat(), 'max_repeats': max_repeats, 'max_repeats_reached': max_repeats_reached, 'cb_kwargs': cb_kwargs, 'type': job_type, } if job_type == SCHEDULER.JOB_TYPE.CRON_STYLE: expected['cron_definition'] = job.cron_definition else: expected['interval_in_seconds'] = job.interval.in_seconds self.assertDictEqual(ctx, expected)