From cf21fc9bf010c71385dbead215d26151fb70d2ad Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 7 Apr 2020 10:54:19 +0200 Subject: [PATCH] Enforced uniqueness of natural keys used in tests. --- tests/fixtures/models.py | 4 ++-- tests/fixtures_regress/models.py | 18 +++++++++--------- tests/multiple_database/models.py | 2 +- tests/serializers/models/natural.py | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/fixtures/models.py b/tests/fixtures/models.py index fb4fe08f17..2ecb56537f 100644 --- a/tests/fixtures/models.py +++ b/tests/fixtures/models.py @@ -66,7 +66,7 @@ class PersonManager(models.Manager): class Person(models.Model): objects = PersonManager() - name = models.CharField(max_length=100) + name = models.CharField(max_length=100, unique=True) class Meta: ordering = ('name',) @@ -119,7 +119,7 @@ class PrimaryKeyUUIDModel(models.Model): class NaturalKeyThing(models.Model): - key = models.CharField(max_length=100) + key = models.CharField(max_length=100, unique=True) other_thing = models.ForeignKey('NaturalKeyThing', on_delete=models.CASCADE, null=True) other_things = models.ManyToManyField('NaturalKeyThing', related_name='thing_m2m_set') diff --git a/tests/fixtures_regress/models.py b/tests/fixtures_regress/models.py index 5bc77d9cc9..f3253d1b90 100644 --- a/tests/fixtures_regress/models.py +++ b/tests/fixtures_regress/models.py @@ -98,7 +98,7 @@ class TestManager(models.Manager): class Store(models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) main = models.ForeignKey('self', models.SET_NULL, null=True) objects = TestManager() @@ -114,7 +114,7 @@ class Store(models.Model): class Person(models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) objects = TestManager() @@ -178,7 +178,7 @@ class RefToNKChild(models.Model): # ome models with pathological circular dependencies class Circle1(models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) def natural_key(self): return (self.name,) @@ -186,7 +186,7 @@ class Circle1(models.Model): class Circle2(models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) def natural_key(self): return (self.name,) @@ -194,7 +194,7 @@ class Circle2(models.Model): class Circle3(models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) def natural_key(self): return (self.name,) @@ -202,7 +202,7 @@ class Circle3(models.Model): class Circle4(models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) def natural_key(self): return (self.name,) @@ -210,7 +210,7 @@ class Circle4(models.Model): class Circle5(models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) def natural_key(self): return (self.name,) @@ -218,7 +218,7 @@ class Circle5(models.Model): class Circle6(models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) def natural_key(self): return (self.name,) @@ -226,7 +226,7 @@ class Circle6(models.Model): class ExternalDependency(models.Model): - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, unique=True) def natural_key(self): return (self.name,) diff --git a/tests/multiple_database/models.py b/tests/multiple_database/models.py index 5d1251ecb3..ace89fac89 100644 --- a/tests/multiple_database/models.py +++ b/tests/multiple_database/models.py @@ -25,7 +25,7 @@ class PersonManager(models.Manager): class Person(models.Model): - name = models.CharField(max_length=100) + name = models.CharField(max_length=100, unique=True) objects = PersonManager() diff --git a/tests/serializers/models/natural.py b/tests/serializers/models/natural.py index 8f0bc48648..88bfed566b 100644 --- a/tests/serializers/models/natural.py +++ b/tests/serializers/models/natural.py @@ -24,7 +24,7 @@ class FKDataNaturalKey(models.Model): class NaturalKeyThing(models.Model): - key = models.CharField(max_length=100) + key = models.CharField(max_length=100, unique=True) other_thing = models.ForeignKey('NaturalKeyThing', on_delete=models.CASCADE, null=True) other_things = models.ManyToManyField('NaturalKeyThing', related_name='thing_m2m_set')