8000 Introduced app registration system by monikasulik · Pull Request #6421 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 28 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4f4139e
App registry: autodiscover
monikasulik Jun 14, 2018
7db2fc9
App registration: Add cms_app attr to django app config
monikasulik Jun 14, 2018
0394871
App registration: run extension methods
monikasulik Jun 15, 2018
0ee728e
App registration: Some clean up
monikasulik Jun 15, 2018
f79f575
App registration: Edge cases
monikasulik Jun 15, 2018
f329f22
App registration: Configure CMS apps
monikasulik Jun 18, 2018
b5f1825
App registration: More clean up
monikasulik Jun 18, 2018
5b88aa1
Merge pull request #3 from monikasulik/app_registration_config
monikasulik Jun 19, 2018
c9f064d
App registration: Test comments
monikasulik Jun 19, 2018
e53eac3
App registration: Integrate into start up (WIP)
monikasulik Jun 21, 2018
f2299db
App registration: Clean up
monikasulik Jun 21, 2018
2416687
Merge pull request #4 from monikasulik/app_registration_start_up
monikasulik Jun 21, 2018
ec35c49
App registration: Remove import test (inconsistent across envs) and u…
monikasulik Jun 21, 2018
5968fc9
App registration: Clean up CMSAppConfig class
monikasulik Jun 21, 2018
c1b606e
Move app registration test apps to test_utils
monikasulik Jun 22, 2018
367e49f
App registration: CHANGELOG and AUTHORS changes
monikasulik Jun 22, 2018
31d767d
Merge pull request #5 from monikasulik/app_registration_improvements
monikasulik Jun 22, 2018
d908a66
App registration: Various minor changes after code review
monikasulik Jun 25, 2018
093408c
App registration: Split app config into 2 classes
monikasulik Jun 25, 2018
263c1c5
App registration: Polish up after separating config base classes
monikasulik Jun 25, 2018
741a803
Merge pull request #6 from monikasulik/app_registration_improvements
monikasulik Jun 25, 2018
bcc02f4
Fix python 2.7 compatibility issue
monikasulik Jun 26, 2018
e64a652
App registration: Improvements after code review
monikasulik Jun 26, 2018
6a55666
Clean up
monikasulik Jun 26, 2018
9f3f6f2
Clean up
monikasulik Jun 26, 2018
6e683d9
Fix abc import for python 2.7
monikasulik Jun 26, 2018
0850fd1
App registration: Clean up
monikasulik Jun 26, 2018
2055642
Minor cleanup
czpython Jun 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move app registration test apps to test_utils
  • Loading branch information
monikasulik committed Jun 22, 2018
commit c1b606ebe447fca8deea67fcaec68150b01a9762
16 changes: 15 additions & 1 deletion cms/app_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,22 @@ def get_urls(self, page=None, language=None, **kwargs):
return self._urls


class CMSAppConfig():
class CMSAppConfig(object):
"""Base class that all cms app configurations should inherit from"""

def configure_app(self, app):
"""
Implement this method if the app provides functionality that
other apps can use and configure.

This method will be run once for every app that defines an
attribute like "<app_label>_enabled" as True on its cms app
config class.
So for example if app A with label "app_a" implements this
method and app B and app C define app_a_enabled = True on their
cms config classes, the method app A has defined will run twice,
once for app B and once for app C.

:param app: django app that has defined the feature as enabled
Copy link
Contributor

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

"""
raise NotImplementedError()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when not passing arguments, raise NotImplementedError, vs NotImplementedError()

