Skip to content

Commit

Permalink
Merge pull request #466 from Viatrak/master
Browse files Browse the repository at this point in the history
Added IDs to system checks. IDs can now be used in SILENCED_SYSTEM_CHECKS. Thanks @Viatrak
  • Loading branch information
bernardopires committed Apr 23, 2017
2 parents 9dd3858 + 8cb4d17 commit 94e8b6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
16 changes: 11 additions & 5 deletions tenant_schemas/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ def best_practice(app_configs, **kwargs):
obj="django.conf.settings",
hint="This is necessary to overwrite built-in django "
"management commands with their schema-aware "
"implementations."))
"implementations.",
id="tenant_schemas.W001"))

if not settings.TENANT_APPS:
errors.append(
Error("TENANT_APPS is empty.",
hint="Maybe you don't need this app?"))
hint="Maybe you don't need this app?",
id="tenant_schemas.E001"))

if hasattr(settings, 'PG_EXTRA_SEARCH_PATHS'):
if get_public_schema_name() in settings.PG_EXTRA_SEARCH_PATHS:
Expand All @@ -74,25 +76,29 @@ def best_practice(app_configs, **kwargs):

if not settings.SHARED_APPS:
errors.append(
Warning("SHARED_APPS is empty."))
Warning("SHARED_APPS is empty.",
id="tenant_schemas.W002"))

if not set(settings.TENANT_APPS).issubset(INSTALLED_APPS):
delta = set(settings.TENANT_APPS).difference(INSTALLED_APPS)
errors.append(
Error("You have TENANT_APPS that are not in INSTALLED_APPS",
hint=[a for a in settings.TENANT_APPS if a in delta]))
hint=[a for a in settings.TENANT_APPS if a in delta],
id="tenant_schemas.E002"))

if not set(settings.SHARED_APPS).issubset(INSTALLED_APPS):
delta = set(settings.SHARED_APPS).difference(INSTALLED_APPS)
errors.append(
Error("You have SHARED_APPS that are not in INSTALLED_APPS",
hint=[a for a in settings.SHARED_APPS if a in delta]))
hint=[a for a in settings.SHARED_APPS if a in delta],
id="tenant_schemas.E003"))

if not isinstance(default_storage, TenantStorageMixin):
errors.append(Warning(
"Your default storage engine is not tenant aware.",
hint="Set settings.DEFAULT_FILE_STORAGE to "
"'tenant_schemas.storage.TenantFileSystemStorage'",
id="tenant_schemas.W003"
))

return errors
15 changes: 10 additions & 5 deletions tenant_schemas/tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def test_tenant_schemas_before_django_installed_apps(self):
obj="django.conf.settings",
hint="This is necessary to overwrite built-in django "
"management commands with their schema-aware "
"implementations."),
"implementations.",
id="tenant_schemas.W001"),
])

@override_settings(INSTALLED_APPS=[
Expand All @@ -83,7 +84,8 @@ def test_tenant_schemas_after_custom_apps_in_installed_apps(self):
def test_tenant_apps_empty(self):
self.assertBestPractice([
Error("TENANT_APPS is empty.",
hint="Maybe you don't need this app?"),
hint="Maybe you don't need this app?",
id="tenant_schemas.E001"),
])

@override_settings(PG_EXTRA_SEARCH_PATHS=['public', 'demo1', 'demo2'])
Expand All @@ -101,7 +103,8 @@ def test_public_schema_on_extra_search_paths(self):
@override_settings(SHARED_APPS=())
def test_shared_apps_empty(self):
self.assertBestPractice([
Warning("SHARED_APPS is empty."),
Warning("SHARED_APPS is empty.",
id="tenant_schemas.W002"),
])

@override_settings(TENANT_APPS=(
Expand All @@ -111,7 +114,8 @@ def test_shared_apps_empty(self):
def test_tenant_app_missing_from_install_apps(self):
self.assertBestPractice([
Error("You have TENANT_APPS that are not in INSTALLED_APPS",
hint=['django.contrib.flatpages']),
hint=['django.contrib.flatpages'],
id="tenant_schemas.E002"),
])

@override_settings(SHARED_APPS=(
Expand All @@ -127,5 +131,6 @@ def test_tenant_app_missing_from_install_apps(self):
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']),
hint=['django.contrib.flatpages'],
id="tenant_schemas.E003"),
])

0 comments on commit 94e8b6c

Please sign in to comment.