def test_batch(self): """Tests filtering jobs by batch""" batch_job = batch_test_utils.create_batch_job(job=self.job1) url = rest_util.get_url('/sources/%d/jobs/?batch_id=%d' % (self.src_file.id, batch_job.batch.id)) response = self.client.generic('GET', url) self.assertEqual(response.status_code, status.HTTP_200_OK, response.content) result = json.loads(response.content) self.assertEqual(len(result['results']), 1) self.assertEqual(result['results'][0]['id'], self.job1.id)
def test_update_batch_fields(self): """Tests running the database update to populate new batch fields in job and recipe models""" definition = {"priority": 303} batch_1 = batch_test_utils.create_batch_old(definition=definition) batch_1.recipe_type_rev_id = 1 batch_1.configuration = {} batch_1.save() batch_1.creator_job.status = 'COMPLETED' batch_1.creator_job.save() batch_2 = batch_test_utils.create_batch() recipe_type = recipe_test_utils.create_recipe_type() recipe_1 = recipe_test_utils.create_recipe(recipe_type=recipe_type) recipe_2 = recipe_test_utils.create_recipe(recipe_type=recipe_type) job_1 = job_test_utils.create_job() job_2 = job_test_utils.create_job() batch_test_utils.create_batch_recipe(batch=batch_1, recipe=recipe_1) batch_test_utils.create_batch_recipe(batch=batch_1, recipe=recipe_2) batch_test_utils.create_batch_job(batch=batch_1, job=job_1) batch_test_utils.create_batch_job(batch=batch_1, job=job_2) batch_1.total_count = 2 batch_1.save() recipe_3 = recipe_test_utils.create_recipe() recipe_4 = recipe_test_utils.create_recipe() job_3 = job_test_utils.create_job() job_4 = job_test_utils.create_job() batch_test_utils.create_batch_recipe(batch=batch_2, recipe=recipe_3) batch_test_utils.create_batch_recipe(batch=batch_2, recipe=recipe_4) batch_test_utils.create_batch_job(batch=batch_2, job=job_3) batch_test_utils.create_batch_job(batch=batch_2, job=job_4) # This batch tests an old batch that never created any recipes time_rev_1 = now() time_rev_2 = time_rev_1 + timedelta(minutes=1) time_batch = time_rev_2 + timedelta(minutes=1) time_rev_3 = time_batch + timedelta(minutes=1) recipe_type_3 = recipe_test_utils.create_recipe_type() recipe_test_utils.edit_recipe_type(recipe_type_3, recipe_type_3.definition) recipe_test_utils.edit_recipe_type(recipe_type_3, recipe_type_3.definition) RecipeTypeRevision.objects.filter( recipe_type_id=recipe_type_3.id, revision_num=1).update(created=time_rev_1) RecipeTypeRevision.objects.filter( recipe_type_id=recipe_type_3.id, revision_num=2).update(created=time_rev_2) RecipeTypeRevision.objects.filter( recipe_type_id=recipe_type_3.id, revision_num=3).update(created=time_rev_3) batch_3 = batch_test_utils.create_batch_old(recipe_type=recipe_type_3) batch_3.recipe_type_rev_id = 1 batch_3.created = time_batch batch_3.save() # Run update updater = DatabaseUpdater() updater.update() # Check results batch_1 = Batch.objects.get(id=batch_1.id) self.assertTrue(batch_1.is_creation_done) self.assertEqual(batch_1.recipes_estimated, 2) recipe_type_rev = RecipeTypeRevision.objects.get_revision( recipe_type.id, recipe_type.revision_num) self.assertEqual(batch_1.recipe_type_rev_id, recipe_type_rev.id) self.assertEqual(batch_1.root_batch_id, batch_1.id) self.assertEqual(batch_1.get_configuration().priority, 303) job_1 = Job.objects.get(id=job_1.id) self.assertEqual(job_1.batch_id, batch_1.id) job_2 = Job.objects.get(id=job_2.id) self.assertEqual(job_2.batch_id, batch_1.id) job_3 = Job.objects.get(id=job_3.id) self.assertEqual(job_3.batch_id, batch_2.id) job_4 = Job.objects.get(id=job_4.id) self.assertEqual(job_4.batch_id, batch_2.id) recipe_1 = Recipe.objects.get(id=recipe_1.id) self.assertEqual(recipe_1.batch_id, batch_1.id) recipe_2 = Recipe.objects.get(id=recipe_2.id) self.assertEqual(recipe_2.batch_id, batch_1.id) recipe_3 = Recipe.objects.get(id=recipe_3.id) self.assertEqual(recipe_3.batch_id, batch_2.id) recipe_4 = Recipe.objects.get(id=recipe_4.id) self.assertEqual(recipe_4.batch_id, batch_2.id) batch_3 = Batch.objects.get(id=batch_3.id) recipe_type_rev = RecipeTypeRevision.objects.get_revision( recipe_type_3.id, 2) self.assertEqual(batch_3.recipe_type_rev_id, recipe_type_rev.id) self.assertEqual(batch_3.root_batch_id, batch_3.id)