Beispiel #1
0
 def test_invalidate_image_collection_removes_the_collection(self):
     invalidate.invalidate_image_collection(self.mock_db_client,
                                            self.image_collections[0])
     # Check that the image collection is removed
     self.assertEqual(
         0,
         self.mock_db_client.image_source_collection.find({
             '_id':
             self.image_collections[0]
         }).count())
     # Check that the other collections are still here
     for i in range(1, len(self.image_collections)):
         self.assertEqual(
             1,
             self.mock_db_client.image_source_collection.find({
                 '_id':
                 self.image_collections[i]
             }).count())
Beispiel #2
0
    def test_invalidate_image_collection_removes_tasks(self):
        self.assertEqual(
            len(self.image_collections) * (1 + len(self.systems)),
            self.mock_db_client.tasks_collection.find().count())
        invalidate.invalidate_image_collection(self.mock_db_client,
                                               self.image_collections[0])

        # Check that the total number of tasks has gone down like we expected
        self.assertEqual(
            (len(self.image_collections) - 1) * (1 + len(self.systems)),
            self.mock_db_client.tasks_collection.find().count())

        # Check explicitly that each of the tasks associated with the invalidated image collection are removed
        self.assertEqual(
            0,
            self.mock_db_client.tasks_collection.find({
                '_id':
                self.generate_dataset_tasks[self.image_collections[0]]
            }).count())
        for run_system_task_id in self.run_system_tasks[
                self.image_collections[0]]:
            self.assertEqual(
                0,
                self.mock_db_client.tasks_collection.find({
                    '_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,
                self.mock_db_client.tasks_collection.find({
                    '_id':
                    self.generate_dataset_tasks[self.image_collections[i]]
                }).count())
            for run_system_task_id in self.run_system_tasks[
                    self.image_collections[i]]:
                self.assertEqual(
                    1,
                    self.mock_db_client.tasks_collection.find({
                        '_id':
                        run_system_task_id
                    }).count())
Beispiel #3
0
    def test_invalidate_image_collection_invalidates_descendant_controllers(
            self):
        with mock.patch('batch_analysis.invalidate.invalidate_controller'
                        ) as mock_invalidate_controller:
            invalidate.invalidate_image_collection(self.mock_db_client,
                                                   self.image_collections[0])

            # Check that all the descendant controllers are invalidated
            self.assertIn(
                mock.call(self.mock_db_client,
                          self.controllers[self.image_collections[0]]),
                mock_invalidate_controller.call_args_list)

            # Check that the descendant controllers are not invalidated
            for i in range(1, len(self.image_collections)):
                self.assertNotIn(
                    mock.call(self.mock_db_client,
                              self.controllers[self.image_collections[i]]),
                    mock_invalidate_controller.call_args_list)
Beispiel #4
0
    def test_invalidate_image_collection_invalidates_descendant_trials(self):
        with mock.patch('batch_analysis.invalidate.invalidate_trial_result'
                        ) as mock_invalidate_trial:
            invalidate.invalidate_image_collection(self.mock_db_client,
                                                   self.image_collections[0])

            # Check that all the descendant trials are invalidated
            for trial_result_id in self.trial_results[
                    self.image_collections[0]]:
                self.assertIn(mock.call(self.mock_db_client, trial_result_id),
                              mock_invalidate_trial.call_args_list)

            # Check that the other trials are not invalidated
            for i in range(1, len(self.image_collections)):
                for trial_result_id in self.trial_results[
                        self.image_collections[i]]:
                    self.assertNotIn(
                        mock.call(self.mock_db_client, trial_result_id),
                        mock_invalidate_trial.call_args_list)
Beispiel #5
0
    def test_invalidate_image_collection_removes_images(self):
        # Collect the image ids
        removed_ids = []
        kept_ids = []
        for s_image_collection in self.mock_db_client.image_source_collection.find(
            {'images': {
                '$exists': True
            }}, {
                '_id': True,
                'images': True
            }):
            if s_image_collection['_id'] == self.image_collections[0]:
                removed_ids += [
                    image_id for _, image_id in s_image_collection['images']
                ]
            else:
                kept_ids += [
                    image_id for _, image_id in s_image_collection['images']
                ]

        invalidate.invalidate_image_collection(self.mock_db_client,
                                               self.image_collections[0])

        # Check the removed ids are gone
        for image_id in removed_ids:
            self.assertEqual(
                0,
                self.mock_db_client.image_collection.find({
                    '_id': image_id
                }).count())
        for image_id in kept_ids:
            self.assertEqual(
                1,
                self.mock_db_client.image_collection.find({
                    '_id': image_id
                }).count())