-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: use DBusMock template, port to ApkPolkit2 interface
Using the template allows to run more code on method calls and do more complicated logic. Helps #32
- Loading branch information
1 parent
78171ec
commit 5543a01
Showing
2 changed files
with
115 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# apkpolkit1.py -- apkPolkit1 mock template | ||
# | ||
# Copyright (C) 2022 Pablo Correa Gomez <[email protected]> | ||
# | ||
# SPDX-License-Identifier: GPL-2.0+ | ||
|
||
import dbus | ||
import dbusmock | ||
|
||
import time | ||
|
||
# These should ideally be directly fetched from C | ||
APK_POLKIT_STATE_AVAILABLE = 0 | ||
APK_POLKIT_STATE_INSTALLED = 1 | ||
APK_POLKIT_STATE_UPGRADABLE = 4 | ||
APK_POLKIT_STATE_DOWNGRADABLE = 5 | ||
|
||
BUS_NAME = 'dev.Cogitri.apkPolkit2' | ||
MAIN_OBJ = '/dev/Cogitri/apkPolkit2' | ||
MAIN_IFACE = 'dev.Cogitri.apkPolkit2' | ||
SYSTEM_BUS = True | ||
|
||
def load(mock, parameters): | ||
repos = [ | ||
(True, "a", "https://alpine.org/alpine/edge/main"), | ||
(False, "b", "https://pmos.org/pmos/master"), | ||
(True, "c", "/home/data/foo/bar/baz"), | ||
] | ||
mock.repos = repos | ||
|
||
pkgs = [ | ||
{"name": "apk-test-app", | ||
"description": "desktop app", | ||
"installed_size": dbus.UInt64(50), | ||
"version": "0.1.0-r0", | ||
"license": "GPL", | ||
"package_state": dbus.UInt32(APK_POLKIT_STATE_AVAILABLE), | ||
"size": dbus.UInt64(40), | ||
"url": "url"}, | ||
{"name": "system-pkg", | ||
"description": "system package", | ||
"installed_size": dbus.UInt64(50), | ||
"version": "2.0-r0", | ||
"license": "GPL", | ||
"package_state": dbus.UInt32(APK_POLKIT_STATE_AVAILABLE), | ||
"size": dbus.UInt64(40), | ||
"url": "url"}, | ||
] | ||
mock.pkgs = pkgs | ||
|
||
mock.AddMethods(MAIN_IFACE, [ | ||
('AddRepository', 's', '', ''), | ||
('RemoveRepository', 's', '', ''), | ||
('UpdateRepositories', '', '', ''), | ||
]) | ||
|
||
|
||
@dbus.service.method(MAIN_IFACE, in_signature='s', out_signature='') | ||
def AddPackage(self, pkg_name): | ||
if (pkg_name == "slow"): | ||
time.sleep(10) | ||
|
||
@dbus.service.method(MAIN_IFACE, in_signature='s', out_signature='') | ||
def DeletePackage(self, pkg_name): | ||
if (pkg_name == "slow"): | ||
time.sleep(10) | ||
|
||
@dbus.service.method(MAIN_IFACE, in_signature='asu', out_signature='aa{sv}') | ||
def GetPackagesDetails(self, packages, requestedProperties): | ||
apps = [] | ||
# We only expect to refine the desktop app for now. | ||
# Ideally, the state should be updated on the different DBus calls | ||
for pkg in packages: | ||
if pkg == "apk-test-app": | ||
apps.append(self.pkgs[0]) | ||
else: | ||
apps.append({"name": pkg, "error": "pkg not found!"}) | ||
|
||
return apps | ||
|
||
@dbus.service.method(MAIN_IFACE, in_signature='', out_signature='a(bss)') | ||
def ListRepositories(self): | ||
return self.repos | ||
|
||
@dbus.service.method(MAIN_IFACE, in_signature='u', out_signature='aa{sv}') | ||
def ListUpgradablePackages(self, requestedProperties): | ||
for pkg in self.pkgs: | ||
if pkg["name"] == "apk-test-app": | ||
pkg["package_state"] = dbus.UInt32(APK_POLKIT_STATE_UPGRADABLE) | ||
pkg["staging_version"] = "0.2.0-r0" | ||
if pkg["name"] == "system-pkg": | ||
pkg["package_state"] = dbus.UInt32(APK_POLKIT_STATE_DOWNGRADABLE) | ||
pkg["staging_version"] = "0.1.0-r0" | ||
return self.pkgs | ||
|
||
|
||
@dbus.service.method(MAIN_IFACE, in_signature='as', out_signature='') | ||
def UpgradePackages(self, packages): | ||
for pkg in packages: | ||
for p in self.pkgs: | ||
if p["name"] == pkg: | ||
p["version"] = p["staging_version"] | ||
p["package_state"] = dbus.UInt32(APK_POLKIT_STATE_INSTALLED) | ||
|
||
# @dbus.service.method(MAIN_IFACE, in_signature='asu', out_signature='aa{sv}') | ||
# def SearchFilesOwners(self, paths, requestedProperties): | ||
# return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters