def test_rel_navigate(): for suffix, expected in REL_URL_TEST_CASES: url = URL(REL_URL_BASE) new_url = url.navigate(suffix) assert new_url.to_text() == expected new_url = url.navigate(URL(suffix)) assert new_url.to_text() == expected return
def compose_url(base_url, url): base_url = URL(base_url) url = URL(url) if not url.scheme: absolute_url = base_url.navigate(url.to_text()) else: absolute_url = url return absolute_url.to_text()
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()
def test_navigate(): orig_text = u'http://a.b/c/d?e#f' orig = URL(orig_text) navd = orig.navigate('') # fragment removed on empty navigate assert navd.to_text() == u'http://a.b/c/d?e' # query also removed on non-empty navigate (interp'd as rel path) navd = orig.navigate('dd') assert navd.to_text() == u'http://a.b/c/dd' # check trailing slash navd = orig.navigate('dd/') assert navd.to_text() == u'http://a.b/c/dd/' # path removed on absolute path navigate navd = orig.navigate('/C') assert navd.to_text() == u'http://a.b/C' # only query string navd = orig.navigate('?e=E&ee=EE') assert navd.to_text() == u'http://a.b/c/d?e=E&ee=EE' # only fragment navd = orig.navigate('#FFF') assert navd.to_text() == u'http://a.b/c/d?e#FFF' # an odd case, bears more consideration perhaps navd = orig.navigate('https:') assert navd.to_text() == u'https://a.b/c/d?e' # another odd one, host only navd = orig.navigate('//newhost') assert navd.to_text() == u'http://newhost/c/d?e' # absolute URLs (with scheme + host) replace everything _dest_text = u'http://hatnote.com' _dest = URL(_dest_text) navd = orig.navigate(_dest) assert _dest is not navd # make sure copies are made assert navd.to_text() == _dest_text navd = orig.navigate(_dest_text) assert navd.to_text() == _dest_text