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 30, 2018
1 parent 1c4dd79 commit d5e6562
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sitetree/sitetreeapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,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
32 changes: 32 additions & 0 deletions sitetree/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,35 @@ 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/"

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

item = TreeItem(tree=tree1, alias='other', url='contacts_china', urlaspattern=True, pk=6)
assert st.url(item) == "#unresolved"

# Test that any of the symbols inserted as url don't break the app
item = TreeItem(tree=tree1, alias='other', url='!contacts_china$%^čř%*#$@=!§¨`°"', urlaspattern=True, pk=7)
assert st.url(item) == "#unresolved"

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

0 comments on commit d5e6562

Please sign in to comment.