Skip to content

Commit 212eba6

Browse files
committed
dbus: test History.list
1 parent ee8a713 commit 212eba6

2 files changed

Lines changed: 163 additions & 0 deletions

File tree

dnf-behave-tests/dnf/api/dbus/history.feature

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,138 @@ Scenario: History::recent_changes() accepts "all_advisories" option
243243
downgraded: 0
244244
removed: 0
245245
"""
246+
247+
248+
Scenario: History::list() all transactions by default
249+
When I execute python libdnf5 dbus api script with history interface
250+
"""
251+
options = {{
252+
}}
253+
254+
transactions = iface_history.list(options)
255+
for k in transactions:
256+
# print id and last two words of transaction description
257+
print(str(k.get("id")) + " " + " ".join(k.get("description").split()[-2:]))
258+
"""
259+
Then the exit code is 0
260+
And stdout is
261+
"""
262+
6 remove labirinto
263+
5 downgrade fragola
264+
4 upgrade fragola
265+
3 install labirinto
266+
2 upgrade fragola-2
267+
1 install fragola-1
268+
"""
269+
270+
271+
Scenario: History::list() reversed with a limit
272+
When I execute python libdnf5 dbus api script with history interface
273+
"""
274+
options = {{
275+
"reverse": True,
276+
"limit": dbus.Int64(3)
277+
}}
278+
279+
transactions = iface_history.list(options)
280+
for k in transactions:
281+
# print id and last two words of transaction description
282+
print(str(k.get("id")) + " " + " ".join(k.get("description").split()[-2:]))
283+
"""
284+
Then the exit code is 0
285+
And stdout is
286+
"""
287+
1 install fragola-1
288+
2 upgrade fragola-2
289+
3 install labirinto
290+
"""
291+
292+
293+
Scenario: History::list() with specified package
294+
When I execute python libdnf5 dbus api script with history interface
295+
"""
296+
options = {{
297+
"contains_pkgs": ["fragola"],
298+
}}
299+
300+
transactions = iface_history.list(options)
301+
for k in transactions:
302+
# print id and last two words of transaction description
303+
print(str(k.get("id")) + " " + " ".join(k.get("description").split()[-2:]))
304+
"""
305+
Then the exit code is 0
306+
And stdout is
307+
"""
308+
5 downgrade fragola
309+
4 upgrade fragola
310+
2 upgrade fragola-2
311+
1 install fragola-1
312+
"""
313+
314+
315+
Scenario: History::list() since timestamp
316+
When I execute python libdnf5 dbus api script with history interface
317+
"""
318+
options = {{
319+
"since": dbus.Int64(40)
320+
}}
321+
322+
transactions = iface_history.list(options)
323+
for k in transactions:
324+
# print id and last two words of transaction description
325+
print(str(k.get("id")) + " " + " ".join(k.get("description").split()[-2:]))
326+
"""
327+
Then the exit code is 0
328+
And stdout is
329+
"""
330+
6 remove labirinto
331+
5 downgrade fragola
332+
"""
333+
334+
335+
Scenario: History::list() without packages and limited transaction attributes
336+
When I execute python libdnf5 dbus api script with history interface
337+
"""
338+
options = {{
339+
"transaction_attrs": ["id"],
340+
"include_packages": False
341+
}}
342+
343+
transactions = dbus_to_python(iface_history.list(options))
344+
for k in transactions:
345+
print(k)
346+
"""
347+
Then the exit code is 0
348+
And stdout is
349+
"""
350+
{{'id': 6}}
351+
{{'id': 5}}
352+
{{'id': 4}}
353+
{{'id': 3}}
354+
{{'id': 2}}
355+
{{'id': 1}}
356+
"""
357+
358+
359+
Scenario: History::list() with limited package attributes and limited transaction attributes
360+
When I execute python libdnf5 dbus api script with history interface
361+
"""
362+
options = {{
363+
"transaction_attrs": ["id"],
364+
"package_attrs": ["name"]
365+
}}
366+
367+
transactions = dbus_to_python(iface_history.list(options))
368+
for k in transactions:
369+
print(k)
370+
"""
371+
Then the exit code is 0
372+
And stdout is
373+
"""
374+
{{'downgraded': [], 'id': 6, 'installed': [], 'reinstalled': [], 'removed': [{{'name': 'labirinto'}}], 'upgraded': []}}
375+
{{'downgraded': [{{'name': 'fragola', 'original_evr': '4-1'}}], 'id': 5, 'installed': [], 'reinstalled': [], 'removed': [], 'upgraded': []}}
376+
{{'downgraded': [], 'id': 4, 'installed': [], 'reinstalled': [], 'removed': [], 'upgraded': [{{'name': 'fragola', 'original_evr': '2-1'}}]}}
377+
{{'downgraded': [], 'id': 3, 'installed': [{{'name': 'labirinto'}}], 'reinstalled': [], 'removed': [], 'upgraded': []}}
378+
{{'downgraded': [], 'id': 2, 'installed': [], 'reinstalled': [], 'removed': [], 'upgraded': [{{'name': 'fragola', 'original_evr': '1-1'}}]}}
379+
{{'downgraded': [], 'id': 1, 'installed': [{{'name': 'fragola'}}], 'reinstalled': [], 'removed': [], 'upgraded': []}}
380+
"""

dnf-behave-tests/dnf/steps/dbus.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@ def print_recent_history(dbus_output):
6969
print("{{}}: {{}}".format(key, len(pkgs)))
7070
print_recent_history_pkgs(pkgs)
7171
72+
def dbus_to_python(data):
73+
# Handle Dictionaries
74+
if isinstance(data, (dbus.Dictionary, dict)):
75+
return {{dbus_to_python(k): dbus_to_python(v) for k, v in data.items()}}
76+
77+
# Handle Lists/Arrays
78+
elif isinstance(data, (dbus.Array, list, tuple)):
79+
return [dbus_to_python(i) for i in data]
80+
81+
# Handle Variants
82+
# Most dbus-python types inherit from their native counterparts
83+
# but we cast them to be sure metadata is stripped.
84+
elif isinstance(data, (dbus.String, dbus.ObjectPath, dbus.Signature)):
85+
return str(data)
86+
elif isinstance(data, (dbus.Int16, dbus.Int32, dbus.Int64,
87+
dbus.UInt16, dbus.UInt32, dbus.UInt64)):
88+
return int(data)
89+
elif isinstance(data, dbus.Byte):
90+
return int(data)
91+
elif isinstance(data, dbus.Boolean):
92+
return bool(data)
93+
elif isinstance(data, dbus.Double):
94+
return float(data)
95+
96+
# If it's already a native type or unknown, return as is
97+
return data
98+
99+
72100
iface_history = dbus.Interface(
73101
bus.get_object(DNFDAEMON_BUS_NAME, session),
74102
dbus_interface=IFACE_HISTORY)

0 commit comments

Comments
 (0)