From 67b2b1f116aceee12922d2a8ff832382bca7e8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Fri, 7 Apr 2017 12:47:23 +0200 Subject: [PATCH] Refs #26605 -- Added migrations state test for a swappable model inheriting an abstract model inheriting concrete model. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Sébastien Diemer for the report and test. --- tests/migrations/test_state.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py index cb8156fc00..8b3d1f998a 100644 --- a/tests/migrations/test_state.py +++ b/tests/migrations/test_state.py @@ -1006,6 +1006,48 @@ class ModelStateTests(SimpleTestCase): self.assertEqual(author_state.bases, (models.Model, )) self.assertEqual(author_state.managers, []) + @override_settings(TEST_SWAPPABLE_MODEL='migrations.SomeFakeModel') + def test_create_swappable_from_abstract(self): + """ + A swappable model inheriting from a hierarchy: + concrete -> abstract -> concrete. + """ + new_apps = Apps(['migrations']) + + class SearchableLocation(models.Model): + keywords = models.CharField(max_length=256) + + class Station(SearchableLocation): + name = models.CharField(max_length=128) + + class Meta: + abstract = True + + class BusStation(Station): + bus_routes = models.CharField(max_length=128) + inbound = models.BooleanField(default=False) + + class Meta(Station.Meta): + app_label = 'migrations' + apps = new_apps + swappable = 'TEST_SWAPPABLE_MODEL' + + station_state = ModelState.from_model(BusStation) + self.assertEqual(station_state.app_label, 'migrations') + self.assertEqual(station_state.name, 'BusStation') + self.assertEqual( + [x for x, y in station_state.fields], + ['searchablelocation_ptr', 'name', 'bus_routes', 'inbound'] + ) + self.assertEqual(station_state.fields[1][1].max_length, 128) + self.assertEqual(station_state.fields[2][1].null, False) + self.assertEqual( + station_state.options, + {'abstract': False, 'swappable': 'TEST_SWAPPABLE_MODEL', 'indexes': []} + ) + self.assertEqual(station_state.bases, ('migrations.searchablelocation', )) + self.assertEqual(station_state.managers, []) + @override_settings(TEST_SWAPPABLE_MODEL='migrations.SomeFakeModel') def test_custom_manager_swappable(self): """