Skip to content

Commit 70a9b52

Browse files
committed
Implement tests for fake pulp support of RpmUnit files [RHELDST-21555]
1 parent 005f5e1 commit 70a9b52

File tree

2 files changed

+70
-20
lines changed

2 files changed

+70
-20
lines changed

tests/fake/test_fake_search_all_content.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import pytest
22

33
from pubtools.pulplib import (
4-
FakeController,
54
Criteria,
6-
RpmUnit,
7-
ModulemdUnit,
5+
FakeController,
86
ModulemdDefaultsUnit,
9-
YumRepository,
7+
ModulemdUnit,
108
PulpException,
9+
RpmUnit,
10+
YumRepository,
1111
)
1212

1313

@@ -41,6 +41,9 @@ def populated_units(controller):
4141
arch="x86_64",
4242
repository_memberships=["repo1"],
4343
),
44+
RpmUnit(
45+
name="jq", version="4.0", release="1", arch="x86_64", files=["/some/file"]
46+
),
4447
ModulemdUnit(
4548
name="module1",
4649
stream="s1",
@@ -101,12 +104,12 @@ def test_search_content_all(populated_units, controller):
101104
).result()
102105
]
103106
units3 = [u for u in controller.client.search_content().result()]
104-
assert len(units1) == 3
105-
assert len([u for u in units1 if u.content_type_id == "rpm"]) == 3
107+
assert len(units1) == 4
108+
assert len([u for u in units1 if u.content_type_id == "rpm"]) == 4
106109
assert len(units2) == 2
107110
assert len([u for u in units2 if u.content_type_id == "srpm"]) == 2
108111
# + two modulemd, one modulemd_defaults
109-
assert len(units3) == 8
112+
assert len(units3) == 9
110113

111114
assert set(sum([u.repository_memberships for u in units1], [])) == set(
112115
["repo1", "repo2"]
@@ -150,12 +153,12 @@ def test_search_content_all_pagination(populated_units, controller):
150153
).result()
151154
]
152155
units3 = [u for u in controller.client.search_content().result()]
153-
assert len(units1) == 3
154-
assert len([u for u in units1 if u.content_type_id == "rpm"]) == 3
156+
assert len(units1) == 4
157+
assert len([u for u in units1 if u.content_type_id == "rpm"]) == 4
155158
assert len(units2) == 2
156159
assert len([u for u in units2 if u.content_type_id == "srpm"]) == 2
157160
# + two modulemd, one modulemd_defaults
158-
assert len(units3) == 8
161+
assert len(units3) == 9
159162

160163
assert set(sum([u.repository_memberships for u in units1], [])) == set(
161164
["repo1", "repo2"]

tests/fake/test_fake_search_content.py

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import pytest
22

33
from pubtools.pulplib import (
4-
FakeController,
54
Criteria,
6-
Matcher,
7-
RpmUnit,
85
ErratumUnit,
6+
FakeController,
7+
Matcher,
98
ModulemdUnit,
10-
YumRepository,
119
RpmDependency,
10+
RpmUnit,
11+
YumRepository,
1212
)
1313

1414

@@ -32,6 +32,13 @@ def populated_repo(controller):
3232
sourcerpm="glibc-5.0-1.el5_11.1.src.rpm",
3333
provides=[RpmDependency(name="gcc")],
3434
),
35+
RpmUnit(
36+
name="jq",
37+
version="4.0",
38+
release="1",
39+
arch="x86_64",
40+
files=["/some/file", "/another/file", "/yet/another/file", "/script"],
41+
),
3542
ModulemdUnit(
3643
name="module1", stream="s1", version=1234, context="a1b2", arch="x86_64"
3744
),
@@ -91,7 +98,7 @@ def test_search_content_default_crit(populated_repo):
9198
"""search_content with default criteria on populated repo finds all units"""
9299

93100
units = list(populated_repo.search_content())
94-
assert len(units) == 6
101+
assert len(units) == 7
95102

96103

