Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tests for fake pulp support of RpmUnit files [RHELDST-21555] #222

Merged
merged 1 commit into from
Apr 23, 2024
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
23 changes: 13 additions & 10 deletions tests/fake/test_fake_search_all_content.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pytest

from pubtools.pulplib import (
FakeController,
Criteria,
RpmUnit,
ModulemdUnit,
FakeController,
ModulemdDefaultsUnit,
YumRepository,
ModulemdUnit,
PulpException,
RpmUnit,
YumRepository,
)


Expand Down Expand Up @@ -41,6 +41,9 @@ 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 +104,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 +153,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
67 changes: 57 additions & 10 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,13 @@ 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", "/another/file", "/yet/another/file", "/script"],
),
ModulemdUnit(
name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64"
),
Expand Down Expand Up @@ -91,7 +98,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 +125,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", "/another/file", "/yet/another/file", "/script"],
),
]


Expand Down Expand Up @@ -156,6 +172,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 +190,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 +231,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 +240,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 +263,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 All @@ -266,7 +290,7 @@ def test_search_content_subfields(populated_repo):
crit = Criteria.and_(
Criteria.with_unit_type(RpmUnit), Criteria.with_field("provides.name", "gcc")
)
units = list(populated_repo.search_content(crit))
units = list(populated_repo.search_content(crit).result())

assert units == [
RpmUnit(
Expand All @@ -280,3 +304,26 @@ 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", "/some/file"),
)
units = list(populated_repo.search_content(crit).result())

assert units == [
RpmUnit(
name="jq",
version="4.0",
release="1",
arch="x86_64",
repository_memberships=["repo1"],
unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613",
files=["/some/file", "/another/file", "/yet/another/file", "/script"],
)
]
Loading