1
0
mirror of https://github.com/django/django.git synced 2025-10-27 15:46:10 +00:00

[1.8.x] Fixed #25686 -- Fixed crash on routers without an allow_migrate() method.

Thanks Simon Charette for review.
This commit is contained in:
Josep Cugat
2015-11-06 12:36:38 +01:00
committed by Tim Graham
parent 94d13415d8
commit a42c5376e7
3 changed files with 43 additions and 16 deletions

View File

@@ -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",