11import pytest
2+ import uuid
23
34from pulp_smash .pulp3 .utils import gen_distribution , gen_repo
45from pulp_python .tests .functional .utils import gen_python_remote
910 DistributionsPypiApi ,
1011 PublicationsPypiApi ,
1112 RepositoriesPythonApi ,
13+ RepositoriesPythonVersionsApi ,
1214 RemotesPythonApi ,
1315)
1416
@@ -28,6 +30,10 @@ def python_repo_api_client(python_bindings_client):
2830 """Provides the Python Repository API client object."""
2931 return RepositoriesPythonApi (python_bindings_client )
3032
33+ @pytest .fixture
34+ def python_repo_version_api_client (python_bindings_client ):
35+ """Provides the Python Repository Version API client object."""
36+ return RepositoriesPythonVersionsApi (python_bindings_client )
3137
3238@pytest .fixture
3339def python_distro_api_client (python_bindings_client ):
@@ -55,6 +61,16 @@ def python_publication_api_client(python_bindings_client):
5561
5662# Object Generation Fixtures
5763
64+ @pytest .fixture
65+ def python_repo_factory (python_repo_api_client , gen_object_with_cleanup ):
66+ """A factory to generate a Python Repository with auto-cleanup."""
67+ def _gen_python_repo (** kwargs ):
68+ kwargs .setdefault ("name" , str (uuid .uuid4 ()))
69+ return gen_object_with_cleanup (python_repo_api_client , kwargs )
70+
71+ return _gen_python_repo
72+
73+
5874@pytest .fixture
5975def python_repo (python_repo_api_client , gen_object_with_cleanup ):
6076 """Creates a Python Repository and deletes it at test cleanup time."""
@@ -92,3 +108,43 @@ def _gen_python_remote(**kwargs):
92108 return gen_object_with_cleanup (python_remote_api_client , body )
93109
94110 yield _gen_python_remote
111+
112+
113+ @pytest .fixture
114+ def python_repo_with_sync (
115+ python_repo_api_client , python_repo_factory , python_remote_factory , monitor_task
116+ ):
117+ """A factory to generate a Python Repository synced with the passed in Remote."""
118+ def _gen_python_repo_sync (remote = None , mirror = False , repository = None , ** body ):
119+ kwargs = {}
120+ if pulp_domain := body .get ("pulp_domain" ):
121+ kwargs ["pulp_domain" ] = pulp_domain
122+ remote = remote or python_remote_factory (** kwargs )
123+ repo = repository or python_repo_factory (** body )
124+ sync_body = {"mirror" : mirror , "remote" : remote .pulp_href }
125+ monitor_task (python_repo_api_client .sync (repo .pulp_href , sync_body ).task )
126+ return python_repo_api_client .read (repo .pulp_href )
127+
128+ yield _gen_python_repo_sync
129+
130+
131+ @pytest .fixture
132+ def python_content_summary (python_repo_api_client , python_repo_version_api_client ):
133+ """Get a summary of the repository version's content."""
134+ def _gen_summary (repository_version = None , repository = None , version = None ):
135+ if repository_version is None :
136+ repo_href = get_href (repository )
137+ if version :
138+ repo_ver_href = f"{ repo_href } versions/{ version } /"
139+ else :
140+ repo_ver_href = python_repo_api_client .read (repo_href ).latest_version_href
141+ else :
142+ repo_ver_href = get_href (repository_version )
143+ return python_repo_version_api_client .read (repo_ver_href ).content_summary
144+
145+ yield _gen_summary
146+
147+
148+ def get_href (item ):
149+ """Tries to get the href from the given item, whether it is a string or object."""
150+ return item if isinstance (item , str ) else item .pulp_href
0 commit comments