Skip to content

Commit

Permalink
Extracted check tests into dedicated module
Browse files Browse the repository at this point in the history
  • Loading branch information
lorinkoz committed Apr 21, 2020
1 parent e38dab6 commit e490017
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 53 deletions.
53 changes: 0 additions & 53 deletions dpgs_sandbox/tests/test_apps.py
@@ -1,12 +1,8 @@
from django.apps import apps
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core import checks
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, override_settings

from django_pgschemas.checks import check_apps

settings_public = {"TENANT_MODEL": "shared_public.Tenant", "DOMAIN_MODEL": "shared_public.Domain"}
settings_default = {"URLCONF": ""}

Expand Down Expand Up @@ -139,55 +135,6 @@ def test_extra_search_paths(self):
with self.assertRaises(ImproperlyConfigured):
self.app_config._check_extra_search_paths()

def test_contenttypes_location(self):
with override_settings(TENANTS={"default": {"APPS": ["django.contrib.contenttypes"]}}):
errors = check_apps(self.app_config)
expected_errors = [
checks.Warning(
"'django.contrib.contenttypes' in TENANTS['default']['APPS'] must be on 'public' schema only.",
id="pgschemas.W001",
)
]
self.assertEqual(errors, expected_errors)
with override_settings(TENANTS={"default": {}, "www": {"APPS": ["django.contrib.contenttypes"]}}):
errors = check_apps(self.app_config)
expected_errors = [
checks.Warning(
"'django.contrib.contenttypes' in TENANTS['www']['APPS'] must be on 'public' schema only.",
id="pgschemas.W001",
)
]
self.assertEqual(errors, expected_errors)

def test_user_session_location(self):
user_app = get_user_model()._meta.app_config.name

with override_settings(TENANTS={"default": {"APPS": ["django.contrib.sessions"]}}):
errors = check_apps(self.app_config)
expected_errors = [
checks.Warning(
"'%s' must be together with '%s' in TENANTS['%s']['APPS']."
% (user_app, "django.contrib.sessions", "default"),
id="pgschemas.W002",
)
]
self.assertEqual(errors, expected_errors)
with override_settings(
TENANTS={
"default": {"APPS": ["shared_common"]},
"www": {"APPS": ["shared_common", "django.contrib.sessions"]},
}
):
errors = check_apps(self.app_config)
expected_errors = [
checks.Warning(
"'%s' must be together with '%s' in TENANTS['%s']['APPS']."
% ("django.contrib.sessions", user_app, "default"),
id="pgschemas.W002",
)
]
self.assertEqual(errors, expected_errors)

@override_settings(TENANTS={"public": settings_public, "default": settings_default})
def test_all_good_here(self):
self.app_config.ready()
64 changes: 64 additions & 0 deletions dpgs_sandbox/tests/test_checks.py
@@ -0,0 +1,64 @@
from django.apps import apps
from django.conf import settings
from django.core import checks
from django.test import TestCase, override_settings

from django_pgschemas.checks import check_apps, get_user_app


class AppConfigTestCase(TestCase):
"""
Tests TENANTS settings is properly defined.
"""

def setUp(self):
self.app_config = apps.get_app_config("django_pgschemas")

def test_contenttypes_location(self):
with override_settings(TENANTS={"default": {"APPS": ["django.contrib.contenttypes"]}}):
errors = check_apps(self.app_config)
expected_errors = [
checks.Warning(
"'django.contrib.contenttypes' in TENANTS['default']['APPS'] must be on 'public' schema only.",
id="pgschemas.W001",
)
]
self.assertEqual(errors, expected_errors)
with override_settings(TENANTS={"default": {}, "www": {"APPS": ["django.contrib.contenttypes"]}}):
errors = check_apps(self.app_config)
expected_errors = [
checks.Warning(
"'django.contrib.contenttypes' in TENANTS['www']['APPS'] must be on 'public' schema only.",
id="pgschemas.W001",
)
]
self.assertEqual(errors, expected_errors)

def test_user_session_location(self):
user_app = get_user_app()

with override_settings(TENANTS={"default": {"APPS": ["django.contrib.sessions"]}}):
errors = check_apps(self.app_config)
expected_errors = [
checks.Warning(
"'%s' must be together with '%s' in TENANTS['%s']['APPS']."
% (user_app, "django.contrib.sessions", "default"),
id="pgschemas.W002",
)
]
self.assertEqual(errors, expected_errors)
with override_settings(
TENANTS={
"default": {"APPS": ["shared_common"]},
"www": {"APPS": ["shared_common", "django.contrib.sessions"]},
}
):
errors = check_apps(self.app_config)
expected_errors = [
checks.Warning(
"'%s' must be together with '%s' in TENANTS['%s']['APPS']."
% ("django.contrib.sessions", user_app, "default"),
id="pgschemas.W002",
)
]
self.assertEqual(errors, expected_errors)

0 comments on commit e490017

Please sign in to comment.