init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
107
Telegram/ThirdParty/xdg-desktop-portal/tests/templates/settings.py
vendored
Normal file
107
Telegram/ThirdParty/xdg-desktop-portal/tests/templates/settings.py
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
#
|
||||
# This file is formatted with Python Black
|
||||
# mypy: disable-error-code="misc"
|
||||
|
||||
from tests.templates import init_logger
|
||||
|
||||
import dbus.service
|
||||
from dbusmock import MOCK_IFACE
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
BUS_NAME = "org.freedesktop.impl.portal.Test"
|
||||
MAIN_OBJ = "/org/freedesktop/portal/desktop"
|
||||
SYSTEM_BUS = False
|
||||
MAIN_IFACE = "org.freedesktop.impl.portal.Settings"
|
||||
VERSION = 2
|
||||
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class SettingsParameters:
|
||||
settings: dict
|
||||
|
||||
|
||||
def load(mock, parameters={}):
|
||||
logger.debug(f"Loading parameters: {parameters}")
|
||||
|
||||
assert not hasattr(mock, "settings_params")
|
||||
mock.settings_params = SettingsParameters(
|
||||
settings=parameters.get("settings", {}),
|
||||
)
|
||||
|
||||
mock.AddProperties(
|
||||
MAIN_IFACE,
|
||||
dbus.Dictionary(
|
||||
{
|
||||
"version": dbus.UInt32(parameters.get("version", VERSION)),
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@dbus.service.method(
|
||||
MAIN_IFACE,
|
||||
in_signature="as",
|
||||
out_signature="a{sa{sv}}",
|
||||
)
|
||||
def ReadAll(self, namespaces):
|
||||
logger.debug(f"ReadAll({namespaces})")
|
||||
settings = self.settings_params.settings
|
||||
|
||||
if len(namespaces) == 0 or (len(namespaces) == 1 and namespaces[0] == ""):
|
||||
return settings
|
||||
|
||||
def find_matching(namespace):
|
||||
if len(namespace) >= 3 and namespace[-2:] == ".*":
|
||||
ns_prefix = namespace[:-2]
|
||||
matches = {}
|
||||
for ns in settings:
|
||||
if ns.startswith(ns_prefix):
|
||||
matches[ns] = settings[ns]
|
||||
return matches
|
||||
|
||||
if namespace in settings:
|
||||
return {namespace: settings[namespace]}
|
||||
|
||||
return {}
|
||||
|
||||
result = dbus.Dictionary({}, signature="sa{sv}")
|
||||
for ns in namespaces:
|
||||
result |= find_matching(ns)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@dbus.service.method(
|
||||
MAIN_IFACE,
|
||||
in_signature="ss",
|
||||
out_signature="v",
|
||||
)
|
||||
def Read(self, namespace, key):
|
||||
logger.debug(f"Read({namespace}, {key})")
|
||||
settings = self.settings_params.settings
|
||||
|
||||
return settings[namespace][key]
|
||||
|
||||
|
||||
@dbus.service.method(
|
||||
MOCK_IFACE,
|
||||
in_signature="ssv",
|
||||
out_signature="",
|
||||
)
|
||||
def SetSetting(self, namespace, key, value):
|
||||
logger.debug(f"SetSetting({namespace}, {key}, {value})")
|
||||
settings = self.settings_params.settings
|
||||
|
||||
settings.setdefault(namespace, {})[key] = value
|
||||
|
||||
self.EmitSignal(
|
||||
MAIN_IFACE,
|
||||
"SettingChanged",
|
||||
"ssv",
|
||||
[namespace, key, value],
|
||||
)
|
||||
Reference in New Issue
Block a user