-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Introduced app registration system #6421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
4f4139e
7db2fc9
0394871
0ee728e
f79f575
f329f22
b5f1825
5b88aa1
c9f064d
e53eac3
f2299db
2416687
ec35c49
5968fc9
c1b606e
367e49f
31d767d
d908a66
093408c
263c1c5
741a803
bcc02f4
e64a652
6a55666
9f3f6f2
6e683d9
0850fd1
2055642
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
import inspect | ||
from functools import lru_cache | ||
from importlib import import_module | ||
|
||
from django.apps import apps | ||
|
@@ -52,18 +53,15 @@ def autodiscover_cms_configs(): | |
"class which inherits from CMSAppConfig") | ||
|
||
|
||
@lru_cache(maxsize=None) | ||
def get_cms_apps(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. decorate with |
||
""" | ||
Returns django app configs of apps with a cms config | ||
""" | ||
cms_apps = [] | ||
|
||
for app_config in apps.get_app_configs(): | ||
# The cms_app attr is added by the autodiscover_cms_configs | ||
# function if a cms_config.py file with a suitable class is found. | ||
if hasattr(app_config, 'cms_app'): | ||
cms_apps.append(app_config) | ||
|
||
# NOTE: The cms_app attr is added by the autodiscover_cms_configs | ||
# function if a cms_config.py file with a suitable class is found. | ||
cms_apps = [app_config for app_config in apps.get_app_configs() | ||
if hasattr(app_config, 'cms_app')] | ||
return cms_apps | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
raise KeyError | ||
# Use this app to test what happens when exceptions are raised in this | ||
# file. RuntimeError is just an example exception | ||
raise RuntimeError |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,10 @@ def test_adds_cms_app_attribute_to_django_app_config(self): | |
'cms.test_utils.project.app_with_bad_cms_file', | ||
]) | ||
def test_raises_exception_raised_in_cms_file(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to |
||
# The cms file intentionally raises a KeyError. We need | ||
# The cms file intentionally raises a RuntimeError. We need | ||
# to make sure the exception definitely bubbles up and doesn't | ||
# get caught. | ||
with self.assertRaises(KeyError): | ||
with self.assertRaises(RuntimeError): | ||
app_registration.autodiscover_cms_configs() | ||
|
||
@override_settings(INSTALLED_APPS=[ | ||
|
@@ -57,6 +57,13 @@ def test_raises_exception_when_more_than_one_cms_app_class_found_in_cms_file(sel | |
|
||
class GetCmsAppsTestCase(CMSTestCase): | ||
|
||
def setUp(self): | ||
# The result of get_cms_apps is cached. Clear this cache | ||
# because installed apps change between tests and therefore | ||
# unlike in a live environment, results of this function | ||
# can change between tests | ||
app_registration.get_cms_apps.cache_clear() | ||
|
||
@patch.object(apps, 'get_app_configs') | ||
def test_returns_only_cms_apps(self, mocked_apps): | ||
# apps with cms_app attr and a configure method | ||
|
@@ -216,6 +223,13 @@ def test_runs_configure_app_method_for_correct_apps_when_multiple_apps( | |
|
||
class SetupCmsAppsTestCase(CMSTestCase): | ||
|
||
def setUp(self): | ||
# The result of get_cms_apps is cached. Clear this cache | ||
# because installed apps change between tests and therefore | ||
# unlike in a live environment, results of this function | ||
# can change between tests | ||
app_registration.get_cms_apps.cache_clear() | ||
|
||
@patch.object(setup, 'setup_cms_apps') | ||
def test_setup_cms_apps_function_run_on_startup(self, mocked_setup): | ||
cms_module = import_module('cms') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ | |
|
||
from cms.utils.compat.dj import is_installed as app_is_installed | ||
from cms.app_registration import ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. import order. |
||
autodiscover_cms_configs, get_cms_apps, | ||
configure_cms_apps) | ||
autodiscover_cms_configs, | ||
configure_cms_apps, | ||
get_cms_apps, | ||
) | ||
|
||
|
||
def validate_dependencies(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
param is now
cms_config