def test_passive_app(passive_app, mock_aioresponse, r_package): package_path = URLPath("/src/contrib/latest_0.7.5.tar.gz") remote_path = passive_app.config.UPSTREAM_CRAN_SERVER_URL.add_path( package_path) mock_aioresponse.get(remote_path, status=200, body=r_package) passive_app.test_client.get(package_path, allow_redirects=False) assert len(mock_aioresponse.requests) == 0
def test_relative_on_a_non_leaf_node(self): path = URLPath('/a/b/c/') assert path.relative('.') == '/a/b/c/' assert path.relative('d') == '/a/b/c/d' assert path.relative('..') == '/a/b/' assert path.relative('../d') == '/a/b/d' assert path.relative('/') == '/' assert path.relative('/d') == '/d'
def test_relative_on_a_leaf_node(self): path = URLPath(u'/a/b/c') assert path.relative(u'.') == u'/a/b/' assert path.relative(u'd') == u'/a/b/d' assert path.relative(u'..') == u'/a/' assert path.relative(u'../d') == u'/a/d' assert path.relative(u'/') == u'/' assert path.relative(u'/d') == u'/d'
def test_get_single_binary_package(app, mock_aioresponse, r_package_binary): package_path = URLPath("/src/contrib/later_0.7.5.tar.gz") remote_path = app.config.UPSTREAM_CRAN_SERVER_URL.add_path(package_path) mock_aioresponse.get(remote_path, status=200, body=r_package_binary) request, response = app.test_client.get(package_path, allow_redirects=False) assert response.status == 302 assert response.headers["location"] == remote_path assert not app.compile_queue.empty()
def url_join(base, *paths): """ Append `paths` to `base`. Path resets on each absolute path. Like os.path.join, but for URLs. """ if not hasattr(base, 'add_path'): base = URLObject(base) for path in paths: path = URLPath(path) base = base.add_path(path) return base
def test_relative_on_a_non_leaf_node(self): path = URLPath(u"/a/b/c/") assert path.relative(u".") == u"/a/b/c/" assert path.relative(u"d") == u"/a/b/c/d" assert path.relative(u"..") == u"/a/b/" assert path.relative(u"../d") == u"/a/b/d" assert path.relative(u"/") == u"/" assert path.relative(u"/d") == u"/d"
def test_get_packages(app, mock_aioresponse): packages_index_path = URLPath("/src/contrib/PACKAGES") remote_path = app.config.UPSTREAM_CRAN_SERVER_URL.add_path( packages_index_path) mock_aioresponse.get(remote_path, status=200) request, response = app.test_client.get(packages_index_path) assert response.status == 200 reqs = {k: v for k, v in mock_aioresponse.requests} # check that remote request was made remote_req = reqs["GET"] assert len(reqs) == 1 assert remote_req.path_qs == packages_index_path
def test_add_encodes_non_ascii_and_reserved_characters(self): assert URLPath('/a/b/c').add( u('d /\N{LATIN SMALL LETTER E WITH ACUTE}') ) == '/a/b/c/d%20/%C3%A9'
def test_preserves_equality_with_original_string(self): assert URLPath('/a/b/c') == '/a/b/c' assert URLPath('a/b/c') == 'a/b/c'
def test_add_segment_adds_path_segments_to_a_path(self): assert URLPath('').add_segment('a') == 'a' assert URLPath('/').add_segment('a') == '/a' assert URLPath('/a/b/c').add_segment('d') == '/a/b/c/d' assert URLPath('/a/b/c').add_segment('d/') == '/a/b/c/d%2F'
def test_parent_of_a_non_leaf_node(self): assert URLPath('/a/b/c/').parent == '/a/b/'
def test_is_leaf_node(self): assert URLPath('/a/b/c').is_leaf assert not URLPath('/a/b/c/').is_leaf
def test_join_segments_can_create_relative_paths(self): assert URLPath.join_segments(('a', 'b', 'c'), absolute=False) == 'a/b/c' assert URLPath.join_segments(('a', 'b', 'c', ''), absolute=False) == 'a/b/c/'
def test_join_segments_encodes_non_ascii_and_special_characters_including_slash(self): URLPath.join_segments((u'a b', u'd/é')) == u'/a%20b/d%2F%C3%A9'
def test_join_segments_can_create_relative_paths(self): URLPath.join_segments((u'a', u'b', u'c'), absolute=False) == u'a/b/c' URLPath.join_segments((u'a', u'b', u'c', u''), absolute=False) == u'a/b/c/'
def test_join_segments_joins_segments_into_a_single_path(self): URLPath.join_segments((u'a', u'b', u'c')) == u'/a/b/c' URLPath.join_segments((u'a', u'b', u'c', u'')) == u'/a/b/c/'
def test_join_segments_encodes_non_ascii_and_special_characters_including_slash(self): URLPath.join_segments((u"a b", u"d/é")) == u"/a%20b/d%2F%C3%A9"
def test_join_segments_can_create_relative_paths(self): URLPath.join_segments((u"a", u"b", u"c"), absolute=False) == u"a/b/c" URLPath.join_segments((u"a", u"b", u"c", u""), absolute=False) == u"a/b/c/"
def test_join_segments_joins_segments_into_a_single_path(self): URLPath.join_segments((u"a", u"b", u"c")) == u"/a/b/c" URLPath.join_segments((u"a", u"b", u"c", u"")) == u"/a/b/c/"
def test_segments_decodes_percent_escapes(self): assert URLPath('/a%20b/c%2Fd/').segments == ('a b', 'c/d', '')
def test_join_segments_joins_segments_into_a_single_path(self): assert URLPath.join_segments(('a', 'b', 'c')) == '/a/b/c' assert URLPath.join_segments(('a', 'b', 'c', '')) == '/a/b/c/'
def test_parent_of_a_leaf_node(self): assert URLPath(u'/a/b/c').parent == u'/a/b/'
def test_join_segments_encodes_non_ascii_and_special_characters_including_slash( self): assert URLPath.join_segments(( 'a b', u('d/\N{LATIN SMALL LETTER E WITH ACUTE}'))) == '/a%20b/d%2F%C3%A9'
def test_is_relative_equals_not_is_absolute(self): assert URLPath('a/b/c').is_relative assert not URLPath('/a/b/c').is_relative assert not URLPath('a/b/c').is_absolute assert URLPath('/a/b/c').is_absolute
def test_add_encodes_non_ascii_and_reserved_characters(self): assert URLPath(u'/a/b/c').add(u'd /é') == u'/a/b/c/d%20/%C3%A9'
def test_root_always_returns_the_root_path(self): assert URLPath.root == '/' assert URLPath('/').root == '/' assert URLPath('/a/b/c').root == '/'
def test_add_segment_encodes_slash_characters(self): assert URLPath('/a/b/c').add_segment('d/e') == '/a/b/c/d%2Fe'
def test_preserves_hash_of_the_original_string(self): assert hash(URLPath('/a/b/c')) == hash('/a/b/c')
def test_add_concatenates_whole_paths(self): assert URLPath('').add('a') == 'a' assert URLPath('/').add('a') == '/a' assert URLPath('/a/b/c').add('d') == '/a/b/c/d' assert URLPath('/a/b/c').add('d/') == '/a/b/c/d/' assert URLPath('/a/b/c').add('d/e/f') == '/a/b/c/d/e/f'
def test_segments_breaks_the_path_into_segments(self): assert URLPath('/a/b/c').segments == ('a', 'b', 'c') assert URLPath('/a/b/c/').segments == ('a', 'b', 'c', '') assert URLPath('a/b/c').segments == ('a', 'b', 'c')
def test_add_does_not_encode_slash_characters(self): assert URLPath('/a/b/c').add('d/e') == '/a/b/c/d/e'
def test_join_segments_encodes_non_ascii_and_special_characters_including_slash(self): assert URLPath.join_segments(('a b', u('d/\N{LATIN SMALL LETTER E WITH ACUTE}'))) == '/a%20b/d%2F%C3%A9'