55import pytest
66
77from tests .lib import PipTestEnvironment , TestData
8+ from tests .lib .server import (
9+ file_response ,
10+ make_mock_server ,
11+ package_page ,
12+ server_running ,
13+ )
814
915
1016class TestUploadedPriorTo :
11- """Test --uploaded-prior-to functionality.
12-
13- Only effective with indexes that provide upload-time metadata.
14- """
17+ """Test --uploaded-prior-to functionality."""
1518
1619 def test_uploaded_prior_to_invalid_date (
1720 self , script : PipTestEnvironment , data : TestData
1821 ) -> None :
19- """Test that --uploaded-prior-to fails with invalid date format."""
22+ """Test that invalid date format is rejected ."""
2023 result = script .pip_install_local (
2124 "--uploaded-prior-to=invalid-date" , "simple" , expect_error = True
2225 )
23-
24- # Should fail with date parsing error
2526 assert "invalid" in result .stderr .lower () or "error" in result .stderr .lower ()
2627
28+ def test_uploaded_prior_to_file_index_no_upload_time (
29+ self , script : PipTestEnvironment , data : TestData
30+ ) -> None :
31+ """Test that file:// indexes are exempt from upload-time filtering."""
32+ result = script .pip (
33+ "install" ,
34+ "--index-url" ,
35+ data .index_url ("simple" ),
36+ "--uploaded-prior-to=3030-01-01T00:00:00" ,
37+ "simple" ,
38+ expect_error = False ,
39+ )
40+ assert "Successfully installed simple" in result .stdout
41+
42+ def test_uploaded_prior_to_http_index_no_upload_time (
43+ self , script : PipTestEnvironment , data : TestData
44+ ) -> None :
45+ """Test that HTTP index without upload-time causes immediate error."""
46+ server = make_mock_server ()
47+ simple_package = data .packages / "simple-1.0.tar.gz"
48+ server .mock .side_effect = [
49+ package_page ({"simple-1.0.tar.gz" : "/files/simple-1.0.tar.gz" }),
50+ file_response (simple_package ),
51+ ]
52+
53+ with server_running (server ):
54+ result = script .pip (
55+ "install" ,
56+ "--index-url" ,
57+ f"http://{ server .host } :{ server .port } " ,
58+ "--uploaded-prior-to=3030-01-01T00:00:00" ,
59+ "simple" ,
60+ expect_error = True ,
61+ )
62+
63+ assert "does not provide upload-time metadata" in result .stderr
64+ assert "--uploaded-prior-to" in result .stderr or "Cannot use" in result .stderr
65+
2766 @pytest .mark .network
2867 def test_uploaded_prior_to_with_real_pypi (self , script : PipTestEnvironment ) -> None :
29- """Test uploaded-prior-to functionality against real PyPI with upload times."""
30- # Use a small package with known old versions for testing
31- # requests 2.0.0 was released in 2013
32-
33- # Test 1: With an old cutoff date, should find no matching versions
68+ """Test filtering against real PyPI with upload-time metadata."""
69+ # Test with old cutoff date - should find no matching versions
3470 result = script .pip (
3571 "install" ,
3672 "--dry-run" ,
@@ -39,10 +75,9 @@ def test_uploaded_prior_to_with_real_pypi(self, script: PipTestEnvironment) -> N
3975 "requests==2.0.0" ,
4076 expect_error = True ,
4177 )
42- # Should fail because requests 2.0.0 was uploaded after 2010
43- assert "No matching distribution found" in result .stderr
78+ assert "Could not find a version that satisfies" in result .stderr
4479
45- # Test 2: With a date that should find the package
80+ # Test with future cutoff date - should find the package
4681 result = script .pip (
4782 "install" ,
4883 "--dry-run" ,
@@ -55,8 +90,7 @@ def test_uploaded_prior_to_with_real_pypi(self, script: PipTestEnvironment) -> N
5590
5691 @pytest .mark .network
5792 def test_uploaded_prior_to_date_formats (self , script : PipTestEnvironment ) -> None :
58- """Test different date formats work with real PyPI."""
59- # Test various date formats with a well known small package
93+ """Test various date format strings are accepted."""
6094 formats = [
6195 "2030-01-01" ,
6296 "2030-01-01T00:00:00" ,
@@ -73,5 +107,34 @@ def test_uploaded_prior_to_date_formats(self, script: PipTestEnvironment) -> Non
73107 "requests==2.0.0" ,
74108 expect_error = False ,
75109 )
76- # All dates should allow the package
77110 assert "Would install requests-2.0.0" in result .stdout
111+
112+ def test_uploaded_prior_to_allows_local_files (
113+ self , script : PipTestEnvironment , data : TestData
114+ ) -> None :
115+ """Test that local file installs bypass upload-time filtering."""
116+ simple_wheel = data .packages / "simplewheel-1.0-py2.py3-none-any.whl"
117+
118+ result = script .pip (
119+ "install" ,
120+ "--no-index" ,
121+ "--uploaded-prior-to=2000-01-01T00:00:00" ,
122+ str (simple_wheel ),
123+ expect_error = False ,
124+ )
125+ assert "Successfully installed simplewheel-1.0" in result .stdout
126+
127+ def test_uploaded_prior_to_allows_find_links (
128+ self , script : PipTestEnvironment , data : TestData
129+ ) -> None :
130+ """Test that --find-links bypasses upload-time filtering."""
131+ result = script .pip (
132+ "install" ,
133+ "--no-index" ,
134+ "--find-links" ,
135+ data .find_links ,
136+ "--uploaded-prior-to=2000-01-01T00:00:00" ,
137+ "simple==1.0" ,
138+ expect_error = False ,
139+ )
140+ assert "Successfully installed simple-1.0" in result .stdout
0 commit comments