|
10 | 10 | PYTHON_MD_PYPI_SUMMARY, |
11 | 11 | PYTHON_EGG_FILENAME, |
12 | 12 | PYTHON_EGG_SHA256, |
| 13 | + PYTHON_WHEEL_FILENAME, |
13 | 14 | PYTHON_WHEEL_SHA256, |
| 15 | + PYTHON_WHEEL_URL, |
| 16 | + PYTHON_XS_PROJECT_SPECIFIER, |
14 | 17 | SHELF_PYTHON_JSON, |
15 | 18 | ) |
| 19 | +from pulpcore.pytest_plugin import pulp_content_url |
16 | 20 |
|
17 | 21 |
|
18 | 22 | PYPI_LAST_SERIAL = "X-PYPI-LAST-SERIAL" |
@@ -137,6 +141,110 @@ def test_package_upload_simple( |
137 | 141 | assert summary.added["python.python"]["count"] == 1 |
138 | 142 |
|
139 | 143 |
|
| 144 | +# todo: tests + moving |
| 145 | +# PythonPackageSingleArtifactContentUploadViewSet - create |
| 146 | +def test_wheel_package_upload_with_metadata_1( |
| 147 | + delete_orphans_pre, |
| 148 | + pulp_content_url, |
| 149 | + python_content_factory, |
| 150 | + python_distribution_factory, |
| 151 | + python_repo, |
| 152 | +): |
| 153 | + # pdb.set_trace() |
| 154 | + python_content_factory( |
| 155 | + repository=python_repo, relative_path=PYTHON_WHEEL_FILENAME, url=PYTHON_WHEEL_URL |
| 156 | + ) |
| 157 | + distro = python_distribution_factory(repository=python_repo) |
| 158 | + |
| 159 | + # Test that metadata is accessible |
| 160 | + relative_path = f"{distro.base_path}/{PYTHON_WHEEL_FILENAME}.metadata" |
| 161 | + metadata_url = urljoin(pulp_content_url, relative_path) |
| 162 | + metadata_response = requests.get(metadata_url) |
| 163 | + assert metadata_response.status_code == 200 |
| 164 | + assert len(metadata_response.content) > 0 |
| 165 | + assert "Name: shelf-reader" in metadata_response.text |
| 166 | + |
| 167 | + |
| 168 | +# PythonPackageSingleArtifactContentUploadViewSet - upload |
| 169 | +def test_wheel_package_upload_with_metadata_2( |
| 170 | + delete_orphans_pre, |
| 171 | + download_python_file, |
| 172 | + monitor_task, |
| 173 | + pulp_content_url, |
| 174 | + python_bindings, |
| 175 | + python_distribution_factory, |
| 176 | + python_repo, |
| 177 | +): |
| 178 | + python_file = download_python_file(PYTHON_WHEEL_FILENAME, PYTHON_WHEEL_URL) |
| 179 | + content_body = {"file": python_file} |
| 180 | + content = python_bindings.ContentPackagesApi.upload(**content_body) |
| 181 | + |
| 182 | + body = {"add_content_units": [content.pulp_href]} |
| 183 | + monitor_task(python_bindings.RepositoriesPythonApi.modify(python_repo.pulp_href, body).task) |
| 184 | + distro = python_distribution_factory(repository=python_repo) |
| 185 | + |
| 186 | + # Test that metadata is accessible |
| 187 | + relative_path = f"{distro.base_path}/{PYTHON_WHEEL_FILENAME}.metadata" |
| 188 | + metadata_url = urljoin(pulp_content_url, relative_path) |
| 189 | + metadata_response = requests.get(metadata_url) |
| 190 | + assert metadata_response.status_code == 200 |
| 191 | + assert len(metadata_response.content) > 0 |
| 192 | + assert "Name: shelf-reader" in metadata_response.text |
| 193 | + |
| 194 | + |
| 195 | +# PythonRepositoryViewSet - sync |
| 196 | +def test_wheel_package_upload_with_metadata_3( |
| 197 | + delete_orphans_pre, |
| 198 | + pulp_content_url, |
| 199 | + python_distribution_factory, |
| 200 | + python_remote_factory, |
| 201 | + python_repo_with_sync, |
| 202 | +): |
| 203 | + remote = python_remote_factory(includes=PYTHON_XS_PROJECT_SPECIFIER) |
| 204 | + repo = python_repo_with_sync(remote) |
| 205 | + distro = python_distribution_factory(repository=repo) |
| 206 | + |
| 207 | + # Test that metadata is accessible |
| 208 | + relative_path = f"{distro.base_path}/{PYTHON_WHEEL_FILENAME}.metadata" |
| 209 | + metadata_url = urljoin(pulp_content_url, relative_path) |
| 210 | + metadata_response = requests.get(metadata_url) |
| 211 | + assert metadata_response.status_code == 200 |
| 212 | + assert len(metadata_response.content) > 0 |
| 213 | + assert "Name: shelf-reader" in metadata_response.text |
| 214 | + |
| 215 | + |
| 216 | +# SimpleView - create |
| 217 | +def test_wheel_package_upload_with_metadata_4( |
| 218 | + delete_orphans_pre, |
| 219 | + monitor_task, |
| 220 | + pulp_content_url, |
| 221 | + python_content_summary, |
| 222 | + python_empty_repo_distro, |
| 223 | + python_package_dist_directory, |
| 224 | +): |
| 225 | + repo, distro = python_empty_repo_distro() |
| 226 | + url = urljoin(distro.base_url, "simple/") |
| 227 | + dist_dir, egg_file, wheel_file = python_package_dist_directory |
| 228 | + response = requests.post( |
| 229 | + url, |
| 230 | + data={"sha256_digest": PYTHON_WHEEL_SHA256}, |
| 231 | + files={"content": open(wheel_file, "rb")}, |
| 232 | + auth=("admin", "password"), |
| 233 | + ) |
| 234 | + assert response.status_code == 202 |
| 235 | + monitor_task(response.json()["task"]) |
| 236 | + summary = python_content_summary(repository=repo) |
| 237 | + assert summary.added["python.python"]["count"] == 1 |
| 238 | + |
| 239 | + # Test that metadata is accessible |
| 240 | + relative_path = f"{distro.base_path}/{PYTHON_WHEEL_FILENAME}.metadata" |
| 241 | + metadata_url = urljoin(pulp_content_url, relative_path) |
| 242 | + metadata_response = requests.get(metadata_url) |
| 243 | + assert metadata_response.status_code == 200 |
| 244 | + assert len(metadata_response.content) > 0 |
| 245 | + assert "Name: shelf-reader" in metadata_response.text |
| 246 | + |
| 247 | + |
140 | 248 | @pytest.mark.parallel |
141 | 249 | def test_twine_upload( |
142 | 250 | pulpcore_bindings, |
|
0 commit comments