コード例 #1
0
ファイル: test_tasks.py プロジェクト: acs/arthur
    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)
コード例 #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)
コード例 #3
0
    def test_init(self):
        """Check arguments initialization"""

        args = {'from_date': '1970-01-01', 'component': 'test'}
        before = datetime.now().timestamp()

        task = Task('mytask', 'mock_backend', args)

        self.assertEqual(task.task_id, 'mytask')
        self.assertEqual(task.backend, 'mock_backend')
        self.assertDictEqual(task.backend_args, args)
        self.assertDictEqual(task.cache_args, {})
        self.assertDictEqual(task.sched_args, {})
        self.assertGreater(task.created_on, before)

        # Test when cache and scheduler arguments are given
        cache = {'cache_path': '/tmp/cache', 'fetch': True}
        sched = {'stime': 10}
        before = datetime.now().timestamp()

        task = Task('mytask',
                    'mock_backend',
                    args,
                    cache_args=cache,
                    sched_args=sched)

        self.assertEqual(task.task_id, 'mytask')
        self.assertEqual(task.backend, 'mock_backend')
        self.assertDictEqual(task.backend_args, args)
        self.assertDictEqual(task.cache_args, cache)
        self.assertDictEqual(task.sched_args, sched)
        self.assertGreater(task.created_on, before)
コード例 #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 = '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)
コード例 #5
0
    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])
コード例 #6
0
    def test_init(self, mock_utcnow):
        """Check arguments initialization"""

        mock_utcnow.return_value = datetime.datetime(
            2017, 1, 1, tzinfo=dateutil.tz.tzutc())

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

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

        self.assertEqual(task.task_id, 'mytask')
        self.assertEqual(task.status, TaskStatus.NEW)
        self.assertEqual(task.age, 0)
        self.assertListEqual(task.jobs, [])
        self.assertEqual(task.backend, 'git')
        self.assertEqual(task.category, 'commit')
        self.assertDictEqual(task.backend_args, args)
        self.assertEqual(task.archiving_cfg, None)
        self.assertEqual(task.scheduling_cfg, None)
        self.assertEqual(task.created_on, 1483228800.0)

        # Test when archive and scheduler arguments are given
        archive = ArchivingTaskConfig('/tmp/archive',
                                      False,
                                      archived_after=None)
        sched = SchedulingTaskConfig(delay=10, max_retries=2, max_age=5)

        task = Task('mytask',
                    'git',
                    'commit',
                    args,
                    archiving_cfg=archive,
                    scheduling_cfg=sched)

        self.assertEqual(task.task_id, 'mytask')
        self.assertEqual(task.status, TaskStatus.NEW)
        self.assertEqual(task.age, 0)
        self.assertListEqual(task.jobs, [])
        self.assertEqual(task.backend, 'git')
        self.assertEqual(task.category, 'commit')
        self.assertDictEqual(task.backend_args, args)
        self.assertEqual(task.archiving_cfg, archive)
        self.assertEqual(task.scheduling_cfg, sched)
        self.assertEqual(task.created_on, 1483228800.0)
コード例 #7
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)
コード例 #8
0
    def test_init(self):
        """Check arguments initialization"""

        args = {'from_date': '1970-01-01', 'component': 'test'}
        before = datetime.now().timestamp()

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

        self.assertEqual(task.task_id, 'mytask')
        self.assertEqual(task.backend, 'mock_backend')
        self.assertEqual(task.category, 'category')
        self.assertDictEqual(task.backend_args, args)
        self.assertDictEqual(task.archive_args, {})
        self.assertDictEqual(task.sched_args, {})
        self.assertGreater(task.created_on, before)

        # Test when archive and scheduler arguments are given
        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)

        self.assertEqual(task.task_id, 'mytask')
        self.assertEqual(task.backend, 'mock_backend')
        self.assertEqual(task.category, 'category')
        self.assertDictEqual(task.backend_args, args)
        self.assertDictEqual(task.archive_args, archive)
        self.assertDictEqual(task.sched_args, sched)
        self.assertGreater(task.created_on, before)
コード例 #9
0
    def test_init(self):
        """Check arguments initialization"""

        args = {'from_date': '1970-01-01', 'component': 'test'}
        before = datetime.datetime.now().timestamp()

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

        self.assertEqual(task.task_id, 'mytask')
        self.assertEqual(task.backend, 'mock_backend')
        self.assertEqual(task.category, 'category')
        self.assertDictEqual(task.backend_args, args)
        self.assertEqual(task.archiving_cfg, None)
        self.assertEqual(task.scheduling_cfg, None)
        self.assertGreater(task.created_on, before)

        # Test when archive and scheduler arguments are given
        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)

        self.assertEqual(task.task_id, 'mytask')
        self.assertEqual(task.backend, 'mock_backend')
        self.assertEqual(task.category, 'category')
        self.assertDictEqual(task.backend_args, args)
        self.assertEqual(task.archiving_cfg, archive)
        self.assertEqual(task.scheduling_cfg, sched)
        self.assertGreater(task.created_on, before)
コード例 #10
0
    def test_backend_not_found(self):
        """Test if it raises an exception when a backend is not found"""

        archive = ArchivingTaskConfig('/tmp/archive',
                                      False,
                                      archived_after=None)
        sched = SchedulingTaskConfig(delay=10, max_retries=2, max_age=5)

        with self.assertRaises(NotFoundError) as e:
            _ = Task('mytask',
                     'mock_backend',
                     'mock_item', {},
                     archiving_cfg=archive,
                     scheduling_cfg=sched)
            self.assertEqual(e.exception.element, 'mock_backend')
コード例 #11
0
    def test_has_resuming(self):
        """Test if a task property returns it might be resumed or not"""

        task = Task('git_task',
                    'git',
                    'commit', {},
                    archiving_cfg=None,
                    scheduling_cfg=None)
        self.assertEqual(task.has_resuming(), True)

        task = Task('gerrit_task',
                    'gerrit',
                    'review', {},
                    archiving_cfg=None,
                    scheduling_cfg=None)
        self.assertEqual(task.has_resuming(), False)