From 366a93f17498940b823d7d67a8bee51a776a16ee Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Fri, 7 Aug 2020 09:57:42 +0200 Subject: [PATCH] Refs #31831 -- Added autodector test for unique/index_together on _order field. --- tests/migrations/test_autodetector.py | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 236af438345..0c30cd04896 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -2151,6 +2151,34 @@ class AutodetectorTests(TestCase): ) self.assertNotIn("_order", [name for name, field in changes['testapp'][0].operations[0].fields]) + def test_add_model_order_with_respect_to_index_foo_together(self): + changes = self.get_changes([], [ + self.book, + ModelState('testapp', 'Author', [ + ('id', models.AutoField(primary_key=True)), + ('name', models.CharField(max_length=200)), + ('book', models.ForeignKey('otherapp.Book', models.CASCADE)), + ], options={ + 'order_with_respect_to': 'book', + 'index_together': {('name', '_order')}, + 'unique_together': {('id', '_order')}, + }), + ]) + self.assertNumberMigrations(changes, 'testapp', 1) + self.assertOperationTypes(changes, 'testapp', 0, ['CreateModel']) + self.assertOperationAttributes( + changes, + 'testapp', + 0, + 0, + name='Author', + options={ + 'order_with_respect_to': 'book', + 'index_together': {('name', '_order')}, + 'unique_together': {('id', '_order')}, + }, + ) + def test_alter_model_managers(self): """ Changing the model managers adds a new operation.