summaryrefslogtreecommitdiff
path: root/tests/invalid_models_tests
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-06-03 12:55:30 -0700
committerTim Graham <timograham@gmail.com>2016-06-10 10:57:22 -0400
commit0bce2f102c5734d0c7ff1ebf0b10a316d58ed5ce (patch)
tree54a2a9d3088e8d70255a4aa99dbc255bb2bfa81e /tests/invalid_models_tests
parentfaeeb84edfebecf5a5f40df9ef816e5f1cd457c6 (diff)
Fixed #12810 -- Added a check for clashing ManyToManyField.db_table names.
Diffstat (limited to 'tests/invalid_models_tests')
-rw-r--r--tests/invalid_models_tests/test_models.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py
index b8f15cae60..fa63b9e8a7 100644
--- a/tests/invalid_models_tests/test_models.py
+++ b/tests/invalid_models_tests/test_models.py
@@ -761,3 +761,69 @@ class OtherModelTests(SimpleTestCase):
'as an implicit link is deprecated.'
)
self.assertEqual(ParkingLot._meta.pk.name, 'parent')
+
+ def test_m2m_table_name_clash(self):
+ class Foo(models.Model):
+ bar = models.ManyToManyField('Bar', db_table='myapp_bar')
+
+ class Meta:
+ db_table = 'myapp_foo'
+
+ class Bar(models.Model):
+ class Meta:
+ db_table = 'myapp_bar'
+
+ self.assertEqual(Foo.check(), [
+ Error(
+ "The field's intermediary table 'myapp_bar' clashes with the "
+ "table name of 'invalid_models_tests.Bar'.",
+ obj=Foo._meta.get_field('bar'),
+ id='fields.E340',
+ )
+ ])
+
+ def test_m2m_field_table_name_clash(self):
+ class Foo(models.Model):
+ pass
+
+ class Bar(models.Model):
+ foos = models.ManyToManyField(Foo, db_table='clash')
+
+ class Baz(models.Model):
+ foos = models.ManyToManyField(Foo, db_table='clash')
+
+ self.assertEqual(Bar.check() + Baz.check(), [
+ Error(
+ "The field's intermediary table 'clash' clashes with the "
+ "table name of 'invalid_models_tests.Baz.foos'.",
+ obj=Bar._meta.get_field('foos'),
+ id='fields.E340',
+ ),
+ Error(
+ "The field's intermediary table 'clash' clashes with the "
+ "table name of 'invalid_models_tests.Bar.foos'.",
+ obj=Baz._meta.get_field('foos'),
+ id='fields.E340',
+ )
+ ])
+
+ def test_m2m_autogenerated_table_name_clash(self):
+ class Foo(models.Model):
+ class Meta:
+ db_table = 'bar_foos'
+
+ class Bar(models.Model):
+ # The autogenerated `db_table` will be bar_foos.
+ foos = models.ManyToManyField(Foo)
+
+ class Meta:
+ db_table = 'bar'
+
+ self.assertEqual(Bar.check(), [
+ Error(
+ "The field's intermediary table 'bar_foos' clashes with the "
+ "table name of 'invalid_models_tests.Foo'.",
+ obj=Bar._meta.get_field('foos'),
+ id='fields.E340',
+ )
+ ])