/
test_checks.py
64 lines (57 loc) · 2.46 KB
/
test_checks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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)