Skip to content

Commit

Permalink
Allow get_class from apps.AppConfig (#288)
Browse files Browse the repository at this point in the history
* Allow get_class from apps.AppConfig

* Add a test

* shorten lines
  • Loading branch information
BoPeng committed Jan 17, 2023
1 parent d272150 commit 7c5f067
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions machina/core/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,7 @@ def _get_app_module_path(module_label):
for app in settings.INSTALLED_APPS:
if app.endswith('.' + app_name) or app == app_name:
return app
path = app.split('.')
if len(path) >= 3 and path[-2] == 'apps' and path[-3] == app_name:
return app
return None
7 changes: 7 additions & 0 deletions tests/unit/core/test_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def test_raises_if_the_class_name_is_incorrect(self):
with pytest.raises(ClassNotFoundError):
get_class('forum.models', 'Foo')

def test_get_class_with_app_config(self):
apps = list(settings.INSTALLED_APPS)
idx = apps.index('tests._testsite.apps.forum_conversation')
apps[idx] += '.apps.ForumConversationAppConfig'
with override_settings(INSTALLED_APPS=apps):
get_class('forum_conversation.models', 'Post')

def test_raise_importerror_if_app_raises_importerror(self):
# Setup
apps = list(settings.INSTALLED_APPS)
Expand Down

0 comments on commit 7c5f067

Please sign in to comment.