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)