Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 443 #444

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions tenant_schemas/apps.py
Expand Up @@ -93,6 +93,14 @@ def best_practice(app_configs, **kwargs):
hint=[a for a in settings.SHARED_APPS if a in delta],
id="tenant_schemas.E003"))

installed_not_shared_or_tenant = set(INSTALLED_APPS).difference(
set(settings.SHARED_APPS).union(settings.TENANT_APPS))
if installed_not_shared_or_tenant:
errors.append(
Error("You have INSTALLED_APPS that are not in either of "
"TENANT_APPS or SHARED_APPS",
hint=sorted(installed_not_shared_or_tenant)))

if not isinstance(default_storage, TenantStorageMixin):
errors.append(Warning(
"Your default storage engine is not tenant aware.",
Expand Down
43 changes: 29 additions & 14 deletions tenant_schemas/tests/test_apps.py
@@ -1,7 +1,7 @@
from django.apps import apps
from django.core.checks import Critical, Error, Warning
from django.test import TestCase
from django.test.utils import override_settings
from django.test.utils import modify_settings, override_settings

from tenant_schemas.apps import best_practice
from tenant_schemas.utils import get_tenant_model
Expand Down Expand Up @@ -86,6 +86,9 @@ def test_tenant_apps_empty(self):
Error("TENANT_APPS is empty.",
hint="Maybe you don't need this app?",
id="tenant_schemas.E001"),
Error("You have INSTALLED_APPS that are not in either of "
"TENANT_APPS or SHARED_APPS",
hint=['dts_test_app']),
])

@override_settings(PG_EXTRA_SEARCH_PATHS=['public', 'demo1', 'demo2'])
Expand All @@ -100,11 +103,20 @@ def test_public_schema_on_extra_search_paths(self):
Critical("Do not include tenant schemas (demo1, demo2) on PG_EXTRA_SEARCH_PATHS."),
])

@override_settings(SHARED_APPS=())
@override_settings(SHARED_APPS=(), INSTALLED_APPS=(
'tenant_schemas',
'dts_test_app',
'django.contrib.contenttypes',
))
@modify_settings(TENANT_APPS={
'append': 'django.contrib.contenttypes',
})
def test_shared_apps_empty(self):
self.assertBestPractice([
Warning("SHARED_APPS is empty.",
id="tenant_schemas.W002"),
Warning("SHARED_APPS is empty.", id="tenant_schemas.W002"),
Error("You have INSTALLED_APPS that are not in either of "
"TENANT_APPS or SHARED_APPS",
hint=['tenant_schemas']),
])

@override_settings(TENANT_APPS=(
Expand All @@ -118,19 +130,22 @@ def test_tenant_app_missing_from_install_apps(self):
id="tenant_schemas.E002"),
])

@override_settings(SHARED_APPS=(
'tenant_schemas',
'customers',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.flatpages',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.staticfiles',
))
@modify_settings(SHARED_APPS={
'append': 'django.contrib.flatpages',
})
def test_shared_app_missing_from_install_apps(self):
self.assertBestPractice([
Error("You have SHARED_APPS that are not in INSTALLED_APPS",
hint=['django.contrib.flatpages'],
id="tenant_schemas.E003"),
])

@modify_settings(INSTALLED_APPS={
'append': 'django.contrib.humanize',
})
def test_installed_app_missing_from_shared_and_tenant_apps(self):
self.assertBestPractice([
Error("You have INSTALLED_APPS that are not in either of "
"TENANT_APPS or SHARED_APPS",
hint=['django.contrib.humanize']),
])