Skip to content

Commit

Permalink
Remove pulp-smash from tests
Browse files Browse the repository at this point in the history
closes pulp#796
  • Loading branch information
hstct committed Jul 25, 2023
1 parent 8705277 commit 6d6d796
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 407 deletions.
1 change: 1 addition & 0 deletions CHANGES/796.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed the ``pulp-smash`` test dependency.
23 changes: 22 additions & 1 deletion functest_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
pulp-smash @ git+https://github.com/pulp/pulp-smash.git
pytest
pytest-custom_exit_code
pytest-xdist
python-debian>=0.1.36
trustme~=1.0.0
proxy.py~=2.4.3

# pulpcore
aiohttp
django
dynaconf
drf-spectacular
pulpcore-client
pulp-file-client
python-gnupg
beautifulsoup4

# pulp-smash
click
jsonschema
packaging
plumbum
pyxdg
requests
16 changes: 7 additions & 9 deletions pulp_deb/tests/functional/api/test_crud_content_unit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Tests that perform actions over content unit."""
import uuid
from uuid import uuid4
import pytest


Expand All @@ -11,7 +11,7 @@ def test_create_generic_content_unit(
):
"""Verify all allowed CRUD actions are working and the ones that don't exist fail."""
# Create a random content unit and verify its attributes
attrs = {"artifact": random_artifact.pulp_href, "relative_path": str(uuid.uuid4())}
attrs = {"artifact": random_artifact.pulp_href, "relative_path": str(uuid4())}
content_unit = deb_generic_content_factory(**attrs)
assert content_unit.artifact == random_artifact.pulp_href
assert content_unit.relative_path == attrs["relative_path"]
Expand All @@ -27,14 +27,12 @@ def test_create_generic_content_unit(

# Verify that partial update does not work for content units
with pytest.raises(AttributeError) as exc:
apt_generic_content_api.partial_update(
content_unit.pulp_href, relative_path=str(uuid.uuid4())
)
apt_generic_content_api.partial_update(content_unit.pulp_href, relative_path=str(uuid4()))
assert "object has no attribute 'partial_update'" in exc.value.args[0]

# Verify that update does not work for content units
with pytest.raises(AttributeError) as exc:
apt_generic_content_api.update(content_unit.pulp_href, relative_path=str(uuid.uuid4()))
apt_generic_content_api.update(content_unit.pulp_href, relative_path=str(uuid4()))
assert "object has no attribute 'update'" in exc.value.args[0]

# Verify that delete does not work for content units
Expand All @@ -48,7 +46,7 @@ def test_same_sha256_same_relative_path_no_repo(
apt_generic_content_api, deb_generic_content_factory, random_artifact
):
"""Test whether uploading the same content unit works and that it stays unique."""
attrs = {"artifact": random_artifact.pulp_href, "relative_path": str(uuid.uuid4())}
attrs = {"artifact": random_artifact.pulp_href, "relative_path": str(uuid4())}

# Create the first content unit and verify its attributes
content_unit_1 = deb_generic_content_factory(**attrs)
Expand All @@ -68,7 +66,7 @@ def test_same_sha256_diff_relative_path(
apt_generic_content_api, deb_generic_content_factory, random_artifact
):
"""Test whether uploading the same content unit with different relative path works."""
attrs = {"artifact": random_artifact.pulp_href, "relative_path": str(uuid.uuid4())}
attrs = {"artifact": random_artifact.pulp_href, "relative_path": str(uuid4())}

# Create the first content unit
content_unit_1 = deb_generic_content_factory(**attrs)
Expand All @@ -78,7 +76,7 @@ def test_same_sha256_diff_relative_path(
rel_path = attrs["relative_path"]

# Change the relative path and upload the content unit again verify it is the same
attrs["relative_path"] = str(uuid.uuid4())
attrs["relative_path"] = str(uuid4())
content_unit_2 = deb_generic_content_factory(**attrs)
assert content_unit_2.artifact == random_artifact.pulp_href

Expand Down
12 changes: 5 additions & 7 deletions pulp_deb/tests/functional/api/test_crud_packages.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Tests that perform actions over packages."""
import uuid
from uuid import uuid4
import pytest

from pulp_smash import utils

from pulp_deb.tests.functional.constants import DEB_PACKAGE_RELPATH
from pulp_deb.tests.functional.utils import get_local_package_absolute_path

Expand All @@ -29,12 +27,12 @@ def test_create_package(apt_package_api, deb_package_factory):

# Verify that partial update does not work for packages
with pytest.raises(AttributeError) as exc:
apt_package_api.partial_update(package.pulp_href, relative_path=str(uuid.uuid4()))
apt_package_api.partial_update(package.pulp_href, relative_path=str(uuid4()))
assert "object has no attribute 'partial_update'" in exc.value.args[0]

# Verify that update does not work for packages
with pytest.raises(AttributeError) as exc:
apt_package_api.update(package.pulp_href, relative_path=str(uuid.uuid4()))
apt_package_api.update(package.pulp_href, relative_path=str(uuid4()))
assert "object has no attribute 'update'" in exc.value.args[0]

# Verify that delete does not work for packages
Expand Down Expand Up @@ -77,8 +75,8 @@ def test_structured_package_upload(
attrs = {
"file": get_local_package_absolute_path(DEB_PACKAGE_RELPATH),
"relative_path": DEB_PACKAGE_RELPATH,
"distribution": utils.uuid4(),
"component": utils.uuid4(),
"distribution": str(uuid4()),
"component": str(uuid4()),
}

repository = deb_repository_factory()
Expand Down
15 changes: 7 additions & 8 deletions pulp_deb/tests/functional/api/test_crud_remotes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Tests that CRUD deb remotes."""
from random import choice
from uuid import uuid4
import pytest

from pulpcore.client.pulp_deb.exceptions import ApiException

from pulp_smash import utils

from pulp_deb.tests.functional.constants import DOWNLOAD_POLICIES, DEB_SIGNING_KEY
from pulp_deb.tests.functional.utils import gen_local_deb_remote

Expand Down Expand Up @@ -180,7 +179,7 @@ def test_remote_download_policies(

# Attempt to change the remote policy to an invalid string
with pytest.raises(ApiException) as exc:
deb_patch_remote(remote, {"policy": utils.uuid4()})
deb_patch_remote(remote, {"policy": str(uuid4())})
assert exc.value.status == 400

# Verify that the remote policy remains unchanged
Expand All @@ -200,12 +199,12 @@ def gen_verbose_remote_data(url):
data = gen_local_deb_remote(url)
data.update(
{
"password": utils.uuid4(),
"username": utils.uuid4(),
"password": str(uuid4()),
"username": str(uuid4()),
"policy": choice(DOWNLOAD_POLICIES),
"distributions": f"{utils.uuid4()} {utils.uuid4()}",
"components": f"{utils.uuid4()} {utils.uuid4()}",
"architectures": f"{utils.uuid4()} {utils.uuid4()}",
"distributions": f"{str(uuid4())} {str(uuid4())}",
"components": f"{str(uuid4())} {str(uuid4())}",
"architectures": f"{str(uuid4())} {str(uuid4())}",
"gpgkey": DEB_SIGNING_KEY,
}
)
Expand Down
148 changes: 126 additions & 22 deletions pulp_deb/tests/functional/api/test_download_content.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,132 @@
"""Tests that verify download of content served by Pulp."""
import os
import pytest
import hashlib
from random import choice
from urllib.parse import urljoin

from pulp_smash import config, utils
from pulp_smash.pulp3.utils import download_content_unit
from pulp_deb.tests.functional.constants import DEB_FIXTURE_STANDARD_REPOSITORY_NAME

from pulp_deb.tests.functional.utils import (
get_deb_content_unit_paths,
get_deb_verbatim_content_unit_paths,
from pulp_deb.tests.functional.constants import (
DEB_FIXTURE_STANDARD_REPOSITORY_NAME,
DEB_GENERIC_CONTENT_NAME,
DEB_PACKAGE_NAME,
DEB_PACKAGE_RELEASE_COMPONENT_NAME,
DEB_RELEASE_COMPONENT_NAME,
DEB_RELEASE_FILE_NAME,
)


@pytest.fixture
def deb_get_content_unit_paths(deb_get_content_types):
def _deb_get_content_unit_paths(repo, version_href=None):
"""Return a relative path of content units present in a deb repository.
:param repo: A dict of information about the repository.
:param version_href: The repository version to read.
:returns: A dict of list with the paths of units present in a given repository
for different content types. Paths are given as pairs with the remote and the
local version.
"""

def _rel_path(package, component=""):
sourcename = package.source or package.package
if sourcename.startswith("lib"):
prefix = sourcename[0:4]
else:
prefix = sourcename[0]
return os.path.join(
"pool",
component,
prefix,
sourcename,
f"{package.package}_{package.version}_{package.architecture}.deb",
)

package_content = deb_get_content_types(
"apt_package_api", DEB_PACKAGE_NAME, repo, version_href
)
package_release_component_content = deb_get_content_types(
"apt_package_release_components_api",
DEB_PACKAGE_RELEASE_COMPONENT_NAME,
repo,
version_href,
)
release_component_content = deb_get_content_types(
"apt_release_component_api", DEB_RELEASE_COMPONENT_NAME, repo, version_href
)
result = {
DEB_PACKAGE_NAME: [
(content.relative_path, _rel_path(content, "all")) for content in package_content
]
}
for prc in package_release_component_content:
package = next(
package for package in package_content if package.pulp_href == prc.package
)
release_component = next(
rc for rc in release_component_content if rc.pulp_href == prc.release_component
)
result[DEB_PACKAGE_NAME].append(
(package.relative_path, _rel_path(package, release_component.component))
)
return result

return _deb_get_content_unit_paths


@pytest.fixture
def deb_get_verbatim_content_unit_paths(deb_get_content_types):
def _deb_get_verbatim_content_unit_paths(repo, version_href=None):
"""Return the relative path of content units present in a deb repository.
:param repo: A dict of information about the repository.
:param verison_href: The repository version to read.
:returns: A dict of list with the paths of units present in a given repository
for different content types. Paths are given as pairs with the remote and the
local version.
"""
release_file_content = deb_get_content_types(
"apt_release_file_api", DEB_RELEASE_FILE_NAME, repo, version_href
)
package_content = deb_get_content_types(
"apt_package_api", DEB_PACKAGE_NAME, repo, version_href
)
generic_content = deb_get_content_types(
"apt_generic_content_api", DEB_GENERIC_CONTENT_NAME, repo, version_href
)
return {
DEB_RELEASE_FILE_NAME: [
(content.relative_path, content.relative_path) for content in release_file_content
],
DEB_PACKAGE_NAME: [
(content.relative_path, content.relative_path) for content in package_content
],
DEB_GENERIC_CONTENT_NAME: [
(content.relative_path, content.relative_path) for content in generic_content
],
}

return _deb_get_verbatim_content_unit_paths


@pytest.fixture
def deb_get_random_content_unit_path(request):
def _deb_get_random_content_unit_path(repo, is_verbatim=False):
"""Get paths from random content units in a given repository.
:param repo: A dict of information about the repository.
:param is_verbatim: (Optional) Whether the content is published verbatim or not.
:returns: List of paths of content units.
"""
get_content_unit_paths = (
request.getfixturevalue("deb_get_verbatim_content_unit_paths")
if is_verbatim
else request.getfixturevalue("deb_get_content_unit_paths")
)
return [choice(paths) for paths in get_content_unit_paths(repo).values() if paths]

return _deb_get_random_content_unit_path


@pytest.mark.parallel
@pytest.mark.parametrize("is_verbatim", [False, True])
def test_download_content(
Expand All @@ -24,8 +137,11 @@ def test_download_content(
deb_repository_factory,
deb_verbatim_publication_factory,
deb_get_repository_by_href,
deb_get_random_content_unit_path,
deb_sync_repository,
deb_fixture_server,
download_content_unit,
http_get,
is_verbatim,
):
"""Verify whether content served by pulp can be downloaded.
Expand All @@ -49,27 +165,15 @@ def test_download_content(
distribution = deb_distribution_factory(publication)

# Select a random content unit from the distribution and store its checksums
unit_paths = get_random_content_unit_path(repo, is_verbatim)
unit_paths = deb_get_random_content_unit_path(repo, is_verbatim)
url = deb_fixture_server.make_url(DEB_FIXTURE_STANDARD_REPOSITORY_NAME)
fixtures_hashes = [
hashlib.sha256(utils.http_get(urljoin(url, unit_path[0]))).hexdigest()
for unit_path in unit_paths
hashlib.sha256(http_get(urljoin(url, unit_path[0]))).hexdigest() for unit_path in unit_paths
]

# Verify that the content unit has the same checksums when fetched directly from Pulp-Fixtures
pulp_hashes = []
cfg = config.get_config()
for unit_path in unit_paths:
content = download_content_unit(cfg, distribution.to_dict(), unit_path[1])
content = download_content_unit(distribution.base_path, unit_path[1])
pulp_hashes.append(hashlib.sha256(content).hexdigest())
assert fixtures_hashes == pulp_hashes


def get_random_content_unit_path(repo, is_verbatim):
"""Returns the path from a random content unit of a given (verbatim) repo."""
if is_verbatim:
return [
choice(paths) for paths in get_deb_verbatim_content_unit_paths(repo).values() if paths
]
else:
return [choice(paths) for paths in get_deb_content_unit_paths(repo).values() if paths]
Loading

0 comments on commit 6d6d796

Please sign in to comment.