def set_job_start_state(self, job: Job): """ Fill the properties necessary when the job starts. """ job.start_datetime = datetime.datetime.now().isoformat() job.status = JobStatus.PROCESSING self.job_repository.update_job(job)
def test_init_with_invalid_parameters(self): with self.assertRaises(ValueError): Job('module1', 'class2', 123) with self.assertRaises(ValueError): Job('module1', 'class2', 'text') with self.assertRaises(ValueError): Job('module1', 'class2', range(10))
def test_set_job_error(self): job_activity = FakeJobActivity() job = Job('some_module', 'some_class') job_activity.set_job(job) self.assertIsNone(job_activity._job.error) job_activity.set_job_error(Exception('some exception message')) self.assertEqual(job_activity._job.error, 'some exception message')
def test_set_job_status(self): job_activity = FakeJobActivity() job = Job('some_module', 'some_class') job_activity.set_job(job) self.assertEqual(job_activity._job.status, JobStatus.ENQUEUED) job_activity.set_job_status(JobStatus.PROCESSING) self.assertEqual(job_activity._job.status, JobStatus.PROCESSING)
def test_get_job_activity_instance(self): server_service = ServerService(None, None, None) fake_job_activity = FakeJobActivity() job = Job(fake_job_activity.__module__, fake_job_activity.__class__.__name__) job_instance = server_service.get_job_activity_instance(job) self.assertIsInstance(job_instance, FakeJobActivity) self.assertEqual(job_instance.set_job.call_count, 1)
def test_set_job_end_datetime(self): job_activity = FakeJobActivity() job = Job('some_module', 'some_class') job_activity.set_job(job) self.assertIsNone(job_activity._job.end_datetime) job_activity.set_job_end_datetime() self.assertEqual(job_activity._job.end_datetime, '1988-04-10T11:01:02.123456')
def test_init_with_parameters(self): job = Job('module1', 'class2', ['param3', 'param4']) self.assertEqual(job.module_name, 'module1') self.assertEqual(job.class_name, 'class2') self.assertEqual(job.status, JobStatus.ENQUEUED) self.assertEqual(job.enqueued_datetime, '1988-04-10T11:01:02.123456') self.assertIsNone(job.start_datetime) self.assertIsNone(job.end_datetime) self.assertListEqual(job.parameters, ['param3', 'param4'])
def create_job_object(self, parameters: list[str] = None) -> Job: """ Returns an instance of the entity that represents the job on the repository, based on the activity that inherits from this base class. Args: parameters (list[str]) Returns: Job """ module_name = self.__module__ class_name = self.__class__.__name__ job = Job(module_name, class_name) if (parameters is not None): job.parameters.extend(parameters) return job
def test_init_with_invalid_class_name(self): with self.assertRaises(ValueError): Job('module1', '') with self.assertRaises(ValueError): Job('module1', 123)
def test_init_with_invalid_module_name(self): with self.assertRaises(ValueError): Job('', 'class2') with self.assertRaises(ValueError): Job(123, 'class2')
def get_fake_job() -> Job: return Job('module_test', 'class_test')
def test_get_job(self): job_activity = FakeJobActivity() job = Job('some_module', 'some_class') job_activity._job = job actual_job = job_activity.get_job() self.assertEqual(actual_job, job)
def test_set_job(self): job_activity = FakeJobActivity() job = Job('some_module', 'some_class') job_activity.set_job(job) self.assertEqual(job_activity._job, job)