summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/api/test_WebSocketBackend.py (renamed from tests/api/test_WebSocketAPI.py)2
-rw-r--r--tests/api/test_noargs.py2
-rw-r--r--tests/helper/Stubs.py14
-rw-r--r--tests/manager/test_configManager.py101
-rw-r--r--tests/other/test_configparser.py50
5 files changed, 130 insertions, 39 deletions
diff --git a/tests/api/test_WebSocketAPI.py b/tests/api/test_WebSocketBackend.py
index ac22d044e..be465e3d4 100644
--- a/tests/api/test_WebSocketAPI.py
+++ b/tests/api/test_WebSocketBackend.py
@@ -5,7 +5,7 @@ from nose.tools import raises
from module.remote.ttypes import Forbidden
from module.remote.WSClient import WSClient
-class TestWebSocketAPI:
+class TestWebSocketBackend:
def setUp(self):
self.client = WSClient()
diff --git a/tests/api/test_noargs.py b/tests/api/test_noargs.py
index 02e49cf13..aa010f293 100644
--- a/tests/api/test_noargs.py
+++ b/tests/api/test_noargs.py
@@ -6,7 +6,7 @@ from ApiTester import ApiTester
from module.remote.ttypes import Iface
-IGNORE = ('kill', 'restart')
+IGNORE = ('stop', 'restart')
class TestNoArgs(ApiTester):
def setUp(self):
diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py
index 4ebd12592..f0e8d0614 100644
--- a/tests/helper/Stubs.py
+++ b/tests/helper/Stubs.py
@@ -11,6 +11,8 @@ sys.path.append(abspath(join(dirname(__file__), "..", "..")))
import __builtin__
+from module.Api import Role
+from module.datatypes.User import User
from module.datatypes.PyPackage import PyPackage
from module.threads.BaseThread import BaseThread
from module.config.ConfigParser import ConfigParser
@@ -69,7 +71,8 @@ class Core:
__builtin__.pyreq = self.requestFactory
self.accountManager = AccountManager()
self.addonManager = AddonManager()
- self.eventManager = self.interActionManager = NoopClass()
+ self.eventManager = self.evm = NoopClass()
+ self.interActionManager = self.im = NoopClass()
self.js = JsEngine()
self.cache = {}
self.packageCache = {}
@@ -95,7 +98,7 @@ class Core:
def getPackage(self, id):
return PyPackage(self, 0, "tmp", "tmp", "", "", 0, 0)
-
+
def print_exc(self):
log(ERROR, format_exc())
@@ -104,15 +107,17 @@ class NoopClass:
def __getattr__(self, item):
return noop
+
class AddonManager(NoopClass):
def activePlugins(self):
return []
-class AccountManager:
+class AccountManager:
def getAccountForPlugin(self, name):
return None
+
class Thread(BaseThread):
def __init__(self, core):
BaseThread.__init__(self, core)
@@ -131,3 +136,6 @@ __builtin__._ = lambda x: x
__builtin__.pypath = abspath(join(dirname(__file__), "..", ".."))
__builtin__.addonManager = AddonManager()
__builtin__.pyreq = None
+
+adminUser = User(None, uid=0, role=Role.Admin)
+normalUser = User(None, uid=1, role=Role.User) \ No newline at end of file
diff --git a/tests/manager/test_configManager.py b/tests/manager/test_configManager.py
new file mode 100644
index 000000000..1cfb6a5de
--- /dev/null
+++ b/tests/manager/test_configManager.py
@@ -0,0 +1,101 @@
+# -*- coding: utf-8 -*-
+
+from unittest import TestCase
+from collections import defaultdict
+
+from nose.tools import raises
+
+from tests.helper.Stubs import Core, adminUser, normalUser
+
+from module.Api import InvalidConfigSection
+from module.database import DatabaseBackend
+from module.config.ConfigParser import ConfigParser
+from module.config.ConfigManager import ConfigManager
+
+class TestConfigManager(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls.core = Core()
+ cls.db = DatabaseBackend(cls.core)
+ cls.core.db = cls.db
+ cls.db.manager = cls.core
+ cls.db.manager.statusMsg = defaultdict(lambda: "statusmsg")
+ cls.parser = ConfigParser()
+ cls.config = ConfigManager(cls.core, cls.parser)
+ cls.db.setup()
+
+ def setUp(self):
+ self.db.clearAllConfigs()
+
+ def addConfig(self):
+ self.config.addConfigSection("plugin", "Name", "desc", "something",
+ [("value", "str", "label", "desc", "default")])
+
+ def test_db(self):
+
+ self.db.saveConfig("plugin", "some value", 0)
+ self.db.saveConfig("plugin", "some other value", 1)
+
+ assert self.db.loadConfig("plugin", 0) == "some value"
+ assert self.db.loadConfig("plugin", 1) == "some other value"
+
+ d = self.db.loadAllConfigs()
+ assert d[0]["plugin"] == "some value"
+
+ self.db.deleteConfig("plugin", 0)
+
+ assert 0 not in self.db.loadAllConfigs()
+
+ self.db.deleteConfig("plugin")
+
+ assert not self.db.loadAllConfigs()
+ assert self.db.loadConfig("plugin") == ""
+
+ def test_parser(self):
+ assert self.config.get("general", "language")
+ self.config["general"]["language"] = "de"
+ assert self.config["general"]["language"] == "de"
+ assert self.config.get("general", "language", adminUser) == "de"
+
+ def test_user(self):
+ self.addConfig()
+
+ assert self.config["plugin"]["value"] == "default"
+ assert self.config.get("plugin", "value", adminUser) == "default"
+ assert self.config.get("plugin", "value", normalUser) == "default"
+
+ assert self.config.set("plugin", "value", False, user=normalUser)
+ assert self.config.get("plugin", "value", normalUser) is False
+ assert self.config["plugin"]["value"] == "default"
+
+ assert self.config.set("plugin", "value", True, user=adminUser)
+ assert self.config.get("plugin", "value", adminUser) is True
+ assert self.config["plugin"]["value"] is True
+ assert self.config.get("plugin", "value", normalUser) is False
+
+ self.config.delete("plugin", normalUser)
+ assert self.config.get("plugin", "value", normalUser) == "default"
+
+ self.config.delete("plugin")
+ assert self.config.get("plugin", "value", adminUser) == "default"
+ assert self.config["plugin"]["value"] == "default"
+
+ # should not trigger something
+ self.config.delete("foo")
+
+
+ def test_sections(self):
+ pass
+
+ @raises(InvalidConfigSection)
+ def test_restricted_access(self):
+ self.config.get("general", "language", normalUser)
+
+ @raises(InvalidConfigSection)
+ def test_error(self):
+ self.config.get("foo", "bar")
+
+ @raises(InvalidConfigSection)
+ def test_error_set(self):
+ self.config.set("foo", "bar", True) \ No newline at end of file
diff --git a/tests/other/test_configparser.py b/tests/other/test_configparser.py
index acb05c63e..51ffc5a68 100644
--- a/tests/other/test_configparser.py
+++ b/tests/other/test_configparser.py
@@ -1,44 +1,18 @@
# -*- coding: utf-8 -*-
-from collections import defaultdict
+from nose.tools import raises
+
from tests.helper.Stubs import Core
-from module.database import DatabaseBackend
from module.config.ConfigParser import ConfigParser
-# TODO
class TestConfigParser():
- db = None
-
@classmethod
def setUpClass(cls):
- cls.db = DatabaseBackend(Core())
- cls.db.manager = cls.db.core
- cls.db.manager.statusMsg = defaultdict(lambda: "statusmsg")
+ # Only needed to get imports right
+ cls.core = Core()
cls.config = ConfigParser()
- cls.db.setup()
- cls.db.clearAllConfigs()
-
- @classmethod
- def tearDownClass(cls):
- cls.db.shutdown()
-
- def test_db(self):
-
- self.db.saveConfig("plugin", "some value", 0)
- self.db.saveConfig("plugin", "some other value", 1)
-
- assert self.db.loadConfig("plugin", 0) == "some value"
- assert self.db.loadConfig("plugin", 1) == "some other value"
-
- d = self.db.loadAllConfigs()
- assert d[0]["plugin"] == "some value"
-
- self.db.deleteConfig("plugin")
-
- assert not self.db.loadAllConfigs()
-
def test_dict(self):
@@ -46,8 +20,16 @@ class TestConfigParser():
self.config["general"]["language"] = "de"
assert self.config["general"]["language"] == "de"
- def test_config(self):
- pass
+ def test_contains(self):
+
+ assert "general" in self.config
+ assert "foobaar" not in self.config
+
+
+ @raises(KeyError)
+ def test_invalid_config(self):
+ print self.config["invalid"]["config"]
- def test_userconfig(self):
- pass \ No newline at end of file
+ @raises(KeyError)
+ def test_invalid_section(self):
+ print self.config["general"]["invalid"] \ No newline at end of file