tests (unit): Fix tests.
This commit is contained in:
parent
3a2a5f787d
commit
e68278a1ac
1 changed files with 88 additions and 102 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Libervia: an XMPP client
|
||||
# Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
|
||||
# Copyright (C) 2009-2025 Jérôme Poisson (goffi@goffi.org)
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
|
|
@ -21,6 +21,8 @@ from unittest.mock import MagicMock, AsyncMock
|
|||
from pytest import fixture
|
||||
from twisted.internet import defer
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from libervia.backend import G
|
||||
from wokkel.data_form import NS_X_DATA
|
||||
from libervia.backend.core.main import LiberviaBackend
|
||||
from libervia.backend.tools import async_trigger as trigger
|
||||
from libervia.backend.core import xmpp
|
||||
|
|
@ -42,6 +44,7 @@ def storage():
|
|||
class MockLiberviaBackend(LiberviaBackend):
|
||||
|
||||
def __init__(self, bridge, storage):
|
||||
G.set_host(self)
|
||||
self._cb_map = {}
|
||||
self._menus = {}
|
||||
self._menus_paths = {}
|
||||
|
|
@ -51,7 +54,7 @@ class MockLiberviaBackend(LiberviaBackend):
|
|||
# map for short name to whole namespace,
|
||||
# extended by plugins with register_namespace
|
||||
self.ns_map = {
|
||||
"x-data": xmpp.NS_X_DATA,
|
||||
"x-data": NS_X_DATA,
|
||||
"disco#info": xmpp.NS_DISCO_INFO,
|
||||
}
|
||||
self.memory = MagicMock()
|
||||
|
|
@ -73,36 +76,11 @@ class MockLiberviaBackend(LiberviaBackend):
|
|||
def get_test_config(self, section, name, default=None):
|
||||
return self._test_config.get((section or None, name), default)
|
||||
|
||||
def set_test_config(self, section, name, value):
|
||||
self._test_config[(section or None, name)] = value
|
||||
|
||||
def clear_test_config(self):
|
||||
self._test_config.clear()
|
||||
|
||||
def register_namespace(self, short_name, namespace):
|
||||
# Plugin classes may be instantiated several times in tests, so we do nothing in
|
||||
# this method to avoid ConflictError.
|
||||
pass
|
||||
|
||||
@contextmanager
|
||||
def use_option_and_reload(self, section, name, value):
|
||||
self.set_test_config(section, name, value)
|
||||
self.reload_plugins()
|
||||
try:
|
||||
yield self
|
||||
finally:
|
||||
self.clear_test_config()
|
||||
self.reload_plugins()
|
||||
|
||||
def reload_plugins(self):
|
||||
self.plugins.clear()
|
||||
self.trigger._TriggerManager__triggers.clear()
|
||||
self.ns_map = {
|
||||
"x-data": xmpp.NS_X_DATA,
|
||||
"disco#info": xmpp.NS_DISCO_INFO,
|
||||
}
|
||||
self._import_plugins()
|
||||
|
||||
def _init(self):
|
||||
pass
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue