Commit 47209e42 authored by Nick Yefremov's avatar Nick Yefremov

Remade SttingsdTest, introdues SettingsdTestCase

parent 9b7b6e34
...@@ -4,96 +4,169 @@ from dbus import SystemBus ...@@ -4,96 +4,169 @@ from dbus import SystemBus
import os, sys import os, sys
SEPARATOR = "\n" + "-"*30 + "\n" SEPARATOR = "\n" + "-" * 30 + "\n"
list_ = ["common_info", "date_time", "dnsmasq_config", "example", list_ = ["common_info", "date_time", "dnsmasq_config", "example",
"local_groups", "local_users", "network", "nss_roles", "local_groups", "local_users", "network", "nss_roles",
"ntp_config", "package_updates", "rtorrentd_config", "ssl", "ntp_config", "package_updates", "rtorrentd_config", "ssl",
"statistics", "system_services"] "statistics", "system_services"]
class TestSettingsdMain():
def __init__(self, *args, **kwargs): class SettingsdTests:
def __init__(self, logger=None):
self.dbus = SystemBus() self.dbus = SystemBus()
self.log_file = open("test_log.log", "w") self.logger = logger
def test_interactive(self): def _log(self, message, level="critical"):
for module_name in list_: if self.logger:
#### auto if level == "critical":
print("Module name: %s\nWant to run all methods of this module automatically? (y/n)" % module_name) self.logger.critical(message)
auto = False elif level == "debug":
confirmaion = input() self.logger.debug(message)
if confirmaion == "y": elif level == "info":
auto = True self.logger.info(message)
else:
remote_object = dbus.get_object("org.etersoft.settingsd", "/org/etersoft/settingsd/functions/{}".format(module_name)) print("-" * 30)
print(level.upper() + ":\n" + message)
print("-" * 30)
def load_module(self, module_):
remote_object = self.dbus.get_object("org.etersoft.settingsd", "/org/etersoft/settingsd/functions/{}"
.format(module_))
remote_object.Introspect() remote_object.Introspect()
return remote_object
def run_method(self, module_, func_, *args, **kwargs):
object_ = self.load_module(module_)
return object_.__getattr__(func_)(*args, **kwargs)
def test_module(self, module_name):
remote_object = self.load_module(module_name)
results = []
for method_name, args in remote_object.__dict__['_introspect_method_map'].items(): for method_name, args in remote_object.__dict__['_introspect_method_map'].items():
if method_name.rsplit(".", 1)[1] == "Introspect": if method_name.rsplit(".", 1)[1] == "Introspect" or (args != "" and args != " "):
continue
if auto:
if args != "" and args !=" ":
print("Test with arguments:", ".".join((method_name.rsplit(".", 3)[1:])), args)
print( "\nProceed test? (y/n)")
confirmaion = input()
if confirmaion == "y":
print("Argument(%d) types: " % len(args), *args)
print("Enter arguments:\n")
in_args = input().split()
try:
print("Output: ", remote_object.__getattr__(method_name.rsplit(".", 1)[1])(*in_args), SEPARATOR)
except Exception as e:
print(SEPARATOR, str(e), SEPARATOR)
else:
continue continue
else: else:
try: self._log("Testing: ", ".".join((method_name.rsplit(".", 3)[1:])), level="info")
print("Testing: ", ".".join((method_name.rsplit(".", 3)[1:]))) results.append(remote_object.__getattr__(method_name.rsplit(".", 1)[1])())
print("Output: ", remote_object.__getattr__(method_name.rsplit(".", 1)[1])(), SEPARATOR) self._log("Test passed successfully", level="info")
except Exception as e: return results
print(SEPARATOR, str(e), SEPARATOR)
else:
print("Testing: ", ".".join((method_name.rsplit(".", 3)[1:])), "\nProceed test? (y/n)") class SettingsdTestCase(TestCase):
confirmaion = input() def __init__(self, *args, **kwargs):
if confirmaion == "y": super().__init__(*args, **kwargs)
if args != "" and args != " ": self.autotest_ = SettingsdTests()
pass self.modules_list_ = ["common_info", "date_time", "dnsmasq_config", "example",
try: "local_groups", "local_users", "network", "nss_roles",
print("Output: ", remote_object.__getattr__(method_name.rsplit(".", 1)[1])(), SEPARATOR) "ntp_config", "package_updates", "rtorrentd_config", "ssl",
except Exception as e: "statistics", "system_services"]
print(SEPARATOR, str(e), SEPARATOR)
else:
print("Skipped...." + SEPARATOR)
def test_auto(self): def test_auto(self):
for module_name in list_: for module_ in self.modules_list_:
remote_object = dbus.get_object("org.etersoft.settingsd", "/org/etersoft/settingsd/functions/{}".format(module_name)) for res in self.autotest_.test_module(module_):
remote_object.Introspect() self.assertIsNotNone(res)
for method_name, args in remote_object.__dict__['_introspect_method_map'].items():
if args != "" and args !=" ": def test_time_systemCloсk_setUtcTime(self):
print("Test with arguments:", ".".join((method_name.rsplit(".", 3)[1:]))) self.assertIsInstance(self.autotest_.run_method("date_time", "setUtcTime", 5, 6, 12, 10, 2019, 0), int)
try:
print("Testing: ", ".".join((method_name.rsplit(".", 3)[1:]))) def test_time_zone_setTimeZone(self):
print("Output: ", remote_object.__getattr__(method_name.rsplit(".", 1)[1])(), SEPARATOR) def test_(entity):
except Exception as e: entity.autotest_.run_method("date_time", "setTimeZone", "+5")
print(SEPARATOR, str(e), SEPARATOR) return "Success"
self.log_file.write(SEPARATOR + str(e) + SEPARATOR) self.assertEqual(test_(self), "Success")
self.log_file.close()
def test_dnsmasq_simple_setServers(self):
pass
if __name__ == "__main__":
test_interface = TestSettingsdMain() def test_dnsmasq_simple_setInterfaces(self):
if len(sys.argv) > 1: pass
if sys.argv[1] == "-i" or sys.argv[1] == "--interactive":
test_interface.test_interactive() def test_dnsmasq_simple_setExceptInterfaces(self):
elif sys.argv[1] == '-h' or sys.argv[1] == "--help": pass
print("Usage:\
\n\tpython3 test.py [OPTION]\n \ def test_dnsmasq_simple_setRange(self):
\n\tOptions:\ pass
\n\t-i, --interactive : Interactive mode (Default: auto mode with skip of argumented methods)\
\n\t-h, --help: Get help\ def test_dnsmasq_simple_addStaticHost(self):
") pass
exit(0)
test_interface.test_auto() def test_dnsmasq_simple_removeStaticHost(self):
pass
def test_functions_localGroups_addGroup(self):
pass
def test_functions_localGroups_removeGroup(self):
pass
def test_functions_localUsers_addUser(self):
pass
def test_functions_localUsers_removeUser(self):
pass
def test_functions_network_dumpCurrentSettingsd(self):
pass
def test_functions_network_reloadNetworkConfig(self):
pass
def test_functions_nssRoles_addRole(self):
pass
def test_functions_nssRoles_removeRole(self):
pass
def test_time_ntp_setServers(self):
pass
def test_rtorrent_daemon_setUser(self):
pass
def test_rtorrent_daemon_setDownloadsDir(self):
pass
def test_rtorrent_daemon_setSessionDir(self):
pass
def test_rtorrent_daemon_setTmpDir(self):
pass
def test_rtorrent_daemon_setSocketPath(self):
pass
def test_rtorrent_daemon_setSocketUser(self):
pass
def test_rtorrent_daemon_setSockerGroup(self):
pass
def test_rtorrent_daemon_setSocketMode(self):
pass
def test_rtorrent_daemon_setRawConfigPath(self):
pass
def test_rtorrent_daemon_setRawConfig(self):
pass
def test_functions_ssl_setCertificate(self):
pass
def test_functions_systemService_enable(self):
pass
def test_functions_systemService_disable(self):
pass
def test_functions_systemService_reload(self):
pass
def test_functions_systemService_start(self):
pass
def test_functions_systemService_stop(self):
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment