Skip to content

Commit

Permalink
Update fake pulp to support RpmUnit files [RHELDST-21555]
Browse files Browse the repository at this point in the history
  • Loading branch information
negillett committed Apr 17, 2024
1 parent 9142c61 commit 69d78da
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
10 changes: 8 additions & 2 deletions pubtools/pulplib/_impl/fake/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,16 @@ def pulp_value(pulp_field, obj):

for cls_field in attr.fields(type(obj)):
pulp_key = cls_field.metadata.get(PULP2_FIELD)
subfield = None
if pulp_key:
subfield = None
# provides and requires attributes of RpmUnit needs special conversion
# method as we want to get values of specific attribute in list of objects
if pulp_key == "provides" or pulp_key == "requires":
if pulp_key in ("provides", "requires"):
pulp_key = pulp_field
subfield = pulp_field.split(".")[1]
elif pulp_key == "files.file":
pulp_key = "files"
subfield = "files"

obj_value = getattr(obj, cls_field.name, None)
# TODO: will we need to differentiate between "absent" and
Expand Down Expand Up @@ -179,6 +182,9 @@ def convert_field_to_pulp(obj, field_name, value, subfield):
# We can convert from datetime back to the ISO8601 timestamp format
# used within Pulp
return value.strftime("%Y-%m-%dT%H:%M:%SZ")
elif cls_field.name == "files":
# TODO: what does a pulp 'files' object look like?
value = {"file": value, "iso?": }

if subfield:
return [getattr(item, subfield) for item in value]
Expand Down
13 changes: 7 additions & 6 deletions tests/fake/test_fake_search_all_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def populated_units(controller):
arch="x86_64",
repository_memberships=["repo1"],
),
RpmUnit(name="jq", version="4.0", release="1", arch="x86_64", files=["/some/file"]),
ModulemdUnit(
name="module1",
stream="s1",
Expand Down Expand Up @@ -101,12 +102,12 @@ def test_search_content_all(populated_units, controller):
).result()
]
units3 = [u for u in controller.client.search_content().result()]
assert len(units1) == 3
assert len([u for u in units1 if u.content_type_id == "rpm"]) == 3
assert len(units1) == 4
assert len([u for u in units1 if u.content_type_id == "rpm"]) == 4
assert len(units2) == 2
assert len([u for u in units2 if u.content_type_id == "srpm"]) == 2
# + two modulemd, one modulemd_defaults
assert len(units3) == 8
assert len(units3) == 9

assert set(sum([u.repository_memberships for u in units1], [])) == set(
["repo1", "repo2"]
Expand Down Expand Up @@ -150,12 +151,12 @@ def test_search_content_all_pagination(populated_units, controller):
).result()
]
units3 = [u for u in controller.client.search_content().result()]
assert len(units1) == 3
assert len([u for u in units1 if u.content_type_id == "rpm"]) == 3
assert len(units1) == 4
assert len([u for u in units1 if u.content_type_id == "rpm"]) == 4
assert len(units2) == 2
assert len([u for u in units2 if u.content_type_id == "srpm"]) == 2
# + two modulemd, one modulemd_defaults
assert len(units3) == 8
assert len(units3) == 9

assert set(sum([u.repository_memberships for u in units1], [])) == set(
["repo1", "repo2"]
Expand Down
55 changes: 46 additions & 9 deletions tests/fake/test_fake_search_content.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import pytest

from pubtools.pulplib import (
FakeController,
Criteria,
Matcher,
RpmUnit,
ErratumUnit,
FakeController,
Matcher,
ModulemdUnit,
YumRepository,
RpmDependency,
RpmUnit,
YumRepository,
)


Expand All @@ -32,6 +32,9 @@ def populated_repo(controller):
sourcerpm="glibc-5.0-1.el5_11.1.src.rpm",
provides=[RpmDependency(name="gcc")],
),
RpmUnit(
name="jq", version="4.0", release="1", arch="x86_64", files=["/some/file"]
),
ModulemdUnit(
name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64"
),
Expand Down Expand Up @@ -91,7 +94,7 @@ def test_search_content_default_crit(populated_repo):
"""search_content with default criteria on populated repo finds all units"""

units = list(populated_repo.search_content())
assert len(units) == 6
assert len(units) == 7


def test_search_content_by_type(populated_repo):
Expand All @@ -118,6 +121,15 @@ def test_search_content_by_type(populated_repo):
repository_memberships=["repo1"],
provides=[RpmDependency(name="gcc")],
),
RpmUnit(
name="jq",
version="4.0",
release="1",
arch="x86_64",
repository_memberships=["repo1"],
unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613",
files=["/some/file"],
),
]


Expand Down Expand Up @@ -156,6 +168,14 @@ def test_search_content_with_fields(populated_repo):
arch="x86_64",
repository_memberships=["repo1"],
),
RpmUnit(
name="jq",
version="4.0",
release="1",
arch="x86_64",
repository_memberships=["repo1"],
unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613",
),
]


Expand All @@ -166,7 +186,7 @@ def test_search_erratum_by_type(populated_repo):
units = list(populated_repo.search_content(crit))
assert units == [
ErratumUnit(
unit_id="85776e9a-dd84-f39e-7154-5a137a1d5006",
unit_id="d71037d1-b83e-90ec-17e0-aa3c03983ca8",
id="RHBA-1234:56",
summary="The best advisory",
repository_memberships=["repo1"],
Expand Down Expand Up @@ -207,7 +227,7 @@ def test_search_content_by_unit_type(populated_repo):
units = list(populated_repo.search_content(crit))
assert sorted(units) == [
ModulemdUnit(
unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613",
unit_id="e6f4590b-9a16-4106-cf6a-659eb4862b21",
name="module1",
stream="s1",
version=1234,
Expand All @@ -216,7 +236,7 @@ def test_search_content_by_unit_type(populated_repo):
repository_memberships=["repo1"],
),
ModulemdUnit(
unit_id="e6f4590b-9a16-4106-cf6a-659eb4862b21",
unit_id="85776e9a-dd84-f39e-7154-5a137a1d5006",
name="module2",
stream="s2",
version=1234,
Expand All @@ -239,7 +259,7 @@ def test_search_content_mixed_fields(populated_repo):
# Note: sorting different types not natively supported, hence sorting by repr
assert sorted(units, key=repr) == [
ModulemdUnit(
unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613",
unit_id="e6f4590b-9a16-4106-cf6a-659eb4862b21",
name="module1",
stream="s1",
version=1234,
Expand Down Expand Up @@ -280,3 +300,20 @@ def test_search_content_subfields(populated_repo):
repository_memberships=["repo1"],
)
]


def test_search_content_files(populated_repo):
"""
search_content using files subfield in attributes that are lists of strings.
"""
crit = Criteria.and_(
Criteria.with_unit_type(RpmUnit),
Criteria.with_field("files.file", Matcher.in_(["/some/file"])),
)
units = list(populated_repo.search_content(crit).result())

assert units == [
RpmUnit(
name="jq", version="4.0", release="1", arch="x86_64", files=["/some/file"]
)
]

0 comments on commit 69d78da

Please sign in to comment.