Skip to content

Commit c0c81a7

Browse files
committed
Add functional test, changelog, avoid forbidden hashes in unit test
1 parent 8d33856 commit c0c81a7

4 files changed

Lines changed: 83 additions & 4 deletions

File tree

CHANGES/1371.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement `layout` option on AptPublication that allows user to choose different cache-friendly style of deb URL.

pulp_deb/tests/functional/api/test_publish.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from debian import deb822
33
import os
44
import pytest
5+
import re
56

67
from pulp_deb.tests.functional.constants import (
78
DEB_FIXTURE_ALT_SINGLE_DIST,
@@ -18,6 +19,9 @@
1819
DEB_PUBLICATION_ARGS_ONLY_SIMPLE,
1920
DEB_PUBLICATION_ARGS_ONLY_STRUCTURED,
2021
DEB_PUBLICATION_ARGS_SIMPLE_AND_STRUCTURED,
22+
DEB_PUBLICATION_ARGS_NESTED_ALPHABETICALLY,
23+
DEB_PUBLICATION_ARGS_NESTED_BY_DIGEST,
24+
DEB_PUBLICATION_ARGS_NESTED_BY_BOTH,
2125
DEB_PUBLISH_COMPLEX_DEBIAN_SECURITY,
2226
DEB_PUBLISH_COMPLEX_UBUNTU_BACKPORTS,
2327
DEB_PUBLISH_EMPTY_REPOSITORY,
@@ -196,6 +200,66 @@ def test_publish_any_repo_version(
196200
deb_delete_publication(second_publication)
197201

198202

203+
@pytest.mark.parallel
204+
@pytest.mark.parametrize(
205+
"publication_args",
206+
[
207+
DEB_PUBLICATION_ARGS_ONLY_STRUCTURED,
208+
DEB_PUBLICATION_ARGS_NESTED_ALPHABETICALLY,
209+
DEB_PUBLICATION_ARGS_NESTED_BY_DIGEST,
210+
DEB_PUBLICATION_ARGS_NESTED_BY_BOTH,
211+
],
212+
)
213+
def test_publish_layout(
214+
apt_distribution_api,
215+
create_publication_and_verify_repo_version,
216+
deb_distribution_factory,
217+
download_content_unit,
218+
publication_args,
219+
):
220+
"""Test whether a the layout parameter is generating expected package URLs
221+
and the packages are available.
222+
223+
The following cases are tested:
224+
225+
* `Publish a repo where layout is not specified (alphabetical by default).`_
226+
* `Publish a repo explicit alphabetical layout.`_
227+
* `Publish a repo explicit digest layout.`_
228+
* `Publish a repo explicit "both" layout.`_
229+
"""
230+
remote_args = {"distributions": DEB_FIXTURE_SINGLE_DIST}
231+
232+
# Create a repository and publication.
233+
publication, _, _, _ = create_publication_and_verify_repo_version(
234+
remote_args, publication_args, is_modified=True
235+
)
236+
237+
# Create a distribution
238+
distribution = deb_distribution_factory(publication)
239+
distribution = apt_distribution_api.read(distribution.pulp_href)
240+
241+
# Expected filename format
242+
if "layout" not in publication_args or publication_args["layout"] == "nested_alphabetically":
243+
expected = r"pool/asgard/[a-z]/"
244+
else: # nested_by_digest or nested_by_both
245+
expected = r"pool/asgard/[0-9a-f]{2}/[0-9a-f]{4}/"
246+
247+
# Verify than an expected Package index exists, and that the expected URL is
248+
# generated and that the package is actually available.
249+
package_index = download_content_unit(
250+
distribution.to_dict()["base_path"], "dists/ragnarok/asguard/binary-ppc64/Packages"
251+
)
252+
for line in str(package_index):
253+
if not line.startswith("Filename:"):
254+
continue
255+
256+
_, _, filename = line.partition(": ")
257+
assert re.match(expected, filename)
258+
259+
package = download_content_unit(distribution.to_dict()["base_path"], filename)
260+
assert "404" not in str(package)
261+
262+
199263
@pytest.mark.parallel
200264
@pytest.mark.parametrize(
201265
"set_on, expect_signed",

pulp_deb/tests/functional/constants.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ def _clean_dict(d):
4747
DEB_PUBLICATION_ARGS_ONLY_STRUCTURED = {"simple": False, "structured": True}
4848
DEB_PUBLICATION_ARGS_SIMPLE_AND_STRUCTURED = {"simple": True, "structured": True}
4949
DEB_PUBLICATION_ARGS_ALL = {"simple": True, "structured": True, "signing_service": ""}
50+
DEB_PUBLICATION_ARGS_NESTED_ALPHABETICALLY = {
51+
"simple": False,
52+
"structured": True,
53+
"layout": "nested_alphabetically",
54+
}
55+
DEB_PUBLICATION_ARGS_NESTED_BY_DIGEST = {
56+
"simple": False,
57+
"structured": True,
58+
"layout": "nested_by_digest",
59+
}
60+
DEB_PUBLICATION_ARGS_NESTED_BY_BOTH = {
61+
"simple": False,
62+
"structured": True,
63+
"layout": "nested_by_both",
64+
}
5065

5166
DEB_P2P_REMOTE_ARGS_SIMPLE = {"distributions": "default", "policy": "immediate"}
5267
DEB_P2P_REMOTE_ARGS_STRUCTURED = {"distributions": "ragnarok nosuite", "policy": "immediate"}

pulp_deb/tests/unit/test_models.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from django.core.files.uploadedfile import SimpleUploadedFile
22
from django.test import TestCase
3-
43
from pulpcore.plugin.models import Artifact, ContentArtifact
4+
55
from pulp_deb.app.constants import LAYOUT_TYPES
6-
from pulp_deb.app.models import Package, AptRepository, Release
6+
from pulp_deb.app.models import AptRepository, Package, Release
77
from pulp_deb.app.models.repository import handle_duplicate_releases
88
from pulp_deb.app.serializers import Package822Serializer
99

@@ -34,15 +34,14 @@ def setUp(self):
3434
essential=True,
3535
maintainer="Utgardloki",
3636
description="A sea jötunn associated with the ocean.",
37+
sha256="eeff11",
3738
)
3839
self.package1.save()
3940
self.artifact1 = Artifact(
4041
size=42,
4142
md5="aabb",
4243
sha1="ccdd",
43-
sha224="ddcc",
4444
sha256="eeff11",
45-
sha384="ffee",
4645
sha512="kkll",
4746
file=SimpleUploadedFile("test_filename", b"test content"),
4847
)

0 commit comments

Comments
 (0)