Example #1
0
    def test_add_image_sources_enforces_uniqueness_if_already_dereferenced(
            self):
        image_source1 = mock_core.MockImageSource()
        image_source1.save()

        image_source2 = mock_core.MockImageSource()
        image_source2.save()

        obj = SimpleExperiment(name="TestSimpleExperiment",
                               image_sources=[image_source1])
        obj.add_image_sources([image_source1, image_source2])
        self.assertEqual(obj.image_sources, [image_source1, image_source2])

        # check we can still save
        obj.save()
Example #2
0
    def test_add_image_sources_enforces_uniqueness_without_dereferencing(self):
        image_source1 = CountedImageSource()
        image_source1.save()

        image_source2 = CountedImageSource()
        image_source2.save()

        obj = SimpleExperiment(name="TestSimpleExperiment",
                               image_sources=[image_source1])
        obj.save()

        del obj  # Clear the obj to clear existing objects and references
        CountedImageSource.instances = 0

        obj = SimpleExperiment.objects.all().first()
        self.assertEqual(0, CountedImageSource.instances)
        obj.add_image_sources([image_source1, image_source2])
        self.assertEqual(0, CountedImageSource.instances)
        # this will auto-dereference
        self.assertEqual(obj.image_sources, [image_source1, image_source2])

        # check we can still save
        obj.save()