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
@@ -29,6 +31,12 @@ def python_repo_api_client(python_bindings_client):
2931 return RepositoriesPythonApi (python_bindings_client )
3032
3133
34+ @pytest .fixture
35+ def python_repo_version_api_client (python_bindings_client ):
36+ """Provides the Python Repository Version API client object."""
37+ return RepositoriesPythonVersionsApi (python_bindings_client )
38+
39+
3240@pytest .fixture
3341def python_distro_api_client (python_bindings_client ):
3442 """Provides the Python Distribution API client object."""
@@ -55,6 +63,16 @@ def python_publication_api_client(python_bindings_client):
5563
5664# Object Generation Fixtures
5765
66+ @pytest .fixture
67+ def python_repo_factory (python_repo_api_client , gen_object_with_cleanup ):
68+ """A factory to generate a Python Repository with auto-cleanup."""
69+ def _gen_python_repo (** kwargs ):
70+ kwargs .setdefault ("name" , str (uuid .uuid4 ()))
71+ return gen_object_with_cleanup (python_repo_api_client , kwargs )
72+
73+ return _gen_python_repo
74+
75+
5876@pytest .fixture
5977def python_repo (python_repo_api_client , gen_object_with_cleanup ):
6078 """Creates a Python Repository and deletes it at test cleanup time."""
@@ -92,3 +110,43 @@ def _gen_python_remote(**kwargs):
92110 return gen_object_with_cleanup (python_remote_api_client , body )
93111
94112 yield _gen_python_remote
113+
114+
115+ @pytest .fixture
116+ def python_repo_with_sync (
117+ python_repo_api_client , python_repo_factory , python_remote_factory , monitor_task
118+ ):
119+ """A factory to generate a Python Repository synced with the passed in Remote."""
120+ def _gen_python_repo_sync (remote = None , mirror = False , repository = None , ** body ):
121+ kwargs = {}
122+ if pulp_domain := body .get ("pulp_domain" ):
123+ kwargs ["pulp_domain" ] = pulp_domain
124+ remote = remote or python_remote_factory (** kwargs )
125+ repo = repository or python_repo_factory (** body )
126+ sync_body = {"mirror" : mirror , "remote" : remote .pulp_href }
127+ monitor_task (python_repo_api_client .sync (repo .pulp_href , sync_body ).task )
128+ return python_repo_api_client .read (repo .pulp_href )
129+
130+ yield _gen_python_repo_sync
131+
132+
133+ @pytest .fixture
134+ def python_content_summary (python_repo_api_client , python_repo_version_api_client ):
135+ """Get a summary of the repository version's content."""
136+ def _gen_summary (repository_version = None , repository = None , version = None ):
137+ if repository_version is None :
138+ repo_href = get_href (repository )
139+ if version :
140+ repo_ver_href = f"{ repo_href } versions/{ version } /"
141+ else :
142+ repo_ver_href = python_repo_api_client .read (repo_href ).latest_version_href
143+ else :
144+ repo_ver_href = get_href (repository_version )
145+ return python_repo_version_api_client .read (repo_ver_href ).content_summary
146+
147+ yield _gen_summary
148+
149+
150+ def get_href (item ):
151+ """Tries to get the href from the given item, whether it is a string or object."""
152+ return item if isinstance (item , str ) else item .pulp_href
0 commit comments