def test_to_dict(self):
        """Check whether the object is converted into a dict"""

        args = {'from_date': '1970-01-01', 'component': 'test'}
        category = 'commit'
        archive = ArchivingTaskConfig('/tmp/archive',
                                      False,
                                      archived_after=None)
        sched = SchedulingTaskConfig(delay=10,
                                     max_retries=2,
                                     max_age=5,
                                     queue='myqueue')
        before = datetime.datetime.now().timestamp()

        task = Task('mytask',
                    'git',
                    category,
                    args,
                    archiving_cfg=archive,
                    scheduling_cfg=sched)
        task.set_job('job-0', 0)
        task.set_job('job-1', 1)

        d = task.to_dict()

        expected_job_0 = {'job_id': 'job-0', 'job_number': 0}
        expected_job_1 = {'job_id': 'job-1', 'job_number': 1}
        expected = {
            'task_id': 'mytask',
            'status': 'NEW',
            'age': 0,
            'num_failures': 0,
            'jobs': [expected_job_0, expected_job_1],
            'backend': 'git',
            'backend_args': args,
            'category': category,
            'archiving_cfg': {
                'archive_path': '/tmp/archive',
                'archived_after': None,
                'fetch_from_archive': False
            },
            'scheduling_cfg': {
                'delay': 10,
                'max_retries': 2,
                'max_age': 5,
                'queue': 'myqueue'
            }
        }

        created_on = d.pop('created_on')
        self.assertGreater(created_on, before)
        self.assertDictEqual(d, expected)
    def test_set_job(self):
        """Check whether the job is added to the task"""

        args = {'from_date': '1970-01-01', 'component': 'test'}
        category = 'commit'

        task = Task('mytask', 'git', category, args)

        task.set_job('job-0', 0)
        task.set_job('job-1', 1)

        expected_job_0 = JobData('job-0', 0)
        expected_job_1 = JobData('job-1', 1)

        self.assertEqual(len(task.jobs), 2)
        self.assertListEqual(task.jobs, [expected_job_0, expected_job_1])