Skip to content

Commit

Permalink
fix idlesign#257 and test various url patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Oct 28, 2018
1 parent 1c4dd79 commit 55da7de
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sitetree/sitetreeapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ def url(self, sitetree_item, context=None):
view_path = url
all_arguments = []

view_path = view_path.strip('"\'')

if ' ' in url:
view_path = url.split(' ')
# We should try to resolve URL parameters from site tree item.
Expand All @@ -682,7 +684,7 @@ def url(self, sitetree_item, context=None):
# We enclose arg in double quotes as already resolved.
all_arguments.append('"%s"' % resolved)

view_path = view_path[0].strip('"\' ')
view_path = view_path[0].strip()

url_pattern = "'%s' %s" % (view_path, ' '.join(all_arguments))

Expand Down
22 changes: 22 additions & 0 deletions sitetree/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,25 @@ def test_model_tree_item():

with pytest.raises(Exception):
TreeItem(tree=tree1, alias='only').save() # Unique alias within tree


def test_sitetree_url():
""" Few simple tests to ensure SiteTree.url function works properly """
from sitetree.models import Tree, TreeItem
from sitetree.sitetreeapp import get_sitetree
tree1 = Tree(alias='test')
tree1.save()
st = get_sitetree()

item = TreeItem(tree=tree1, alias='other', url='foo', pk=1)
assert st.url(item) == "foo"

item = TreeItem(tree=tree1, alias='other', url='foo/bar', pk=2)
assert st.url(item) == "foo/bar"

item = TreeItem(tree=tree1, alias='other', url='contacts_china \'2\'', urlaspattern=True, pk=3)
assert st.url(item) == "/contacts/australia/2/"

# Test for bug #257
item = TreeItem(tree=tree1, alias='other', url='contacts_china\'', urlaspattern=True, pk=4)
assert st.url(item) == "#unresolved"

0 comments on commit 55da7de

Please sign in to comment.