summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Klöcker <djangoproject@ingo-kloecker.de>2017-04-07 12:47:23 +0200
committerTim Graham <timograham@gmail.com>2017-04-07 13:41:07 -0400
commit67b2b1f116aceee12922d2a8ff832382bca7e8ad (patch)
treede845032cf315e0e559f8137f19dffd97ab6efd9
parentdf8f1d018fcbf780e4e8eb98f550b2db6ad2d4c0 (diff)
Refs #26605 -- Added migrations state test for a swappable model inheriting an abstract model inheriting concrete model.
Thanks Sébastien Diemer for the report and test.
-rw-r--r--tests/migrations/test_state.py42
1 files changed, 42 insertions, 0 deletions
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
@@ -1007,6 +1007,48 @@ class ModelStateTests(SimpleTestCase):
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):
"""
Tests making a ProjectState from unused models with custom managers