def test_state_change_event(self): model = Job() self.assertIsNone(model.time_started) self.assertIsNone(model.attempts) model.state = WorkState.RUNNING self.assertIsInstance(model.time_started, datetime) self.assertEqual(model.attempts, 1)
def test_insert(self): # A job can not be created without a jobtype, create one first jobtype = JobType() jobtype.name = "foo" jobtype.description = "this is a job type" jobtype.classname = "Foobar" jobtype.code = dedent(""" class Foobar(JobType): pass""").encode("utf-8") jobtype.mode = JobTypeLoadMode.OPEN db.session.add(jobtype) job = Job() job.job_type = jobtype software = Software() software.jobs = [job] software.software = "foo" db.session.add_all([job, software]) db.session.commit() job_id = job.id software_id = software.id db.session.remove() software = Software.query.filter_by(id=software_id).first() self.assertEqual(software.jobs[0].id, job_id) self.assertEqual(software.software, "foo") self.assertEqual(software.version, "any")
def test_insert(self): # A job can not be created without a jobtype, create one first jobtype = JobType() jobtype.name = "foo" jobtype.description = "this is a job type" jobtype.classname = "Foobar" jobtype.code = dedent(""" class Foobar(JobType): pass""").encode("utf-8") jobtype.mode = JobTypeLoadMode.OPEN db.session.add(jobtype) job = Job() job.job_type = jobtype tag = Tag() tag.jobs = [job] tag.tag = "foo456" db.session.add_all([tag, job]) db.session.commit() model_id = tag.id job_id = job.id db.session.remove() result = Tag.query.filter_by(id=model_id).first() self.assertEqual(result.tag, "foo456") self.assertEqual(result.jobs[0].id, job_id)
def test_insert(self): jobtype = JobType() jobtype.name = "foo" jobtype.description = "this is a job type" jobtype_version = JobTypeVersion() jobtype_version.jobtype = jobtype jobtype_version.version = 1 jobtype_version.classname = "Foobar" jobtype_version.code = (""" class Foobar(JobType): pass""").encode("utf-8") db.session.add(jobtype_version) job = Job() job.title = "Test Job" job.jobtype_version = jobtype_version task = Task(state=WorkState.DONE, priority=404, frame=1, last_error="foobar", job=job) db.session.add(task) db.session.commit() task_id = task.id db.session.remove() searched = Task.query.filter_by(id=task_id).first() self.assertIsNotNone(searched) self.assertEqual(searched.state, WorkState.DONE) self.assertEqual(searched.priority, 404) self.assertEqual(searched.attempts, 0) self.assertEqual(searched.frame, 1)
def test_insert(self): # A job can not be created without a jobtype, create one first jobtype = JobType() jobtype.name = "foo" jobtype.description = "this is a job type" jobtype_version = JobTypeVersion() jobtype_version.jobtype = jobtype jobtype_version.version = 1 jobtype_version.classname = "Foobar" jobtype_version.code = (""" class Foobar(JobType): pass""").encode("utf-8") db.session.add(jobtype_version) queue = JobQueue() queue.name = "FooQueue" job = Job() job.title = "Test Job" job.jobtype_version = jobtype_version job.queue = queue tag = Tag() tag.jobs = [job] tag.tag = "foo456" db.session.add_all([tag, job]) db.session.commit() model_id = tag.id job_id = job.id db.session.remove() result = Tag.query.filter_by(id=model_id).first() self.assertEqual(result.tag, "foo456") self.assertEqual(result.jobs[0].id, job_id)
def test_unique(self): # A job can not be created without a jobtype, create one first jobtype = JobType() jobtype.name = "foo" jobtype.description = "this is a job type" jobtype.classname = "Foobar" jobtype.code = dedent(""" class Foobar(JobType): pass""").encode("utf-8") db.session.add(jobtype) job = Job() job.job_type = jobtype software = Software() software.software = "foo" requirementA = JobSoftwareRequirement() requirementB = JobSoftwareRequirement() requirementA.job = job requirementA.software = software requirementB.job = job requirementB.software = software db.session.add_all([job, requirementA, requirementB]) with self.assertRaises(DatabaseError): db.session.commit()
def test_insert(self): jobtype = JobType() jobtype.name = "foo" jobtype.description = "this is a job type" jobtype_version = JobTypeVersion() jobtype_version.jobtype = jobtype jobtype_version.version = 1 jobtype_version.classname = "Foobar" jobtype_version.code = (""" class Foobar(JobType): pass""").encode("utf-8") db.session.add(jobtype_version) job = Job() job.title = "Test Job" job.jobtype_version = jobtype_version task = Task( state=WorkState.DONE, priority=404, frame=1, last_error="foobar", job=job) db.session.add(task) db.session.commit() task_id = task.id db.session.remove() searched = Task.query.filter_by(id=task_id).first() self.assertIsNotNone(searched) self.assertEqual(searched.state, WorkState.DONE) self.assertEqual(searched.priority, 404) self.assertEqual(searched.attempts, 0) self.assertEqual(searched.frame, 1)
def test_cpus(self): model = Job() model.cpus = Agent.MIN_CPUS model.cpus = Agent.MAX_CPUS with self.assertRaises(ValueError): model.cpus = Agent.MIN_CPUS - 10 with self.assertRaises(ValueError): model.cpus = Agent.MAX_CPUS + 10
def test_priority(self): model = Job() model.priority = Job.MIN_PRIORITY model.priority = Job.MAX_PRIORITY with self.assertRaises(ValueError): model.priority = Job.MIN_PRIORITY - 10 with self.assertRaises(ValueError): model.priority = Job.MAX_PRIORITY + 10
def test_ram(self): model = Job() model.ram = Agent.MIN_RAM model.ram = Agent.MAX_RAM with self.assertRaises(ValueError): model.ram = Agent.MIN_RAM - 10 with self.assertRaises(ValueError): model.ram = Agent.MAX_RAM + 10
def test_unique(self): job = Job() tagA = Tag() tagB = Tag() tagA.jobs = [job] tagA.tag = "foo0" tagB.jobs = [job] tagB.tag = "foo1" db.session.add_all([job, tagA, tagB]) with self.assertRaises(DatabaseError): db.session.commit()
def test_unique(self): job = Job() softwareA = Software() softwareB = Software() softwareA.jobs = [job] softwareA.software = "foo" softwareB.jobs = [job] softwareB.software = "foo" db.session.add_all([job, softwareA, softwareB]) with self.assertRaises(DatabaseError): db.session.commit()
def create_queue_with_job(self, name, jobtype_version): queue = JobQueue(name=name) job = Job(title="Test Job %s" % name, jobtype_version=jobtype_version, queue=queue) for i in range(0, 100): task = Task(job=job, frame=i) db.session.add(task) db.session.add(job) db.session.flush() return queue
def test_insert(self): # A job can not be created without a jobtype, create one first jobtype = JobType() jobtype.name = "foo" jobtype.description = "this is a job type" jobtype_version = JobTypeVersion() jobtype_version.jobtype = jobtype jobtype_version.version = 1 jobtype_version.classname = "Foobar" jobtype_version.code = (""" class Foobar(JobType): pass""").encode("utf-8") db.session.add(jobtype_version) queue = JobQueue() queue.name = "FooQueue" job = Job() job.title = "Test Job" job.jobtype_version = jobtype_version job.queue = queue # Software requirement needs a software first software = Software() software.software = "foo" requirement = JobSoftwareRequirement() requirement.job = job requirement.software = software db.session.add(job) db.session.commit() job_id = job.id requirement_id = requirement.id requirement2 = JobSoftwareRequirement.query.\ filter_by(id=requirement_id).first() self.assertEqual(requirement.job.id, job_id) self.assertEqual(requirement2.software.software, "foo") self.assertEqual(requirement2.min_version, None) self.assertEqual(requirement2.max_version, None)
def test_clear_last_error(self): jobtype = JobType() jobtype.name = "foo" jobtype.description = "this is a job type" jobtype_version = JobTypeVersion() jobtype_version.jobtype = jobtype jobtype_version.version = 1 jobtype_version.classname = "Foobar" jobtype_version.code = (""" class Foobar(JobType): pass""").encode("utf-8") db.session.add(jobtype_version) job = Job() job.title = "Test Job" job.jobtype_version = jobtype_version task = Task(frame=1, job=job, last_error="foobar") db.session.add(task) db.session.commit() db.session.add(task) task.state = WorkState.DONE self.assertIsNone(task.last_error)