diff --git a/dpgs_sandbox/tests/test_apps.py b/dpgs_sandbox/tests/test_apps.py index 99c7897..e012784 100644 --- a/dpgs_sandbox/tests/test_apps.py +++ b/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": ""} @@ -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() diff --git a/dpgs_sandbox/tests/test_checks.py b/dpgs_sandbox/tests/test_checks.py new file mode 100644 index 0000000..f8d4936 --- /dev/null +++ b/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)