1 change: 1 addition & 0 deletions cms/test_utils/project/app_using_non_feature/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_using_non_feature.apps.NonFeatureCMSConfig'
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class NonFeatureCMSConfig(AppConfig):
name = 'cms.tests.test_app_registry.app_using_non_feature'
name = 'cms.test_utils.project.app_using_non_feature'
label = 'app_using_non_feature'
1 change: 1 addition & 0 deletions cms/test_utils/project/app_with_bad_cms_file/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_bad_cms_file.apps.BadCMSFileConfig'
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class BadCMSFileConfig(AppConfig):
name = 'cms.tests.test_app_registry.app_with_bad_cms_file'
name = 'cms.test_utils.project.app_with_bad_cms_file'
label = 'bad_cms_file'
1 change: 1 addition & 0 deletions cms/test_utils/project/app_with_cms_config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_cms_config.apps.CMSConfigConfig'
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class CMSConfigConfig(AppConfig):
name = 'cms.tests.test_app_registry.app_with_cms_config'
name = 'cms.test_utils.project.app_with_cms_config'
label = 'app_with_cms_config'
1 change: 1 addition & 0 deletions cms/test_utils/project/app_with_cms_feature/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_cms_feature.apps.CMSFeatureConfig'
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class CMSFeatureConfig(AppConfig):
name = 'cms.tests.test_app_registry.app_with_cms_feature'
name = 'cms.test_utils.project.app_with_cms_feature'
label = 'app_with_cms_feature'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_two_cms_app_classes.apps.TwoCMSAppClassesConfig'
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class TwoCMSAppClassesConfig(AppConfig):
name = 'cms.tests.test_app_registry.app_with_two_cms_app_classes'
name = 'cms.test_utils.project.app_with_two_cms_app_classes'
label = 'app_with_two_cms_app_classes'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_without_cms_app_class.apps.WithoutCMSAppClassConfig'
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class WithoutCMSAppClassConfig(AppConfig):
name = 'cms.tests.test_app_registry.app_without_cms_app_class'
name = 'cms.test_utils.project.app_without_cms_app_class'
label = 'app_without_cms_app_class'
1 change: 1 addition & 0 deletions cms/test_utils/project/app_without_cms_file/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_without_cms_file.apps.WithoutCMSFileConfig'
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class WithoutCMSFileConfig(AppConfig):
name = 'cms.tests.test_app_registry.app_without_cms_file'
name = 'cms.test_utils.project.app_without_cms_file'
label = 'app_without_cms_file'
20 changes: 10 additions & 10 deletions cms/tests/test_app_registration.py
10000
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
class AutodiscoverTestCase(CMSTestCase):

@override_settings(INSTALLED_APPS=[
'cms.tests.test_app_registry.app_with_cms_feature',
'cms.tests.test_app_registry.app_without_cms_file'
'cms.test_utils.project.app_with_cms_feature',
'cms.test_utils.project.app_without_cms_file'
])
def test_adds_cms_app_attribute_to_django_app_config(self):
app_registration.autodiscover_cms_configs()
Expand All @@ -30,7 +30,7 @@ def test_adds_cms_app_attribute_to_django_app_config(self):
self.assertFalse(hasattr(app_list[1], 'cms_app'))

@override_settings(INSTALLED_APPS=[
'cms.tests.test_app_registry.app_with_bad_cms_file',
'cms.test_utils.project.app_with_bad_cms_file',
])
def test_raises_exception_raised_in_cms_file(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to test_exception_propagates_from_cms_file

# The cms file intentionally raises a KeyError. We need
Expand All @@ -40,15 +40,15 @@ def test_raises_exception_raised_in_cms_file(self):
app_registration.autodiscover_cms_configs()

@override_settings(INSTALLED_APPS=[
'cms.tests.test_app_registry.app_without_cms_app_class',
'cms.test_utils.project.app_without_cms_app_class',
])
def test_raises_exception_when_no_cms_app_class_found_in_cms_file(self):
# No cms config defined in the cms file so raise exception
with self.assertRaises(ImproperlyConfigured):
app_registration.autodiscover_cms_configs()

@override_settings(INSTALLED_APPS=[
'cms.tests.test_app_registry.app_with_two_cms_app_classes',
'cms.test_utils.project.app_with_two_cms_app_classes',
])
def test_raises_exception_when_more_than_one_cms_app_class_found_in_cms_file(self):
# More than one cms config defined so raise exception
Expand Down Expand Up @@ -226,9 +226,9 @@ def test_setup_cms_apps_function_run_on_startup(self, mocked_setup):
mocked_setup.assert_called_once()

@override_settings(INSTALLED_APPS=[
'cms.tests.test_app_registry.app_with_cms_feature',
'cms.tests.test_app_registry.app_without_cms_file',
'cms.tests.test_app_registry.app_with_cms_config'
'cms.test_utils.project.app_with_cms_feature',
'cms.test_utils.project.app_without_cms_file',
'cms.test_utils.project.app_with_cms_config'
])
def test_cms_apps_setup_after_setup_function_run(self):
# This is the function that gets run on startup
Expand All @@ -253,8 +253,8 @@ def test_cms_apps_setup_after_setup_function_run(self):
self.assertTrue(config_app.cms_app.configured)

@override_settings(INSTALLED_APPS=[
'cms.tests.test_app_registry.app_with_cms_config',
'cms.tests.test_app_registry.app_using_non_feature'
'cms.test_utils.project.app_with_cms_config',
'cms.test_utils.project.app_using_non_feature'
])
def test_raises_not_implemented_exception_when_feature_app_doesnt_implement_configure_method(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be shortened to test_raises_not_implemented_exception and the rest explained in comment

with self.assertRaises(NotImplementedError):
Expand Down
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0