Example #1
0
    def test_load_referenced_models_autoloads_models_that_are_just_ids(
            self, mock_autoload):
        system = mock_core.MockSystem()
        system.save()

        image_source = mock_core.MockImageSource()
        image_source.save()

        metric = mock_core.MockMetric()
        metric.save()

        obj = SimpleExperiment(name="TestSimpleExperiment",
                               systems=[system],
                               image_sources=[image_source],
                               metrics=[metric])
        obj.save()
        del obj  # Clear existing references, which should reset the references to ids

        obj = next(SimpleExperiment.objects.all())
        self.assertFalse(mock_autoload.called)
        obj.load_referenced_models()
        self.assertTrue(mock_autoload.called)
        self.assertIn(mock.call(VisionSystem, ids=[system.pk]),
                      mock_autoload.call_args_list)
        self.assertIn(mock.call(ImageSource, ids=[image_source.pk]),
                      mock_autoload.call_args_list)
        self.assertIn(mock.call(Metric, ids=[metric.pk]),
                      mock_autoload.call_args_list)
Example #2
0
    def test_load_referenced_models_does_nothing_to_models_that_are_already_objects(
            self, mock_autoload):
        system = mock_core.MockSystem()
        system.save()

        image_source = mock_core.MockImageSource()
        image_source.save()

        metric = mock_core.MockMetric()
        metric.save()

        obj = SimpleExperiment(name="TestSimpleExperiment",
                               systems=[system],
                               image_sources=[image_source],
                               metrics=[metric])
        obj.save()

        self.assertFalse(mock_autoload.called)
        obj.load_referenced_models()
        self.assertFalse(mock_autoload.called)