|
1 | 1 | import pytest |
2 | 2 | import requests |
3 | 3 | import subprocess |
4 | | - |
| 4 | +import time |
5 | 5 | from pulp_python.tests.functional.constants import ( |
6 | 6 | PYPI_URL, |
7 | 7 | PYTHON_XS_FIXTURE_CHECKSUMS, |
|
12 | 12 | from pypi_simple import ProjectPage |
13 | 13 | from packaging.version import parse |
14 | 14 | from urllib.parse import urljoin, urlsplit |
| 15 | +from random import sample |
15 | 16 |
|
16 | 17 |
|
17 | 18 | def test_pull_through_install( |
@@ -97,17 +98,48 @@ def test_pull_through_filter(python_remote_factory, python_distribution_factory) |
97 | 98 |
|
98 | 99 | @pytest.mark.parallel |
99 | 100 | def test_pull_through_with_repo( |
100 | | - python_repo_with_sync, python_remote_factory, python_distribution_factory |
| 101 | + python_repo_factory, |
| 102 | + python_remote_factory, |
| 103 | + python_distribution_factory, |
| 104 | + python_bindings, |
| 105 | + pulpcore_bindings, |
| 106 | + monitor_task, |
| 107 | + has_pulp_plugin, |
101 | 108 | ): |
102 | | - """Tests that if content is already in repository, pull-through isn't used.""" |
103 | | - remote = python_remote_factory() |
104 | | - repo = python_repo_with_sync(remote) |
| 109 | + """Tests that content is saved to repository.""" |
| 110 | + remote = python_remote_factory(includes=[]) |
| 111 | + repo = python_repo_factory() |
105 | 112 | distro = python_distribution_factory(repository=repo.pulp_href, remote=remote.pulp_href) |
106 | 113 |
|
107 | | - url = urljoin(distro.base_url, "simple/shelf-reader/") |
108 | | - project_page = ProjectPage.from_response(requests.get(url), "shelf-reader") |
109 | | - |
110 | | - assert len(project_page.packages) == 2 |
111 | | - for package in project_page.packages: |
112 | | - assert package.filename in PYTHON_XS_FIXTURE_CHECKSUMS |
113 | | - assert "?redirect=" not in package.url |
| 114 | + # Perform a download of aiohttp to ensure it's saved to the repo |
| 115 | + url = urljoin(distro.base_url, "simple/aiohttp/") |
| 116 | + project_page = ProjectPage.from_response(requests.get(url), "aiohttp") |
| 117 | + for package in sample(project_page.packages, 3): |
| 118 | + assert "?redirect=" in package.url |
| 119 | + r = requests.get(package.url) |
| 120 | + assert r.status_code == 200 |
| 121 | + |
| 122 | + if has_pulp_plugin("core", max="3.73"): |
| 123 | + pytest.skip("Pull-through repository save added in 3.74") |
| 124 | + |
| 125 | + for _ in range(3): |
| 126 | + tasks = pulpcore_bindings.TasksApi.list(reserved_resources=repo.prn) |
| 127 | + if tasks.count == 3: |
| 128 | + break |
| 129 | + time.sleep(1) # Wait for tasks to be created |
| 130 | + else: |
| 131 | + assert tasks.count == 3 |
| 132 | + |
| 133 | + for task in tasks.results: |
| 134 | + monitor_task(task.pulp_href) |
| 135 | + |
| 136 | + repo = python_bindings.RepositoriesPythonApi.read(repo.pulp_href) |
| 137 | + assert repo.latest_version_href[-2] == "3" |
| 138 | + content = python_bindings.ContentPackagesApi.list(repository_version=repo.latest_version_href) |
| 139 | + assert content.count == 3 |
| 140 | + |
| 141 | + # Check that getting content that is already present doesn't trigger a task |
| 142 | + r = requests.get(package.url) |
| 143 | + assert r.status_code == 200 |
| 144 | + tasks = pulpcore_bindings.TasksApi.list(reserved_resources=repo.prn) |
| 145 | + assert tasks.count == 3 |
0 commit comments