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): """