|
2 | 2 | import uuid |
3 | 3 |
|
4 | 4 | from pulp_smash.pulp3.utils import gen_distribution, gen_repo |
| 5 | +from pulp_python.tests.functional.constants import PYTHON_EGG_FILENAME, PYTHON_URL |
5 | 6 | from pulp_python.tests.functional.utils import gen_python_remote |
6 | 7 |
|
7 | 8 | from pulpcore.client.pulp_python import ( |
@@ -130,6 +131,38 @@ def _gen_python_repo_sync(remote=None, mirror=False, repository=None, **body): |
130 | 131 | yield _gen_python_repo_sync |
131 | 132 |
|
132 | 133 |
|
| 134 | +@pytest.fixture |
| 135 | +def download_python_file(tmp_path, http_get): |
| 136 | + """Download a Python file and return its path.""" |
| 137 | + def _download_python_file(relative_path, url): |
| 138 | + file_path = tmp_path / relative_path |
| 139 | + with open(file_path, mode="wb") as f: |
| 140 | + f.write(http_get(url)) |
| 141 | + return file_path |
| 142 | + |
| 143 | + yield _download_python_file |
| 144 | + |
| 145 | + |
| 146 | +@pytest.fixture |
| 147 | +def python_content_factory(python_content_api_client, download_python_file, monitor_task): |
| 148 | + """A factory to create a Python Package Content.""" |
| 149 | + def _gen_python_content(relative_path=PYTHON_EGG_FILENAME, url=None, **body): |
| 150 | + body["relative_path"] = relative_path |
| 151 | + if url: |
| 152 | + body["file"] = download_python_file(relative_path, url) |
| 153 | + elif not any(x in body for x in ("artifact", "file", "upload")): |
| 154 | + body["file"] = download_python_file(PYTHON_EGG_FILENAME, PYTHON_URL) |
| 155 | + if repo := body.get("repository"): |
| 156 | + repo_href = repo if isinstance(repo, str) else repo.pulp_href |
| 157 | + body["repository"] = repo_href |
| 158 | + |
| 159 | + task = python_content_api_client.create(**body).task |
| 160 | + response = monitor_task(task) |
| 161 | + return python_content_api_client.read(response.created_resources[0]) |
| 162 | + |
| 163 | + yield _gen_python_content |
| 164 | + |
| 165 | + |
133 | 166 | @pytest.fixture |
134 | 167 | def python_content_summary(python_repo_api_client, python_repo_version_api_client): |
135 | 168 | """Get a summary of the repository version's content.""" |
|
0 commit comments