Skip to content

Commit 3279ea5

Browse files
authored
Merge pull request #276 from gerrod3/pipinstalltest
Add test for pip install
2 parents 772ddfe + ec540ea commit 3279ea5

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

CHANGES/4682.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added test to check that content served by Pulp can be consumed through pip install
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import unittest
2+
3+
from pulp_smash import api, config, cli
4+
from pulp_smash.pulp3.utils import (
5+
gen_repo,
6+
gen_distribution,
7+
sync,
8+
)
9+
10+
from pulp_python.tests.functional.utils import (
11+
gen_python_publication,
12+
gen_python_remote,
13+
)
14+
15+
from pulp_python.tests.functional.constants import (
16+
PYTHON_FIXTURES_URL,
17+
PYTHON_REMOTE_PATH,
18+
PYTHON_DISTRIBUTION_PATH,
19+
PYTHON_REPO_PATH,
20+
)
21+
22+
from urllib.parse import urlsplit
23+
24+
25+
class PipInstallContentTestCase(unittest.TestCase):
26+
"""
27+
Verify whether content served by Pulp can be consumed through pip install.
28+
"""
29+
30+
def test_install(self):
31+
"""
32+
Verify whether content served by Pulp can be consumed through pip install.
33+
34+
Do the following:
35+
36+
1. Create, populate, publish, and distribute a repository.
37+
2. Pip install a package from the pulp repository.
38+
3. Check pip install was successful.
39+
40+
This test targets the following issues:
41+
* `Pulp #4682 <https://pulp.plan.io/issues/4682>`_
42+
* `Pulp #4677 <https://pulp.plan.io/issues/4677>`_
43+
"""
44+
cfg = config.get_config()
45+
client = api.Client(cfg, api.json_handler)
46+
47+
repo = client.post(PYTHON_REPO_PATH, gen_repo())
48+
self.addCleanup(client.delete, repo["pulp_href"])
49+
50+
body = gen_python_remote(PYTHON_FIXTURES_URL)
51+
remote = client.post(PYTHON_REMOTE_PATH, body)
52+
self.addCleanup(client.delete, remote["pulp_href"])
53+
54+
sync(cfg, remote, repo)
55+
repo = client.get(repo["pulp_href"])
56+
57+
publication = gen_python_publication(cfg, repository=repo)
58+
self.addCleanup(client.delete, publication["pulp_href"])
59+
60+
body = gen_distribution()
61+
body["publication"] = publication["pulp_href"]
62+
distribution = client.using_handler(api.task_handler).post(
63+
PYTHON_DISTRIBUTION_PATH, body
64+
)
65+
self.addCleanup(client.delete, distribution["pulp_href"])
66+
67+
cli_client = cli.Client(cfg)
68+
# uninstall package before trying to install it
69+
if self.check_install(cli_client, "shelf-reader"):
70+
cli_client.run(("pip", "uninstall", "shelf-reader", "-y"))
71+
72+
host_base_url = cfg.get_content_host_base_url()
73+
url = "".join(
74+
[host_base_url, "/pulp/content/", distribution["base_path"], "/simple/"]
75+
)
76+
# Pip install shelf-reader
77+
out = cli_client.run(
78+
(
79+
"pip",
80+
"install",
81+
"--trusted-host",
82+
urlsplit(host_base_url).hostname,
83+
"-i",
84+
url,
85+
"shelf-reader",
86+
)
87+
).stdout
88+
self.addCleanup(cli_client.run, ("pip", "uninstall", "shelf-reader", "-y"))
89+
90+
# check that pip correctly installed
91+
self.assertTrue(self.check_install(cli_client, "shelf-reader"), out)
92+
93+
def check_install(self, cli_client, package):
94+
"""Returns true if python package is installed, false otherwise"""
95+
return cli_client.run(("pip", "list")).stdout.find(package) != -1

0 commit comments

Comments
 (0)