From 652bcc6f5fa9084768890488fec5208e082c2add Mon Sep 17 00:00:00 2001 From: Adam Chainz Date: Fri, 18 Mar 2016 14:24:29 +0000 Subject: [PATCH] Refs #25415 -- Fixed invalid models in the test suite. --- tests/expressions/models.py | 4 ++-- tests/foreign_object/models/empty_join.py | 2 +- tests/introspection/models.py | 2 +- tests/many_to_many/models.py | 1 - tests/model_forms/models.py | 2 +- tests/model_formsets/models.py | 2 +- tests/model_formsets/tests.py | 2 +- tests/model_meta/models.py | 4 ++-- tests/ordering/models.py | 2 +- tests/queries/models.py | 12 ++++++------ 10 files changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/expressions/models.py b/tests/expressions/models.py index 264120d2512..6dc956c8fe2 100644 --- a/tests/expressions/models.py +++ b/tests/expressions/models.py @@ -80,8 +80,8 @@ class Time(models.Model): @python_2_unicode_compatible class SimulationRun(models.Model): - start = models.ForeignKey(Time, models.CASCADE, null=True) - end = models.ForeignKey(Time, models.CASCADE, null=True) + start = models.ForeignKey(Time, models.CASCADE, null=True, related_name='+') + end = models.ForeignKey(Time, models.CASCADE, null=True, related_name='+') midpoint = models.TimeField() def __str__(self): diff --git a/tests/foreign_object/models/empty_join.py b/tests/foreign_object/models/empty_join.py index 61ac5e35a4e..28f3006c947 100644 --- a/tests/foreign_object/models/empty_join.py +++ b/tests/foreign_object/models/empty_join.py @@ -80,7 +80,7 @@ class BrokenContainsRelation(StartsWithRelation): @python_2_unicode_compatible class SlugPage(models.Model): - slug = models.CharField(max_length=20) + slug = models.CharField(max_length=20, unique=True) descendants = StartsWithRelation( 'self', from_fields=['slug'], diff --git a/tests/introspection/models.py b/tests/introspection/models.py index 6d6650bc246..b8c7a83b9f9 100644 --- a/tests/introspection/models.py +++ b/tests/introspection/models.py @@ -45,7 +45,7 @@ class Article(models.Model): body = models.TextField(default='') reporter = models.ForeignKey(Reporter, models.CASCADE) response_to = models.ForeignKey('self', models.SET_NULL, null=True) - unmanaged_reporters = models.ManyToManyField(Reporter, through='ArticleReporter') + unmanaged_reporters = models.ManyToManyField(Reporter, through='ArticleReporter', related_name='+') def __str__(self): return self.headline diff --git a/tests/many_to_many/models.py b/tests/many_to_many/models.py index 3e4cdd2e708..a199cd77e24 100644 --- a/tests/many_to_many/models.py +++ b/tests/many_to_many/models.py @@ -51,7 +51,6 @@ class Article(models.Model): class AbstractArticle(models.Model): class Meta: abstract = True - ordering = ('title',) publications = models.ManyToManyField(Publication, name='publications', related_name='+') diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py index b00e6a26584..0de67eb1f90 100644 --- a/tests/model_forms/models.py +++ b/tests/model_forms/models.py @@ -131,7 +131,7 @@ class Author(models.Model): class Author1(models.Model): - publication = models.OneToOneField(Publication, models.SET_NULL, null=False) + publication = models.OneToOneField(Publication, models.CASCADE, null=False) full_name = models.CharField(max_length=255) diff --git a/tests/model_formsets/models.py b/tests/model_formsets/models.py index 7b7337fd525..0bf56189a7d 100644 --- a/tests/model_formsets/models.py +++ b/tests/model_formsets/models.py @@ -166,7 +166,7 @@ class MexicanRestaurant(Restaurant): class ClassyMexicanRestaurant(MexicanRestaurant): - restaurant = models.OneToOneField(MexicanRestaurant, models.CASCADE, parent_link=True, primary_key=True) + the_restaurant = models.OneToOneField(MexicanRestaurant, models.CASCADE, parent_link=True, primary_key=True) tacos_are_yummy = models.BooleanField(default=False) diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py index 7ac1700691a..60acc463ccb 100644 --- a/tests/model_formsets/tests.py +++ b/tests/model_formsets/tests.py @@ -1461,7 +1461,7 @@ class ModelFormsetTest(TestCase): # a formset for a Model that has a custom primary key that still needs to be # added to the formset automatically FormSet = modelformset_factory(ClassyMexicanRestaurant, fields=["tacos_are_yummy"]) - self.assertEqual(sorted(FormSet().forms[0].fields.keys()), ['restaurant', 'tacos_are_yummy']) + self.assertEqual(sorted(FormSet().forms[0].fields.keys()), ['tacos_are_yummy', 'the_restaurant']) def test_model_formset_with_initial_model_instance(self): # has_changed should compare model instance and primary key diff --git a/tests/model_meta/models.py b/tests/model_meta/models.py index 7060cf521c0..074db093f9f 100644 --- a/tests/model_meta/models.py +++ b/tests/model_meta/models.py @@ -134,11 +134,11 @@ class CommonAncestor(models.Model): class FirstParent(CommonAncestor): - first_ancestor = models.OneToOneField(CommonAncestor, models.SET_NULL, primary_key=True, parent_link=True) + first_ancestor = models.OneToOneField(CommonAncestor, models.CASCADE, primary_key=True, parent_link=True) class SecondParent(CommonAncestor): - second_ancestor = models.OneToOneField(CommonAncestor, models.SET_NULL, primary_key=True, parent_link=True) + second_ancestor = models.OneToOneField(CommonAncestor, models.CASCADE, primary_key=True, parent_link=True) class Child(FirstParent, SecondParent): diff --git a/tests/ordering/models.py b/tests/ordering/models.py index 213a8f5ce87..2c4e9b33084 100644 --- a/tests/ordering/models.py +++ b/tests/ordering/models.py @@ -25,7 +25,7 @@ class Author(models.Model): @python_2_unicode_compatible class Article(models.Model): author = models.ForeignKey(Author, models.SET_NULL, null=True) - second_author = models.ForeignKey(Author, models.SET_NULL, null=True) + second_author = models.ForeignKey(Author, models.SET_NULL, null=True, related_name='+') headline = models.CharField(max_length=100) pub_date = models.DateTimeField() diff --git a/tests/queries/models.py b/tests/queries/models.py index c0ce3a5d60f..67a28e950eb 100644 --- a/tests/queries/models.py +++ b/tests/queries/models.py @@ -526,8 +526,8 @@ class Job(models.Model): class JobResponsibilities(models.Model): - job = models.ForeignKey(Job, models.SET_NULL, to_field='name') - responsibility = models.ForeignKey('Responsibility', models.SET_NULL, to_field='description') + job = models.ForeignKey(Job, models.CASCADE, to_field='name') + responsibility = models.ForeignKey('Responsibility', models.CASCADE, to_field='description') @python_2_unicode_compatible @@ -620,7 +620,7 @@ class Order(models.Model): @python_2_unicode_compatible class OrderItem(models.Model): - order = models.ForeignKey(Order, models.SET_NULL, related_name='items') + order = models.ForeignKey(Order, models.CASCADE, related_name='items') status = models.IntegerField() class Meta: @@ -637,8 +637,8 @@ class BaseUser(models.Model): @python_2_unicode_compatible class Task(models.Model): title = models.CharField(max_length=10) - owner = models.ForeignKey(BaseUser, models.SET_NULL, related_name='owner') - creator = models.ForeignKey(BaseUser, models.SET_NULL, related_name='creator') + owner = models.ForeignKey(BaseUser, models.CASCADE, related_name='owner') + creator = models.ForeignKey(BaseUser, models.CASCADE, related_name='creator') def __str__(self): return self.title @@ -654,7 +654,7 @@ class Staff(models.Model): @python_2_unicode_compatible class StaffUser(BaseUser): - staff = models.OneToOneField(Staff, models.SET_NULL, related_name='user') + staff = models.OneToOneField(Staff, models.CASCADE, related_name='user') def __str__(self): return self.staff