def test_invalidate_image_collection_removes_images(self): # Collect the image ids removed_ids = [image._id for image in self.image_collections[0].images] kept_ids = [ image._id for image_collection in self.image_collections[1:] for image in image_collection.images ] invalidate.invalidate_image_collections( [self.image_collections[0].identifier]) # Check the expected images are gone self.assertEqual( 0, Image.objects.raw({ '_id': { '$in': removed_ids } }).count()) self.assertEqual(len(kept_ids), Image.objects.raw({ '_id': { '$in': kept_ids } }).count())
def test_invalidate_image_collection_removes_descendant_trials(self): self.assertEqual( len(self.image_collections) * len(self.systems), TrialResult.objects.all().count()) invalidate.invalidate_image_collections( [self.image_collections[0].identifier]) # Check that the total number of tasks has gone down like we expected self.assertEqual((len(self.image_collections) - 1) * len(self.systems), TrialResult.objects.all().count()) # Check explicity that all the descendant trials are removed for trial_result_id in self.trial_results[ self.image_collections[0].identifier]: self.assertEqual( 0, TrialResult.objects.raw({ '_id': trial_result_id }).count()) # Check that the other trials are not removed for i in range(1, len(self.image_collections)): for trial_result_id in self.trial_results[ self.image_collections[i].identifier]: self.assertEqual( 1, TrialResult.objects.raw({ '_id': trial_result_id }).count())
def test_invalidate_image_collection_removes_the_collection(self): self.assertEqual(len(self.image_collections), ImageCollection.objects.all().count()) invalidate.invalidate_image_collections( [self.image_collections[0].identifier]) # Check that the number has gone down self.assertEqual( len(self.image_collections) - 1, ImageCollection.objects.all().count()) # Check that the image collection is removed self.assertEqual( 0, ImageCollection.objects.raw({ '_id': self.image_collections[0].identifier }).count()) # Check that the other collections are still here for i in range(1, len(self.image_collections)): self.assertEqual( 1, ImageCollection.objects.raw({ '_id': self.image_collections[i].identifier }).count())
def test_invalidate_image_collection_removes_tasks(self): self.assertEqual( len(self.image_collections) * (1 + len(self.systems) + len(self.unfinished_systems)), Task.objects.all().count()) invalidate.invalidate_image_collections( [self.image_collections[0].identifier]) # Check that the total number of tasks has gone down like we expected self.assertEqual( (len(self.image_collections) - 1) * (1 + len(self.systems) + len(self.unfinished_systems)), Task.objects.all().count()) # Check explicitly that each of the tasks associated with the invalidated image collection are removed self.assertEqual( 0, Task.objects.raw({ '_id': self.import_dataset_tasks[self.image_collections[0].identifier] }).count()) for run_system_task_id in self.run_system_tasks[ self.image_collections[0].identifier]: self.assertEqual( 0, Task.objects.raw({ '_id': run_system_task_id }).count()) # Check that the remaining tasks are still there. for i in range(1, len(self.image_collections)): self.assertEqual( 1, Task.objects.raw({ '_id': self.import_dataset_tasks[ self.image_collections[i].identifier] }).count()) for run_system_task_id in self.run_system_tasks[ self.image_collections[i].identifier]: self.assertEqual( 1, Task.objects.raw({ '_id': run_system_task_id }).count())
def test_invalidate_image_collection_autoloads_image_collection_types( self, mock_autoload): invalidate.invalidate_image_collections([self.image_collections[0].pk]) self.assertTrue(mock_autoload.called) self.assertIn(mock.call(ImageSource, [self.image_collections[0].pk]), mock_autoload.call_args_list)