mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
Merge pull request #258 from ownaginatious/constance_dbs_setting
Workaround to make `django-constance` work in multi-DB project
This commit is contained in:
commit
61356da3fb
2 changed files with 13 additions and 1 deletions
|
|
@ -16,9 +16,13 @@ class ConstanceConfig(AppConfig):
|
|||
Creates a fake content type and permission
|
||||
to be able to check for permissions
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
constance_dbs = getattr(settings, 'CONSTANCE_DBS', None)
|
||||
if constance_dbs is not None and using not in constance_dbs:
|
||||
return
|
||||
if ContentType._meta.installed and Permission._meta.installed:
|
||||
content_type, created = ContentType.objects.using(using).get_or_create(
|
||||
app_label='constance',
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from django.apps import apps
|
|||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db.models import signals
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
|
||||
class TestApp(TestCase):
|
||||
|
|
@ -20,6 +20,14 @@ class TestApp(TestCase):
|
|||
|
||||
self.assert_content_type_and_permission_created('default')
|
||||
|
||||
@override_settings(CONSTANCE_DBS=['default'])
|
||||
def test_only_use_databases_in_constance_dbs(self):
|
||||
Permission.objects.using('default').delete()
|
||||
Permission.objects.using('secondary').delete()
|
||||
self.assert_uses_correct_database('default')
|
||||
with self.assertRaises(AssertionError):
|
||||
self.assert_uses_correct_database('secondary')
|
||||
|
||||
def assert_uses_correct_database(self, database_name):
|
||||
self.call_post_migrate(database_name)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue