22
33import io
44import tarfile
5+ from urllib .parse import urljoin
56
67import pytest
8+ import requests
79
810from pulp_python .tests .functional .constants import PYTHON_SM_PROJECT_SPECIFIER
911
@@ -63,7 +65,9 @@ def test_package_list(python_repo_with_sync, python_remote_factory, catalog):
6365
6466
6567@pytest .mark .parallel
66- def test_package_list_snapshots (python_bindings , python_repo_with_sync , monitor_task ):
68+ def test_package_list_snapshots (
69+ bindings_cfg , python_bindings , python_repo_with_sync , python_repo_factory , monitor_task
70+ ):
6771 """Metadata and update times use only files in the requested repository version."""
6872 repo = python_repo_with_sync ()
6973 repositories = python_bindings .RepositoriesPythonApi
@@ -81,27 +85,51 @@ def test_package_list_snapshots(python_bindings, python_repo_with_sync, monitor_
8185 original = repositories .packages (repo .pulp_href )
8286 assert original .count == 1
8387 row = original .results [0 ]
88+ response = requests .get (
89+ urljoin (bindings_cfg .host , f"{ repo .pulp_href } packages/" ),
90+ auth = (bindings_cfg .username , bindings_cfg .password ),
91+ )
92+ assert response .status_code == 200
93+ assert response .json ()["results" ][0 ]["versions" ][0 ]["last_updated" ].endswith ("Z" )
8494 assert row .description == sdist .description
85- assert [( item .version , item . last_updated ) for item in row .versions ] == [
86- ( "0.1" , newest . pulp_created )
87- ]
95+ assert [item .version for item in row .versions ] == ["0.1" ]
96+ added = row . versions [ 0 ]. last_updated
97+ assert added >= versions . read ( repo . latest_version_href ). pulp_created
8898
8999 monitor_task (
90100 repositories .modify (repo .pulp_href , {"remove_content_units" : [newest .pulp_href ]}).task
91101 )
92102 current = repositories .packages (repo .pulp_href ).results [0 ]
93- assert current .versions [0 ].last_updated == remaining . pulp_created
103+ assert remaining . pulp_created < current .versions [0 ].last_updated <= added
94104 assert current .description == remaining .description
105+ monitor_task (
106+ repositories .modify (repo .pulp_href , {"add_content_units" : [newest .pulp_href ]}).task
107+ )
108+ readded = repositories .packages (repo .pulp_href ).results [0 ].versions [0 ].last_updated
109+ assert readded > added
110+ other = python_repo_factory ()
111+ monitor_task (
112+ repositories .modify (other .pulp_href , {"add_content_units" : [newest .pulp_href ]}).task
113+ )
114+ assert repositories .packages (repo .pulp_href ).results [0 ].versions [0 ].last_updated == readded
95115 assert versions .packages (repo .latest_version_href ).to_dict () == original .to_dict ()
96116 with pytest .raises (python_bindings .ApiException ) as exc :
97117 versions .packages (f"{ repo .pulp_href } versions/999/" )
98118 assert exc .value .status == 404
99119
100120
101121@pytest .mark .parallel
102- def test_package_list_versions (python_content_factory , python_repo , python_bindings , tmp_path ):
122+ def test_package_list_versions (
123+ python_content_factory ,
124+ python_repo ,
125+ python_bindings ,
126+ python_distribution_factory ,
127+ monitor_task ,
128+ tmp_path ,
129+ ):
103130 """PEP 440 ordering selects metadata and preserves separate rebuild versions."""
104131 content = {}
132+ added_after = {}
105133 for version in ("1.10" , "1.9" , "1.9+test.1" ):
106134 filename = f"catalog-test-{ version } .tar.gz"
107135 path = tmp_path / filename
@@ -113,19 +141,56 @@ def test_package_list_versions(python_content_factory, python_repo, python_bindi
113141 info .size = len (metadata )
114142 archive .addfile (info , io .BytesIO (metadata ))
115143 content [version ] = python_content_factory (filename , file = str (path ), repository = python_repo )
144+ repo = python_bindings .RepositoriesPythonApi .read (python_repo .pulp_href )
145+ added_after [version ] = python_bindings .RepositoriesPythonVersionsApi .read (
146+ repo .latest_version_href
147+ ).pulp_created
116148
117149 data = python_bindings .RepositoriesPythonApi .packages (python_repo .pulp_href )
118150 assert data .count == 1
119151 row = data .results [0 ]
120152 assert row .description .strip () == "Version 1.10"
121- assert [(item .version , item .last_updated ) for item in row .versions ] == [
122- (version , content [version ].pulp_created ) for version in ("1.10" , "1.9+test.1" , "1.9" )
123- ]
153+ assert [item .version for item in row .versions ] == ["1.10" , "1.9+test.1" , "1.9" ]
154+ for item in row .versions :
155+ assert item .last_updated >= added_after [item .version ]
156+ assert item .last_updated > content [item .version ].pulp_created
157+ distro = python_distribution_factory (repository = python_repo )
158+ monitor_task (
159+ python_bindings .PypiYankApi .yank (
160+ path = distro .base_path , yank = {"name" : "catalog-test" , "version" : "1.10" }
161+ ).task
162+ )
163+ row = python_bindings .RepositoriesPythonApi .packages (python_repo .pulp_href ).results [0 ]
164+ assert [item .version for item in row .versions ] == ["1.9+test.1" , "1.9" ]
165+ assert row .description .strip () == "Version 1.9+test.1"
166+
167+
168+ @pytest .mark .parallel
169+ def test_package_list_yanked (
170+ python_bindings , python_repo_with_sync , python_distribution_factory , monitor_task , catalog
171+ ):
172+ """Yank markers exclude versions only from repository versions containing them."""
173+ repo = python_repo_with_sync ()
174+ distro = python_distribution_factory (repository = repo )
175+ monitor_task (
176+ python_bindings .PypiYankApi .yank (
177+ path = distro .base_path , yank = {"name" : "shelf-reader" , "version" : "0.1" }
178+ ).task
179+ )
180+ historical = python_bindings .RepositoriesPythonVersionsApi .packages (repo .latest_version_href )
181+ assert historical .count == 1
182+ latest = python_bindings .RepositoriesPythonApi .read (repo .pulp_href )
183+ excluded = catalog (latest )
184+ assert excluded .count == 0
185+ assert excluded .results == []
124186
125187
126188@pytest .mark .parallel
189+ @pytest .mark .parametrize (
190+ "catalog, denied_status" , [("repository" , 404 ), ("version" , 403 )], indirect = ["catalog" ]
191+ )
127192def test_package_list_permissions (
128- python_bindings , python_repo , python_repo_factory , gen_user , catalog
193+ python_bindings , python_repo , python_repo_factory , gen_user , catalog , denied_status
129194):
130195 """Both actions require view permission on the parent repository."""
131196 other = python_repo_factory ()
@@ -134,7 +199,7 @@ def test_package_list_permissions(
134199 assert catalog (python_repo ).results == []
135200 with pytest .raises (python_bindings .ApiException ) as exc :
136201 catalog (other )
137- assert exc .value .status in ( 403 , 404 )
202+ assert exc .value .status == denied_status
138203 with gen_user (model_roles = ["python.pythonrepository_viewer" ]):
139204 assert catalog (other ).results == []
140205
0 commit comments