97104
def test_search_content_by_type(populated_repo):
@@ -118,6 +125,15 @@ def test_search_content_by_type(populated_repo):
118125
repository_memberships=["repo1"],
119126
provides=[RpmDependency(name="gcc")],
120127
),
128+
RpmUnit(
129+
name="jq",
130+
version="4.0",
131+
release="1",
132+
arch="x86_64",
133+
repository_memberships=["repo1"],
134+
unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613",
135+
files=["/some/file", "/another/file", "/yet/another/file", "/script"],
136+
),
121137
]
122138

123139

@@ -156,6 +172,14 @@ def test_search_content_with_fields(populated_repo):
156172
arch="x86_64",
157173
repository_memberships=["repo1"],
158174
),
175+
RpmUnit(
176+
name="jq",
177+
version="4.0",
178+
release="1",
179+
arch="x86_64",
180+
repository_memberships=["repo1"],
181+
unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613",
182+
),
159183
]
160184

161185

@@ -166,7 +190,7 @@ def test_search_erratum_by_type(populated_repo):
166190
units = list(populated_repo.search_content(crit))
167191
assert units == [
168192
ErratumUnit(
169-
unit_id="85776e9a-dd84-f39e-7154-5a137a1d5006",
193+
unit_id="d71037d1-b83e-90ec-17e0-aa3c03983ca8",
170194
id="RHBA-1234:56",
171195
summary="The best advisory",
172196
repository_memberships=["repo1"],
@@ -207,7 +231,7 @@ def test_search_content_by_unit_type(populated_repo):
207231
units = list(populated_repo.search_content(crit))
208232
assert sorted(units) == [
209233
ModulemdUnit(
210-
unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613",
234+
unit_id="e6f4590b-9a16-4106-cf6a-659eb4862b21",
211235
name="module1",
212236
stream="s1",
213237
version=1234,
@@ -216,7 +240,7 @@ def test_search_content_by_unit_type(populated_repo):
216240
repository_memberships=["repo1"],
217241
),
218242
ModulemdUnit(
219-
unit_id="e6f4590b-9a16-4106-cf6a-659eb4862b21",
243+
unit_id="85776e9a-dd84-f39e-7154-5a137a1d5006",
220244
name="module2",
221245
stream="s2",
222246
version=1234,
@@ -239,7 +263,7 @@ def test_search_content_mixed_fields(populated_repo):
239263
# Note: sorting different types not natively supported, hence sorting by repr
240264
assert sorted(units, key=repr) == [
241265
ModulemdUnit(
242-
unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613",
266+
unit_id="e6f4590b-9a16-4106-cf6a-659eb4862b21",
243267
name="module1",
244268
stream="s1",
245269
version=1234,
@@ -266,7 +290,7 @@ def test_search_content_subfields(populated_repo):
266290
crit = Criteria.and_(
267291
Criteria.with_unit_type(RpmUnit), Criteria.with_field("provides.name", "gcc")
268292
)
269-
units = list(populated_repo.search_content(crit))
293+
units = list(populated_repo.search_content(crit).result())
270294

271295
assert units == [
272296
RpmUnit(
@@ -280,3 +304,26 @@ def test_search_content_subfields(populated_repo):
280304
repository_memberships=["repo1"],
281305
)
282306
]
307+
308+
309+
def test_search_content_files(populated_repo):
310+
"""
311+
search_content using files subfield in attributes that are lists of strings.
312+
"""
313+
crit = Criteria.and_(
314+
Criteria.with_unit_type(RpmUnit),
315+
Criteria.with_field("files", "/some/file"),
316+
)
317+
units = list(populated_repo.search_content(crit).result())
318+
319+
assert units == [
320+
RpmUnit(
321+
name="jq",
322+
version="4.0",
323+
release="1",
324+
arch="x86_64",
325+
repository_memberships=["repo1"],
326+
unit_id="23a7711a-8133-2876-37eb-dcd9e87a1613",
327+
files=["/some/file", "/another/file", "/yet/another/file", "/script"],
328+
)
329+
]

0 commit comments

Comments
 (0)