def test_is_assembly_in_backlog_should_not_find_assembly_version(self): study = mgnify.create_study_obj(study_data) status = AssemblyJobStatus(description='pending') status.save() run = mgnify.create_run_obj(study, run_data) mgnify.create_assembly_job(run, '0', status, 'metaspades', '3.12.0') assert mgnify.is_assembly_job_in_backlog(run_data['run_accession'], 'metaspades', '3.11.1') is None
def test_get_pending_assembly_jobs_should_return_all_pending_jobs(self): status = AssemblyJobStatus(description='pending') status.save() assembler = Assembler(name='metaspades', version='3.12.0') assembler.save() assert len(AssemblyJob.objects.all()) == 0 AssemblyJob(directory='/dir', status=status, priority=0, assembler=assembler, input_size=3).save() AssemblyJob(directory='/dir', status=status, priority=1, assembler=assembler, input_size=4).save() assert len(mgnify.get_pending_assembly_jobs()) == 2
def test_filter_active_runs_should_return_empty_list(self): assert len(AssemblyJob.objects.all()) == 0 study = mgnify.create_study_obj(study_data) run = mgnify.create_run_obj(study, run_data) status = AssemblyJobStatus(description='pending') status.save() mgnify.create_assembly_job(run, '0', status, 'metaspades', '3.12.0') assert len(AssemblyJob.objects.all()) == 1 assert len(mgnify.filter_active_runs([run_data], 'metaspades')) == 0
def test_create_assembly_job_should_set_status_from_model(self): study = mgnify.create_study_obj(study_data) run = mgnify.create_run_obj(study, run_data) _ = Assembler(name='metaspades', version='3.11.1').save() status = AssemblyJobStatus(description='PENDING') status.save() mgnify.create_assembly_job(run, 0, status, 'metaspades') assembly_jobs = AssemblyJob.objects.all() assert len(assembly_jobs) == 1 assembly_job = assembly_jobs[0] assert assembly_job.status.description == status.description
def test_save_assembly_job_should_update_job(self): study = mgnify.create_study_obj(study_data) run = mgnify.create_run_obj(study, run_data) assembler = Assembler(name='metaspades', version='3.12.0') assembler.save() status = AssemblyJobStatus(description='pending') status.save() status2 = AssemblyJobStatus(description='running') status2.save() assert len(AssemblyJob.objects.all()) == 0 assembly_job = AssemblyJob(input_size=0, assembler=assembler, status=status, priority=0) assembly_job.save() RunAssemblyJob(run=run, assembly_job=assembly_job).save() new_priority = 1 mgnify.save_assembly_job(run, 0, assembler.name, assembler.version, status2, new_priority) assert len(RunAssemblyJob.objects.all()) == 1 assembly_jobs = AssemblyJob.objects.all() assert len(assembly_jobs) == 1 updated_assembly_job = assembly_jobs[0] assert updated_assembly_job.pk == assembly_job.pk assert updated_assembly_job.status.pk == status2.pk assert updated_assembly_job.priority == new_priority
def test_save_assembly_job_should_create_new_job(self): study = mgnify.create_study_obj(study_data) run = mgnify.create_run_obj(study, run_data) status = AssemblyJobStatus(description='pending') status.save() job = mgnify.save_assembly_job(run, 1, 'metaspades', '3.12.0', status, 3) jobs = AssemblyJob.objects.all() assert len(jobs) == 1 inserted_job = jobs[0] assert inserted_job.pk == job.pk assert inserted_job.input_size == 1 assert inserted_job.assembler.name == 'metaspades' assert inserted_job.assembler.version == '3.12.0' assert inserted_job.status.pk == status.pk assert inserted_job.priority == 3
def test_get_pending_assembly_jobs_should_order_jobs_by_decreasing_priority(self): status = AssemblyJobStatus(description='pending') status.save() assembler = Assembler(name='metaspades', version='3.12.0') assembler.save() assert len(AssemblyJob.objects.all()) == 0 job1 = AssemblyJob(directory='/dir', status=status, priority=3, assembler=assembler, input_size=3) job1.save() job2 = AssemblyJob(directory='/dir', status=status, priority=1, assembler=assembler, input_size=4) job2.save() pending_jobs = mgnify.get_pending_assembly_jobs() assert len(pending_jobs) == 2 assert pending_jobs[0].pk == job1.pk assert pending_jobs[1].pk == job2.pk
def test_set_assembly_job_running_should_update_existing_assembly_job(self): study = mgnify.create_study_obj(study_data) run = mgnify.create_run_obj(study, run_data) status = AssemblyJobStatus(description='pending') status.save() AssemblyJobStatus(description='running').save() assembler_name = 'metaspades' assembler_version = '3.11.1' inserted_assembly_job = mgnify.create_assembly_job(run, '0', status, assembler_name, assembler_version) assert len(AssemblyJob.objects.all()) == 1 mgnify.set_assembly_job_running(run_data['run_accession'], assembler_name, assembler_version) assembly_jobs = AssemblyJob.objects.all() assert len(assembly_jobs) == 1 assert len(Run.objects.all()) == 1 assert len(Study.objects.all()) == 1 assembly_job = assembly_jobs[0] assert assembly_job.pk == inserted_assembly_job.pk assert assembly_job.status.description == 'running'