Made a few cleanups to invalid_models_tests.test_models.
This commit is contained in:
parent
51ae4e1f32
commit
b0a2a2b07e
|
@ -75,9 +75,7 @@ class IndexTogetherTests(SimpleTestCase):
|
||||||
def test_pointing_to_missing_field(self):
|
def test_pointing_to_missing_field(self):
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
index_together = [
|
index_together = [['missing_field']]
|
||||||
["missing_field"],
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(Model.check(), [
|
self.assertEqual(Model.check(), [
|
||||||
Error(
|
Error(
|
||||||
|
@ -95,15 +93,13 @@ class IndexTogetherTests(SimpleTestCase):
|
||||||
field2 = models.IntegerField()
|
field2 = models.IntegerField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
index_together = [
|
index_together = [['field2', 'field1']]
|
||||||
["field2", "field1"],
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(Bar.check(), [
|
self.assertEqual(Bar.check(), [
|
||||||
Error(
|
Error(
|
||||||
"'index_together' refers to field 'field1' which is not "
|
"'index_together' refers to field 'field1' which is not "
|
||||||
"local to model 'Bar'.",
|
"local to model 'Bar'.",
|
||||||
hint=("This issue may be caused by multi-table inheritance."),
|
hint='This issue may be caused by multi-table inheritance.',
|
||||||
obj=Bar,
|
obj=Bar,
|
||||||
id='models.E016',
|
id='models.E016',
|
||||||
),
|
),
|
||||||
|
@ -114,9 +110,7 @@ class IndexTogetherTests(SimpleTestCase):
|
||||||
m2m = models.ManyToManyField('self')
|
m2m = models.ManyToManyField('self')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
index_together = [
|
index_together = [['m2m']]
|
||||||
["m2m"],
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(Model.check(), [
|
self.assertEqual(Model.check(), [
|
||||||
Error(
|
Error(
|
||||||
|
@ -188,9 +182,7 @@ class UniqueTogetherTests(SimpleTestCase):
|
||||||
def test_pointing_to_missing_field(self):
|
def test_pointing_to_missing_field(self):
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = [
|
unique_together = [['missing_field']]
|
||||||
["missing_field"],
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(Model.check(), [
|
self.assertEqual(Model.check(), [
|
||||||
Error(
|
Error(
|
||||||
|
@ -205,9 +197,7 @@ class UniqueTogetherTests(SimpleTestCase):
|
||||||
m2m = models.ManyToManyField('self')
|
m2m = models.ManyToManyField('self')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = [
|
unique_together = [['m2m']]
|
||||||
["m2m"],
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(Model.check(), [
|
self.assertEqual(Model.check(), [
|
||||||
Error(
|
Error(
|
||||||
|
@ -311,21 +301,21 @@ class FieldNamesTests(SimpleTestCase):
|
||||||
class ModelWithLongField(models.Model):
|
class ModelWithLongField(models.Model):
|
||||||
m2m_field = models.ManyToManyField(
|
m2m_field = models.ManyToManyField(
|
||||||
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
||||||
related_name="rn1"
|
related_name='rn1',
|
||||||
)
|
)
|
||||||
m2m_field2 = models.ManyToManyField(
|
m2m_field2 = models.ManyToManyField(
|
||||||
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
||||||
related_name="rn2", through='m2msimple'
|
related_name='rn2', through='m2msimple',
|
||||||
)
|
)
|
||||||
m2m_field3 = models.ManyToManyField(
|
m2m_field3 = models.ManyToManyField(
|
||||||
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
||||||
related_name="rn3",
|
related_name='rn3',
|
||||||
through='m2mcomplex'
|
through='m2mcomplex',
|
||||||
)
|
)
|
||||||
fk = models.ForeignKey(
|
fk = models.ForeignKey(
|
||||||
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
VeryLongModelNamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz,
|
||||||
models.CASCADE,
|
models.CASCADE,
|
||||||
related_name="rn4",
|
related_name='rn4',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Models used for setting `through` in M2M field.
|
# Models used for setting `through` in M2M field.
|
||||||
|
@ -567,7 +557,7 @@ class OtherModelTests(SimpleTestCase):
|
||||||
def test_ordering_non_iterable(self):
|
def test_ordering_non_iterable(self):
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = "missing_field"
|
ordering = 'missing_field'
|
||||||
|
|
||||||
self.assertEqual(Model.check(), [
|
self.assertEqual(Model.check(), [
|
||||||
Error(
|
Error(
|
||||||
|
@ -640,7 +630,7 @@ class OtherModelTests(SimpleTestCase):
|
||||||
def test_ordering_pointing_to_missing_field(self):
|
def test_ordering_pointing_to_missing_field(self):
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ("missing_field",)
|
ordering = ('missing_field',)
|
||||||
|
|
||||||
self.assertEqual(Model.check(), [
|
self.assertEqual(Model.check(), [
|
||||||
Error(
|
Error(
|
||||||
|
@ -651,13 +641,11 @@ class OtherModelTests(SimpleTestCase):
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_ordering_pointing_to_missing_foreignkey_field(self):
|
def test_ordering_pointing_to_missing_foreignkey_field(self):
|
||||||
# refs #22711
|
|
||||||
|
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
missing_fk_field = models.IntegerField()
|
missing_fk_field = models.IntegerField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ("missing_fk_field_id",)
|
ordering = ('missing_fk_field_id',)
|
||||||
|
|
||||||
self.assertEqual(Model.check(), [
|
self.assertEqual(Model.check(), [
|
||||||
Error(
|
Error(
|
||||||
|
@ -667,9 +655,7 @@ class OtherModelTests(SimpleTestCase):
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_ordering_pointing_to_existing_foreignkey_field(self):
|
def test_ordering_pointing_to_foreignkey_field(self):
|
||||||
# refs #22711
|
|
||||||
|
|
||||||
class Parent(models.Model):
|
class Parent(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -677,7 +663,7 @@ class OtherModelTests(SimpleTestCase):
|
||||||
parent = models.ForeignKey(Parent, models.CASCADE)
|
parent = models.ForeignKey(Parent, models.CASCADE)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ("parent_id",)
|
ordering = ('parent_id',)
|
||||||
|
|
||||||
self.assertFalse(Child.check())
|
self.assertFalse(Child.check())
|
||||||
|
|
||||||
|
@ -752,8 +738,8 @@ class OtherModelTests(SimpleTestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Group(models.Model):
|
class Group(models.Model):
|
||||||
primary = models.ManyToManyField(Person, through="Membership", related_name="primary")
|
primary = models.ManyToManyField(Person, through='Membership', related_name='primary')
|
||||||
secondary = models.ManyToManyField(Person, through="Membership", related_name="secondary")
|
secondary = models.ManyToManyField(Person, through='Membership', related_name='secondary')
|
||||||
|
|
||||||
class Membership(models.Model):
|
class Membership(models.Model):
|
||||||
person = models.ForeignKey(Person, models.CASCADE)
|
person = models.ForeignKey(Person, models.CASCADE)
|
||||||
|
|
Loading…
Reference in New Issue