Skip to content

Commit ec1fffc

Browse files
apoorvaeternityadamghill
authored andcommitted
Use rindex when handling installed app that points to an app config
1 parent 2af6f73 commit ec1fffc

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

django_unicorn/components/unicorn_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def get_locations(component_name):
9191
for app in unicorn_apps:
9292
# Handle an installed app that actually points to an app config
9393
if ".apps." in app:
94-
app_config_idx = app.index(".apps.")
94+
app_config_idx = app.rindex(".apps.")
9595
app = app[:app_config_idx]
9696

9797
app_module_name = f"{app}.components.{module_name}"

tests/components/test_get_locations.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def test_get_locations_fully_qualified_with_dots():
2929
("HelloWorldView", "project.components.hello_world"),
3030
]
3131
actual = get_locations("project.components.hello_world.HelloWorldView")
32-
print(actual)
3332

3433
assert expected == actual
3534

@@ -118,10 +117,17 @@ def test_get_locations_apps_setting_invalid(settings):
118117
def test_get_locations_installed_app_with_app_config(settings):
119118
unicorn_apps = settings.UNICORN["APPS"]
120119
del settings.UNICORN["APPS"]
121-
settings.INSTALLED_APPS = ("example.coffee.apps.Config",)
120+
settings.INSTALLED_APPS = ["example.coffee.apps.Config",]
122121

123122
expected = [("HelloWorldView", "example.coffee.components.hello_world",)]
124123
actual = get_locations("hello-world")
125124

126125
assert expected == actual
126+
127+
# test when the app is in a subdirectory "apps"
128+
settings.INSTALLED_APPS[0] = "foo_project.apps.bar_app.apps.Config"
129+
expected_location = [("FooBarView", "foo_project.apps.bar_app.components.foo_bar")]
130+
actual_location = get_locations("foo-bar")
131+
assert expected_location == actual_location
132+
127133
settings.UNICORN["APPS"] = unicorn_apps

0 commit comments

Comments
 (0)