Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flake8.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
exclude = ./docs/*,*/migrations/*
ignore = Q000,Q003,D100,D104,D106,D200,D205,D400,D401,D402
ignore = Q000,Q003,D100,D104,D106,D200,D205,D400,D401,D402,D413
max-line-length = 100

# Flake8-quotes extension codes
Expand All @@ -15,3 +15,4 @@ max-line-length = 100
# D200: one-line docstring should fit on one line with quotes
# D401: first line should be imperative (nitpicky)
# D402: first line should not be the function’s “signature” (false positives)
# D413: missing blank line after last section
52 changes: 13 additions & 39 deletions pulp_python/tests/functional/api/test_auto_publish.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,26 @@
# coding=utf-8
"""Tests automatic updating of publications and distributions."""
import unittest

from pulp_smash import config
from pulp_smash.pulp3.bindings import monitor_task
from pulp_smash.pulp3.utils import gen_repo, gen_distribution, download_content_unit

from pulp_python.tests.functional.utils import gen_python_client, gen_python_remote
from pulp_python.tests.functional.utils import set_up_module as setUpModule # noqa:F401
from pulp_smash.pulp3.utils import download_content_unit

from pulpcore.client.pulp_python import (
RepositoriesPythonApi,
RemotesPythonApi,
PublicationsPypiApi,
ContentPackagesApi,
DistributionsPypiApi,
RepositorySyncURL,
from pulp_python.tests.functional.utils import (
cfg,
gen_python_remote,
TestCaseUsingBindings,
TestHelpersMixin
)
from pulp_python.tests.functional.utils import set_up_module as setUpModule # noqa:F401
from pulpcore.client.pulp_python import RepositorySyncURL


class AutoPublishDistributeTestCase(unittest.TestCase):
class AutoPublishDistributeTestCase(TestCaseUsingBindings, TestHelpersMixin):
"""Test auto-publish and auto-distribution"""

@classmethod
def setUpClass(cls):
"""Create class-wide variables."""
cls.cfg = config.get_config()
cls.client = gen_python_client()

cls.content_api = ContentPackagesApi(cls.client)
cls.repo_api = RepositoriesPythonApi(cls.client)
cls.remote_api = RemotesPythonApi(cls.client)
cls.publications_api = PublicationsPypiApi(cls.client)
cls.distributions_api = DistributionsPypiApi(cls.client)

def setUp(self):
"""Create remote, repo, publish settings, and distribution."""
self.remote = self.remote_api.create(gen_python_remote(policy="immediate"))
self.repo = self.repo_api.create(gen_repo(autopublish=True))
response = self.distributions_api.create(gen_distribution(repository=self.repo.pulp_href))
distribution_href = monitor_task(response.task).created_resources[0]
self.distribution = self.distributions_api.read(distribution_href)

def tearDown(self):
"""Clean up."""
self.repo_api.delete(self.repo.pulp_href)
self.remote_api.delete(self.remote.pulp_href)
self.distributions_api.delete(self.distribution.pulp_href)
self.addCleanup(self.remote_api.delete, self.remote.pulp_href)
self.repo, self.distribution = self._create_empty_repo_and_distribution(autopublish=True)

def test_01_sync(self):
"""Assert that syncing the repository triggers auto-publish and auto-distribution."""
Expand All @@ -61,7 +35,7 @@ def test_01_sync(self):
# Check that all the appropriate resources were created
self.assertGreater(len(task.created_resources), 1)
self.assertEqual(self.publications_api.list().count, 1)
download_content_unit(self.cfg, self.distribution.to_dict(), "simple/")
download_content_unit(cfg, self.distribution.to_dict(), "simple/")

# Sync the repository again. Since there should be no new repository version, there
# should be no new publications or distributions either.
Expand All @@ -86,4 +60,4 @@ def test_02_modify(self):
# Check that all the appropriate resources were created
self.assertGreater(len(task.created_resources), 1)
self.assertEqual(self.publications_api.list().count, 1)
download_content_unit(self.cfg, self.distribution.to_dict(), "simple/")
download_content_unit(cfg, self.distribution.to_dict(), "simple/")
87 changes: 23 additions & 64 deletions pulp_python/tests/functional/api/test_consume_content.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# coding=utf-8
"""Tests that perform actions over content unit."""
import unittest

from pulp_smash import cli
from pulp_smash.pulp3.bindings import monitor_task
from pulp_smash.pulp3.utils import gen_repo, gen_distribution, delete_orphans
from pulp_smash.pulp3.utils import delete_orphans, modify_repo

from pulp_python.tests.functional.constants import (
PYTHON_FIXTURE_URL,
Expand All @@ -15,29 +13,19 @@
)

from pulp_python.tests.functional.utils import (
cfg,
gen_artifact,
gen_python_client,
gen_python_content_attrs,
cfg,
publish,
gen_python_remote,
TestCaseUsingBindings,
TestHelpersMixin,
)
from pulp_python.tests.functional.utils import set_up_module as setUpModule # noqa:F401
from urllib.parse import urljoin, urlsplit

from pulpcore.client.pulp_python import (
RepositoriesPythonApi,
RemotesPythonApi,
PublicationsPypiApi,
ContentPackagesApi,
DistributionsPypiApi,
RepositorySyncURL,
)

from pulp_smash.utils import http_get


class PipInstallContentTestCase(unittest.TestCase):
class PipInstallContentTestCase(TestCaseUsingBindings, TestHelpersMixin):
"""
Verify whether content served by Pulp can be consumed through pip install.
Workflows tested are:
Expand All @@ -52,7 +40,7 @@ def setUpClass(cls):
"""
Check if packages to install through tests are already installed
"""
cls.client = gen_python_client()
super().setUpClass()
cls.cli_client = cli.Client(cfg)
cls.PACKAGES = PYTHON_FIXTURES_PACKAGES
cls.PACKAGES_URLS = [
Expand All @@ -67,36 +55,28 @@ def setUpClass(cls):
cls.check_install(cls.cli_client, pkg),
"{} is already installed".format(pkg),
)
cls.repo_api = RepositoriesPythonApi(cls.client)
cls.remote_api = RemotesPythonApi(cls.client)
cls.content_api = ContentPackagesApi(cls.client)
cls.publications_api = PublicationsPypiApi(cls.client)
cls.distro_api = DistributionsPypiApi(cls.client)

def test_workflow_01(self):
"""
Verify workflow 1
"""
repo = self.repo_api.create(gen_repo())
self.addCleanup(self.repo_api.delete, repo.pulp_href)

artifacts = []
for pkg in self.PACKAGES_URLS:
artifacts.append(gen_artifact(pkg))

for filename, artifact in zip(PYTHON_FIXTURES_FILENAMES, artifacts):
created_contents = []
for pkg, filename in zip(self.PACKAGES_URLS, PYTHON_FIXTURES_FILENAMES):
content_response = self.content_api.create(
**gen_python_content_attrs(artifact, filename)
)
created_resources = monitor_task(content_response.task).created_resources
self.repo_api.modify(
repo.pulp_href, {"add_content_units": created_resources}
**gen_python_content_attrs(gen_artifact(pkg), filename)
)
created_contents.extend(monitor_task(content_response.task).created_resources)
created_contents = [self.content_api.read(href).to_dict() for href in created_contents]

repo = self._create_repository()
# Add content
modify_repo(cfg, repo.to_dict(), add_units=created_contents)
repo = self.repo_api.read(repo.pulp_href)
distribution = self.gen_pub_dist(repo)
pub = self._create_publication(repo)
distro = self._create_distribution_from_publication(pub)

self.addCleanup(delete_orphans, cfg)
self.check_consume(distribution.to_dict())
self.check_consume(distro.to_dict())

def test_workflow_02(self):
"""
Expand All @@ -112,20 +92,11 @@ def test_workflow_02(self):
* `Pulp #4682 <https://pulp.plan.io/issues/4682>`_
* `Pulp #4677 <https://pulp.plan.io/issues/4677>`_
"""
repo = self.repo_api.create(gen_repo())
self.addCleanup(self.repo_api.delete, repo.pulp_href)

body = gen_python_remote(includes=PYTHON_LIST_PROJECT_SPECIFIER)
remote = self.remote_api.create(body)
self.addCleanup(self.remote_api.delete, remote.pulp_href)

repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data)
monitor_task(sync_response.task)
repo = self.repo_api.read(repo.pulp_href)

distribution = self.gen_pub_dist(repo)
self.check_consume(distribution.to_dict())
remote = self._create_remote(includes=PYTHON_LIST_PROJECT_SPECIFIER)
repo = self._create_repo_and_sync_with_remote(remote)
pub = self._create_publication(repo)
distro = self._create_distribution_from_publication(pub)
self.check_consume(distro.to_dict())

def check_consume(self, distribution):
"""Tests that pip packages hosted in a distribution can be consumed"""
Expand All @@ -138,18 +109,6 @@ def check_consume(self, distribution):
self.assertTrue(self.check_install(self.cli_client, pkg), out)
self.addCleanup(self.uninstall, self.cli_client, pkg)

def gen_pub_dist(self, repo):
"""Takes a repo and generates a publication and then distributes it"""
publication = publish(repo.to_dict())
self.addCleanup(self.publications_api.delete, publication["pulp_href"])

body = gen_distribution()
body["publication"] = publication["pulp_href"]
distro_response = self.distro_api.create(body)
distro = self.distro_api.read(monitor_task(distro_response.task).created_resources[0])
self.addCleanup(self.distro_api.delete, distro.pulp_href)
return distro

@staticmethod
def check_install(cli_client, package):
"""Returns true if python package is installed, false otherwise"""
Expand Down
Loading