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

        args = {'from_date': '1970-01-01', 'component': 'test'}
        category = 'mocked_category'
        archive = {
            'archive_path': '/tmp/archive',
            'fetch_from_archive': False,
            'archived_after': None,
        }
        sched = {'stime': 10}
        before = datetime.now().timestamp()

        task = Task('mytask',
                    'mock_backend',
                    category,
                    args,
                    archive_args=archive,
                    sched_args=sched)
        d = task.to_dict()

        expected = {
            'task_id': 'mytask',
            'backend': 'mock_backend',
            'backend_args': args,
            'category': category,
            'archive_args': archive,
            'scheduler_args': sched
        }

        created_on = d.pop('created_on')
        self.assertGreater(created_on, before)
        self.assertDictEqual(d, expected)
Example #2
0
    def test_to_dict(self):
        """Check whether the object is converted into a dict"""

        args = {
            'from_date': '1970-01-01',
            'component': 'test'
        }
        category = 'mocked_category'
        archive = {
            'archive_path': '/tmp/archive',
            'fetch_from_archive': False,
            'archived_after': None,
        }
        sched = {
            'stime': 10
        }
        before = datetime.now().timestamp()

        task = Task('mytask', 'mock_backend', category, args,
                    archive_args=archive, sched_args=sched)
        d = task.to_dict()

        expected = {
            'task_id': 'mytask',
            'backend': 'mock_backend',
            'backend_args': args,
            'category': category,
            'archive_args': archive,
            'scheduler_args': sched
        }

        created_on = d.pop('created_on')
        self.assertGreater(created_on, before)
        self.assertDictEqual(d, expected)
    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)
Example #4
0
    def test_to_dict(self):
        """Check whether the object is converted into a dict"""

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

        task = Task('mytask',
                    'mock_backend',
                    category,
                    args,
                    archiving_cfg=archive,
                    scheduling_cfg=sched)
        task.jobs.append('job-0')
        task.jobs.append('job-1')

        d = task.to_dict()

        expected = {
            'task_id': 'mytask',
            'status': 'NEW',
            'age': 0,
            'jobs': ['job-0', 'job-1'],
            'backend': 'mock_backend',
            '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
            }
        }

        created_on = d.pop('created_on')
        self.assertGreater(created_on, before)
        self.assertDictEqual(d, expected)