forked from pulp/pulp_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
110 lines (86 loc) · 2.75 KB
/
Copy pathutils.py
File metadata and controls
110 lines (86 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from functools import partial
from unittest import SkipTest
from pulp_smash import api, selectors
from pulp_smash.pulp3 import utils
from pulp_smash.pulp3.constants import REPO_PATH
from pulp_smash.pulp3.utils import (
gen_publisher,
gen_remote,
gen_repo,
get_content,
sync
)
from pulp_python.tests.functional.constants import (
PYTHON_CONTENT_PATH,
PYTHON_XS_PROJECT_SPECIFIER,
PYTHON_FIXTURES_URL,
PYTHON_REMOTE_PATH
)
def set_up_module():
"""
Skip tests Pulp 3 isn't under test or if pulp-python isn't installed.
"""
utils.require_pulp_3(SkipTest)
utils.require_pulp_plugins({'pulp_python'}, SkipTest)
def gen_python_remote(url=PYTHON_FIXTURES_URL, projects=PYTHON_XS_PROJECT_SPECIFIER, **kwargs):
"""
Return a semi-random dict for use in creating a remote.
Kwargs:
url (str): The URL to a Python remote repository
**kwargs: Specified parameters for the Remote
"""
remote = gen_remote(url)
python_extra_fields = {
'projects': projects,
**kwargs,
}
remote.update(python_extra_fields)
return remote
def gen_python_publisher(**kwargs):
"""
Return a semi-random dict for use in creating a publisher.
Kwargs:
**kwargs: Specified parameters for the Publisher
"""
publisher = gen_publisher()
python_extra_fields = {
**kwargs,
}
publisher.update(python_extra_fields)
return publisher
def get_content_unit_paths(repo):
"""
Return the relative path of content units present in a file repository.
Args:
repo (dict): A dict of information about the repository.
Returns:
list: The paths of units present in a given repository.
"""
return [content_unit['filename'] for content_unit in get_content(repo)]
def populate_pulp(cfg, url=None, projects=None):
"""
Add python content to Pulp.
Args:
cfg (pulp_smash.config.PulpSmashConfig): Information about a Pulp application
url (str): The URL to a Python remote repository
Returns:
list: A list of dicts, where each dict describes one python content in Pulp.
"""
if url is None:
url = PYTHON_FIXTURES_URL
if projects is None:
projects = PYTHON_XS_PROJECT_SPECIFIER
client = api.Client(cfg, api.json_handler)
remote = {}
repo = {}
try:
remote.update(client.post(PYTHON_REMOTE_PATH, gen_python_remote(url, projects=projects)))
repo.update(client.post(REPO_PATH, gen_repo()))
sync(cfg, remote, repo)
finally:
if remote:
client.delete(remote['_href'])
if repo:
client.delete(repo['_href'])
return client.get(PYTHON_CONTENT_PATH)['results']
skip_if = partial(selectors.skip_if, exc=SkipTest)