diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-09-12 05:56:16 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-09-18 22:12:40 +0200 |
| commit | 2abf417c815c20f41c0868d6f66520b32347106e (patch) | |
| tree | 0e02ebe5f1000155268cc8701f412161ebcfecb8 /tests/invalid_models_tests/test_models.py | |
| parent | 00e187961059a0e77403151d2bb38c217101d5af (diff) | |
Refs #27236 -- Removed Meta.index_together per deprecation timeline.
Diffstat (limited to 'tests/invalid_models_tests/test_models.py')
| -rw-r--r-- | tests/invalid_models_tests/test_models.py | 131 |
1 files changed, 1 insertions, 130 deletions
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index dc52f58c44..f22f273c9a 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -5,9 +5,8 @@ from django.core.checks.model_checks import _check_lazy_references from django.db import connection, connections, models from django.db.models.functions import Abs, Lower, Round from django.db.models.signals import post_init -from django.test import SimpleTestCase, TestCase, ignore_warnings, skipUnlessDBFeature +from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature from django.test.utils import isolate_apps, override_settings, register_lookup -from django.utils.deprecation import RemovedInDjango51Warning class EmptyRouter: @@ -30,134 +29,6 @@ def get_max_column_name_length(): @isolate_apps("invalid_models_tests") -@ignore_warnings(category=RemovedInDjango51Warning) -class IndexTogetherTests(SimpleTestCase): - def test_non_iterable(self): - class Model(models.Model): - class Meta: - index_together = 42 - - self.assertEqual( - Model.check(), - [ - Error( - "'index_together' must be a list or tuple.", - obj=Model, - id="models.E008", - ), - ], - ) - - def test_non_list(self): - class Model(models.Model): - class Meta: - index_together = "not-a-list" - - self.assertEqual( - Model.check(), - [ - Error( - "'index_together' must be a list or tuple.", - obj=Model, - id="models.E008", - ), - ], - ) - - def test_list_containing_non_iterable(self): - class Model(models.Model): - class Meta: - index_together = [("a", "b"), 42] - - self.assertEqual( - Model.check(), - [ - Error( - "All 'index_together' elements must be lists or tuples.", - obj=Model, - id="models.E009", - ), - ], - ) - - def test_pointing_to_missing_field(self): - class Model(models.Model): - class Meta: - index_together = [["missing_field"]] - - self.assertEqual( - Model.check(), - [ - Error( - "'index_together' refers to the nonexistent field 'missing_field'.", - obj=Model, - id="models.E012", - ), - ], - ) - - def test_pointing_to_non_local_field(self): - class Foo(models.Model): - field1 = models.IntegerField() - - class Bar(Foo): - field2 = models.IntegerField() - - class Meta: - index_together = [["field2", "field1"]] - - self.assertEqual( - Bar.check(), - [ - Error( - "'index_together' refers to field 'field1' which is not " - "local to model 'Bar'.", - hint="This issue may be caused by multi-table inheritance.", - obj=Bar, - id="models.E016", - ), - ], - ) - - def test_pointing_to_m2m_field(self): - class Model(models.Model): - m2m = models.ManyToManyField("self") - - class Meta: - index_together = [["m2m"]] - - self.assertEqual( - Model.check(), - [ - Error( - "'index_together' refers to a ManyToManyField 'm2m', but " - "ManyToManyFields are not permitted in 'index_together'.", - obj=Model, - id="models.E013", - ), - ], - ) - - def test_pointing_to_fk(self): - class Foo(models.Model): - pass - - class Bar(models.Model): - foo_1 = models.ForeignKey( - Foo, on_delete=models.CASCADE, related_name="bar_1" - ) - foo_2 = models.ForeignKey( - Foo, on_delete=models.CASCADE, related_name="bar_2" - ) - - class Meta: - index_together = [["foo_1_id", "foo_2"]] - - self.assertEqual(Bar.check(), []) - - -# unique_together tests are very similar to index_together tests. -@isolate_apps("invalid_models_tests") class UniqueTogetherTests(SimpleTestCase): def test_non_iterable(self): class Model(models.Model): |
