From a42c5376e764712d8ff4a1f9dd3c2d5537722288 Mon Sep 17 00:00:00 2001 From: Josep Cugat Date: Fri, 6 Nov 2015 12:36:38 +0100 Subject: [1.8.x] Fixed #25686 -- Fixed crash on routers without an allow_migrate() method. Thanks Simon Charette for review. --- tests/multiple_database/tests.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/multiple_database') diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index cad410baff..d329340eec 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -956,6 +956,27 @@ class RouterTestCase(TestCase): self.assertTrue(router.allow_migrate('default', 'app_label')) self.assertEqual(force_text(recorded.pop().message), msg) + def test_allow_syncdb_deprecation(self): + class LegacyRouter(object): + def allow_syncdb(self, db, model): + assert db == 'default' + assert model is User + return True + + with override_settings(DATABASE_ROUTERS=[LegacyRouter()]): + with warnings.catch_warnings(record=True) as recorded: + warnings.filterwarnings('always') + msg = ( + "Router.allow_syncdb has been deprecated and will stop " + "working in Django 1.9. Rename the method to allow_migrate." + ) + self.assertTrue(router.allow_migrate_model('default', User)) + self.assertEqual(force_text(recorded.pop().message), msg) + self.assertEqual(recorded, []) + + self.assertTrue(router.allow_migrate('default', 'app_label')) + self.assertEqual(force_text(recorded.pop().message), msg) + def test_partial_router(self): "A router can choose to implement a subset of methods" dive = Book.objects.using('other').create(title="Dive into Python", -- cgit v1.3