Skip to content

Commit

Permalink
Hotfix: url kwargs title (#1123)
Browse files Browse the repository at this point in the history
* fix bug preventing the url arg from being defined as a dict in routing decorators

* black
  • Loading branch information
sdc50 authored Dec 2, 2024
1 parent efd1cd6 commit 9fd110b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
21 changes: 21 additions & 0 deletions tests/unit_tests/test_tethys_apps/test_base/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,24 @@ def test_register_controllers_catch_all(
mock_UrlMap.assert_called_with(
name="catch_all", url="root/.*/", controller=mock_controller
)

def test__get_url_map_kwargs_list_url_dict(self):
result = tethys_controller._get_url_map_kwargs_list(
url={
"test": "test/url/",
"another_test": "test/{another}/url/",
}
)
self.assertEqual(result[0]["title"], "Test")
self.assertEqual(result[1]["title"], "Another Test")

def test__get_url_map_kwargs_list_url_list(self):
result = tethys_controller._get_url_map_kwargs_list(
name="test",
url=[
"test/url/",
"test/{another}/url/",
],
)
self.assertEqual(result[0]["title"], "Test")
self.assertEqual(result[1]["title"], "Test 1")
7 changes: 2 additions & 5 deletions tethys_apps/base/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,6 @@ def _get_url_map_kwargs_list(
for i, final_url in enumerate(final_urls)
}

if not title:
title = url_name.replace("_", " ").title()

return [
dict(
name=url_name,
Expand All @@ -833,7 +830,7 @@ def _get_url_map_kwargs_list(
regex=regex,
handler=handler,
handler_type=handler_type,
title=title,
title=title or url_name.replace("_", " ").title(),
index=index,
)
for url_name, final_url in final_urls.items()
Expand Down Expand Up @@ -950,7 +947,7 @@ def register_controllers(
UrlMap = url_map_maker(root_url)
url_maps = [UrlMap(**kwargs) for name, kwargs in names.items()]

# Add a catch all endpoint for any URL following the app's root URL and map it to the named controller
# Add a catch-all endpoint for any URL following the app's root URL and map it to the named controller
if catch_all and catch_all in names:
url_maps.append(
UrlMap(
Expand Down

0 comments on commit 9fd110b

Please sign in to comment.