2014-06-13 13:28:05 +02:00
|
|
|
import pytest
|
|
|
|
|
2014-05-07 01:25:44 +02:00
|
|
|
from pip.download import PipSession
|
2014-09-20 01:27:16 +02:00
|
|
|
from pip.index import HTMLPage
|
2013-11-06 18:35:57 +01:00
|
|
|
from pip.index import PackageFinder, Link, INSTALLED_VERSION
|
2011-02-10 02:28:34 +01:00
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2015-04-06 20:18:22 +02:00
|
|
|
def test_sort_locations_file_expand_dir(data):
|
2012-09-17 02:45:16 +02:00
|
|
|
"""
|
2015-04-06 20:18:22 +02:00
|
|
|
Test that a file:// dir gets listdir run with expand_dir
|
2012-09-17 02:45:16 +02:00
|
|
|
"""
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder([data.find_links], [], session=PipSession())
|
2015-04-06 20:18:22 +02:00
|
|
|
files, urls = finder._sort_locations([data.find_links], expand_dir=True)
|
2014-01-28 15:17:51 +01:00
|
|
|
assert files and not urls, (
|
|
|
|
"files and not urls should have been found at find-links url: %s" %
|
|
|
|
data.find_links
|
|
|
|
)
|
2012-09-17 07:42:30 +02:00
|
|
|
|
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_sort_locations_file_not_find_link(data):
|
2012-09-17 07:42:30 +02:00
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
Test that a file:// url dir that's not a find-link, doesn't get a listdir
|
|
|
|
run
|
2012-09-17 07:42:30 +02:00
|
|
|
"""
|
2014-05-07 01:25:44 +02:00
|
|
|
finder = PackageFinder([], [], session=PipSession())
|
2013-08-23 13:12:37 +02:00
|
|
|
files, urls = finder._sort_locations(data.index_url("empty_with_pkg"))
|
2012-09-17 07:42:30 +02:00
|
|
|
assert urls and not files, "urls, but not files should have been found"
|
2012-09-17 02:45:16 +02:00
|
|
|
|
|
|
|
|
2013-11-06 18:35:57 +01:00
|
|
|
def test_INSTALLED_VERSION_greater():
|
|
|
|
"""Test INSTALLED_VERSION compares greater."""
|
|
|
|
assert INSTALLED_VERSION > Link("some link")
|
2013-11-15 01:35:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestLink(object):
|
|
|
|
|
|
|
|
def test_splitext(self):
|
|
|
|
assert ('wheel', '.whl') == Link('http://yo/wheel.whl').splitext()
|
|
|
|
|
2014-12-19 01:44:26 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("url", "expected"),
|
|
|
|
[
|
|
|
|
("http://yo/wheel.whl", "wheel.whl"),
|
|
|
|
("http://yo/wheel", "wheel"),
|
|
|
|
(
|
|
|
|
"http://yo/myproject-1.0%2Bfoobar.0-py2.py3-none-any.whl",
|
|
|
|
"myproject-1.0+foobar.0-py2.py3-none-any.whl",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_filename(self, url, expected):
|
|
|
|
assert Link(url).filename == expected
|
2013-11-15 01:35:24 +01:00
|
|
|
|
|
|
|
def test_no_ext(self):
|
|
|
|
assert '' == Link('http://yo/wheel').ext
|
|
|
|
|
|
|
|
def test_ext(self):
|
|
|
|
assert '.whl' == Link('http://yo/wheel.whl').ext
|
|
|
|
|
|
|
|
def test_ext_fragment(self):
|
|
|
|
assert '.whl' == Link('http://yo/wheel.whl#frag').ext
|
|
|
|
|
|
|
|
def test_ext_query(self):
|
|
|
|
assert '.whl' == Link('http://yo/wheel.whl?a=b').ext
|
2014-06-13 13:28:05 +02:00
|
|
|
|
2014-12-28 23:52:32 +01:00
|
|
|
def test_is_wheel(self):
|
|
|
|
assert Link('http://yo/wheel.whl').is_wheel
|
|
|
|
|
2015-03-06 23:46:44 +01:00
|
|
|
def test_is_wheel_false(self):
|
|
|
|
assert not Link('http://yo/not_a_wheel').is_wheel
|
|
|
|
|
2014-06-13 13:28:05 +02:00
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("html", "url", "expected"),
|
|
|
|
[
|
|
|
|
("<html></html>", "https://example.com/", "https://example.com/"),
|
|
|
|
(
|
|
|
|
"<html><head>"
|
|
|
|
"<base href=\"https://foo.example.com/\">"
|
|
|
|
"</head></html>",
|
|
|
|
"https://example.com/",
|
|
|
|
"https://foo.example.com/",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"<html><head>"
|
|
|
|
"<base><base href=\"https://foo.example.com/\">"
|
|
|
|
"</head></html>",
|
|
|
|
"https://example.com/",
|
|
|
|
"https://foo.example.com/",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_base_url(html, url, expected):
|
|
|
|
assert HTMLPage(html, url).base_url == expected
|
2014-08-11 06:21:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MockLogger(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.called = False
|
|
|
|
|
2014-12-10 01:40:05 +01:00
|
|
|
def warning(self, *args, **kwargs):
|
2014-08-11 06:21:02 +02:00
|
|
|
self.called = True
|
|
|
|
|
|
|
|
|
2014-12-10 01:40:05 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("location", "trusted", "expected"),
|
|
|
|
[
|
|
|
|
("http://pypi.python.org/something", [], True),
|
|
|
|
("https://pypi.python.org/something", [], False),
|
|
|
|
("http://localhost", [], False),
|
|
|
|
("http://127.0.0.1", [], False),
|
|
|
|
("http://example.com/something/", [], True),
|
|
|
|
("http://example.com/something/", ["example.com"], False),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_secure_origin(location, trusted, expected):
|
|
|
|
finder = PackageFinder([], [], session=[], trusted_hosts=trusted)
|
|
|
|
logger = MockLogger()
|
|
|
|
finder._validate_secure_origin(logger, location)
|
|
|
|
assert logger.called == expected
|