forked from pulp/pulp_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_publish.py
More file actions
99 lines (79 loc) · 3.29 KB
/
Copy pathtest_publish.py
File metadata and controls
99 lines (79 loc) · 3.29 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
import unittest
from random import choice
from urllib.parse import urljoin
from requests.exceptions import HTTPError
from pulp_smash import api, config
from pulp_smash.pulp3.constants import REPO_PATH
from pulp_smash.pulp3.utils import (
gen_repo,
get_content,
get_versions,
sync,
publish
)
from pulp_python.tests.functional.constants import (
PYTHON_CONTENT_NAME,
PYTHON_PUBLISHER_PATH,
PYTHON_FIXTURES_URL,
PYTHON_REMOTE_PATH
)
from pulp_python.tests.functional.utils import gen_python_remote, gen_python_publisher
from pulp_python.tests.functional.utils import set_up_module as setUpModule # noqa:F401
class PublishAnyRepoVersionTestCase(unittest.TestCase):
"""
Test whether a particular repository version can be published.
This test targets the following issues:
* `Pulp #3324 <https://pulp.plan.io/issues/3324>`_
* `Pulp Smash #897 <https://github.com/PulpQE/pulp-smash/issues/897>`_
"""
@classmethod
def setUpClass(cls):
"""Create class-wide variables."""
cls.cfg = config.get_config()
cls.client = api.Client(cls.cfg, api.json_handler)
def test_all(self):
"""
Test whether a particular repository version can be published.
1. Create a repository with at least 2 repository versions.
2. Create a publication by supplying the latest ``repository_version``.
3. Assert that the publication ``repository_version`` attribute points
to the latest repository version.
4. Create a publication by supplying the non-latest
``repository_version``.
5. Assert that the publication ``repository_version`` attribute points
to the supplied repository version.
6. Assert that an exception is raised when providing two different
repository versions to be published at same time.
"""
body = gen_python_remote(PYTHON_FIXTURES_URL)
remote = self.client.post(PYTHON_REMOTE_PATH, body)
self.addCleanup(self.client.delete, remote['_href'])
repo = self.client.post(REPO_PATH, gen_repo())
self.addCleanup(self.client.delete, repo['_href'])
sync(self.cfg, remote, repo)
publisher = self.client.post(PYTHON_PUBLISHER_PATH, gen_python_publisher())
self.addCleanup(self.client.delete, publisher['_href'])
# Step 1
repo = self.client.get(repo['_href'])
for python_content in get_content(repo)[PYTHON_CONTENT_NAME]:
self.client.post(
repo['_versions_href'],
{'add_content_units': [python_content['_href']]}
)
versions = get_versions(repo)
non_latest = choice(versions[:-1])['_href']
# Step 2
publication = publish(self.cfg, publisher, repo)
# Step 3
self.assertEqual(publication['repository_version'], versions[-1]['_href'])
# Step 4
publication = publish(self.cfg, publisher, repo, non_latest)
# Step 5
self.assertEqual(publication['repository_version'], non_latest)
# Step 6
with self.assertRaises(HTTPError):
body = {
'repository': repo['_href'],
'repository_version': non_latest
}
self.client.post(urljoin(publisher['_href'], 'publish/'), body)