Пример #1
0
 def test_sealed_non_sealable_model(self):
     class NonSealableLocation(models.Model):
         class Meta:
             db_table = Location._meta.db_table
     queryset = SealableQuerySet(model=NonSealableLocation)
     instance = queryset.seal().get()
     self.assertTrue(instance._state.sealed)
Пример #2
0
    def test_sealed_prefetch_related_non_sealable_model(self):
        class NonSealableClimate(models.Model):
            objects = SealableQuerySet.as_manager()

            class Meta:
                db_table = Climate._meta.db_table

        class NonSealableLocationClimatesThrough(models.Model):
            climate = models.ForeignKey(NonSealableClimate, models.CASCADE)
            location = models.ForeignKey('NonSealableLocation', models.CASCADE)

            class Meta:
                db_table = Location.climates.through._meta.db_table

        class NonSealableLocation(models.Model):
            climates = models.ManyToManyField(
                NonSealableClimate, through=NonSealableLocationClimatesThrough)

            class Meta:
                db_table = Location._meta.db_table

        queryset = SealableQuerySet(model=NonSealableLocation)
        instance = queryset.prefetch_related('climates').seal().get()
        self.assertTrue(instance._state.sealed)
        with self.assertNumQueries(0):
            self.assertTrue(instance.climates.all()[0]._state.sealed)
Пример #3
0
    def test_sealed_select_related_non_sealable_model(self):
        class NonSealableLocation(models.Model):
            class Meta:
                db_table = Location._meta.db_table

        class NonSealableSeaLion(models.Model):
            location = models.ForeignKey(NonSealableLocation, models.CASCADE)

            class Meta:
                db_table = SeaLion._meta.db_table
        queryset = SealableQuerySet(model=NonSealableSeaLion)
        instance = queryset.select_related('location').seal().get()
        self.assertTrue(instance._state.sealed)
        self.assertTrue(instance.location._state.sealed)
Пример #4
0
        class NonSealableClimate(models.Model):
            objects = SealableQuerySet.as_manager()

            class Meta:
                db_table = Climate._meta.db_table
Пример #5
0
 class Foo(models.Model):
     manager = SealableManager()
     as_manager = SealableQuerySet.as_manager()
Пример #6
0
 def test_isinstance_manager(self):
     """Manager classes are subclasses of Manager as many third-party apps expect."""
     self.assertIsInstance(SealableManager(), models.Manager)
     self.assertIsInstance(SealableQuerySet.as_manager(), models.Manager)