Skip to content

Commit

Permalink
Chaining boltons.urlutils.URL.navigate() results in TypeError (#298)
Browse files Browse the repository at this point in the history
* Add test cases for issue #158

* Fix TypeError w/issue #158 and PR #159

This makes only one more test pass (now only 3 failing) but at least
prevents the `TypeError` when attempting to add a `list` and a `tuple`.

* Fix: Expected results should be `https://host/b`

* Provide parameters via `path`

* Move test case after `test_navigate`

Co-authored-by: Wil Cooley <wcooley@nakedape.cc>
  • Loading branch information
allanlei and wcooley authored Jan 15, 2022
1 parent 270e974 commit 395f690
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion boltons/urlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ def navigate(self, dest):
if dest.path.startswith(u'/'): # absolute path
new_path_parts = list(dest.path_parts)
else: # relative path
new_path_parts = self.path_parts[:-1] + dest.path_parts
new_path_parts = list(self.path_parts[:-1]) \
+ list(dest.path_parts)
else:
new_path_parts = list(self.path_parts)
if not query_params:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_urlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,25 @@ def test_navigate():
assert navd.to_text() == _dest_text


@pytest.mark.parametrize(
('expected', 'base', 'paths'), [
('https://host/b', 'https://host', ('a', '/b', )),
('https://host/b', 'https://host', ('a', 'b', )),
('https://host/a/b', 'https://host', ('a/', 'b', )),
('https://host/b', 'https://host', ('/a', 'b', )),
('https://host/a/b', 'https://host/a/', (None, 'b', )),
('https://host/b', 'https://host/a', (None, 'b', )),
])
def test_chained_navigate(expected, base, paths):
"""Chained :meth:`navigate` calls produces correct results."""
url = URL(base)

for path in paths:
url = url.navigate(path)

assert expected == url.to_text()


# TODO: RFC3986 6.2.3 (not just for query add, either)
# def test_add_query():
# url = URL('http://www.example.com')
Expand Down

0 comments on commit 395f690

Please sign in to comment.