Skip to content
This repository was archived by the owner on Apr 16, 2023. It is now read-only.

Commit f593541

Browse files
committed
Check for django-polymorphic-tree install state
It needs to be installed so that the admin templates are loaded.
1 parent f6f75f2 commit f593541

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

conman/routes/apps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ class RouteConfig(AppConfig):
1111
def ready(self):
1212
"""Register checks for conman routes."""
1313
register(checks.polymorphic_installed)
14+
register(checks.polymorphic_tree_installed)
1415
register(checks.subclasses_available)

conman/routes/checks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ def polymorphic_installed(app_configs, **kwargs):
1818
return errors
1919

2020

21+
def polymorphic_tree_installed(app_configs, **kwargs):
22+
"""Check that Django Polymorphic Tree is installed correctly."""
23+
errors = []
24+
try:
25+
apps.get_app_config('polymorphic_tree')
26+
except LookupError:
27+
error = Error(
28+
'Django Polymorpic Tree must be in INSTALLED_APPS.',
29+
hint="Add 'polymorphic_tree' to INSTALLED_APPS.",
30+
id='conman.routes.E003',
31+
)
32+
errors.append(error)
33+
34+
return errors
35+
36+
2137
def subclasses_available(app_configs, **kwargs):
2238
"""Check that at least one Route subclass is available."""
2339
errors = []

conman/routes/tests/test_checks.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,35 @@ def test_not_installed(self):
3636
self.assertEqual(errors, [error])
3737

3838

39+
class TestPolymorphicTreeInstalled(SimpleTestCase):
40+
"""Test checks.polymorphic_tree_installed."""
41+
check = staticmethod(checks.polymorphic_tree_installed)
42+
43+
def test_registered(self):
44+
"""checks.polymorphic_tree_installed is a registered check."""
45+
registered_checks = registry.get_checks()
46+
self.assertIn(self.check, registered_checks)
47+
48+
def test_installed(self):
49+
"""The check passes if django-polymorphic-tree is installed."""
50+
with self.settings(INSTALLED_APPS=['conman.routes', 'polymorphic_tree']):
51+
errors = self.check(app_configs=None)
52+
53+
self.assertEqual(errors, [])
54+
55+
def test_not_installed(self):
56+
"""The check fails if django polymorphic is not installed."""
57+
with self.settings(INSTALLED_APPS=['conman.routes']):
58+
errors = self.check(app_configs=None)
59+
60+
error = Error(
61+
'Django Polymorpic Tree must be in INSTALLED_APPS.',
62+
hint="Add 'polymorphic_tree' to INSTALLED_APPS.",
63+
id='conman.routes.E003',
64+
)
65+
self.assertEqual(errors, [error])
66+
67+
3968
class TestSubclassesAvailable(SimpleTestCase):
4069
"""Test checks.subclasses_available."""
4170
def test_registered(self):

0 commit comments

Comments
 (0)