Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
47209e42
Commit
47209e42
authored
May 06, 2019
by
Nick Yefremov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remade SttingsdTest, introdues SettingsdTestCase
parent
9b7b6e34
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
161 additions
and
88 deletions
+161
-88
test.py
test.py
+161
-88
No files found.
test.py
View file @
47209e42
...
@@ -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
):
self
.
dbus
=
SystemBus
()
self
.
log_file
=
open
(
"test_log.log"
,
"w"
)
def
test_interactive
(
self
):
for
module_name
in
list_
:
#### auto
print
(
"Module name:
%
s
\n
Want to run all methods of this module automatically? (y/n)"
%
module_name
)
auto
=
False
confirmaion
=
input
()
if
confirmaion
==
"y"
:
auto
=
True
remote_object
=
dbus
.
get_object
(
"org.etersoft.settingsd"
,
"/org/etersoft/settingsd/functions/{}"
.
format
(
module_name
))
remote_object
.
Introspect
()
for
method_name
,
args
in
remote_object
.
__dict__
[
'_introspect_method_map'
]
.
items
():
if
method_name
.
rsplit
(
"."
,
1
)[
1
]
==
"Introspect"
:
continue
if
auto
:
if
args
!=
""
and
args
!=
" "
:
print
(
"Test with arguments:"
,
"."
.
join
((
method_name
.
rsplit
(
"."
,
3
)[
1
:])),
args
)
print
(
"
\n
Proceed 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
else
:
try
:
print
(
"Testing: "
,
"."
.
join
((
method_name
.
rsplit
(
"."
,
3
)[
1
:])))
print
(
"Output: "
,
remote_object
.
__getattr__
(
method_name
.
rsplit
(
"."
,
1
)[
1
])(),
SEPARATOR
)
except
Exception
as
e
:
print
(
SEPARATOR
,
str
(
e
),
SEPARATOR
)
else
:
print
(
"Testing: "
,
"."
.
join
((
method_name
.
rsplit
(
"."
,
3
)[
1
:])),
"
\n
Proceed test? (y/n)"
)
confirmaion
=
input
()
if
confirmaion
==
"y"
:
if
args
!=
""
and
args
!=
" "
:
pass
try
:
print
(
"Output: "
,
remote_object
.
__getattr__
(
method_name
.
rsplit
(
"."
,
1
)[
1
])(),
SEPARATOR
)
except
Exception
as
e
:
print
(
SEPARATOR
,
str
(
e
),
SEPARATOR
)
else
:
print
(
"Skipped...."
+
SEPARATOR
)
def
test_auto
(
self
):
for
module_name
in
list_
:
remote_object
=
dbus
.
get_object
(
"org.etersoft.settingsd"
,
"/org/etersoft/settingsd/functions/{}"
.
format
(
module_name
))
remote_object
.
Introspect
()
for
method_name
,
args
in
remote_object
.
__dict__
[
'_introspect_method_map'
]
.
items
():
if
args
!=
""
and
args
!=
" "
:
print
(
"Test with arguments:"
,
"."
.
join
((
method_name
.
rsplit
(
"."
,
3
)[
1
:])))
try
:
print
(
"Testing: "
,
"."
.
join
((
method_name
.
rsplit
(
"."
,
3
)[
1
:])))
print
(
"Output: "
,
remote_object
.
__getattr__
(
method_name
.
rsplit
(
"."
,
1
)[
1
])(),
SEPARATOR
)
except
Exception
as
e
:
print
(
SEPARATOR
,
str
(
e
),
SEPARATOR
)
self
.
log_file
.
write
(
SEPARATOR
+
str
(
e
)
+
SEPARATOR
)
self
.
log_file
.
close
()
if
__name__
==
"__main__"
:
test_interface
=
TestSettingsdMain
()
if
len
(
sys
.
argv
)
>
1
:
if
sys
.
argv
[
1
]
==
"-i"
or
sys
.
argv
[
1
]
==
"--interactive"
:
test_interface
.
test_interactive
()
elif
sys
.
argv
[
1
]
==
'-h'
or
sys
.
argv
[
1
]
==
"--help"
:
print
(
"Usage:
\
\n\t
python3 test.py [OPTION]
\n
\
\n\t
Options:
\
\n\t
-i, --interactive : Interactive mode (Default: auto mode with skip of argumented methods)
\
\n\t
-h, --help: Get help
\
"
)
exit
(
0
)
test_interface
.
test_auto
()
class
SettingsdTests
:
def
__init__
(
self
,
logger
=
None
):
self
.
dbus
=
SystemBus
()
self
.
logger
=
logger
def
_log
(
self
,
message
,
level
=
"critical"
):
if
self
.
logger
:
if
level
==
"critical"
:
self
.
logger
.
critical
(
message
)
elif
level
==
"debug"
:
self
.
logger
.
debug
(
message
)
elif
level
==
"info"
:
self
.
logger
.
info
(
message
)
else
:
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
()
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
():
if
method_name
.
rsplit
(
"."
,
1
)[
1
]
==
"Introspect"
or
(
args
!=
""
and
args
!=
" "
):
continue
else
:
self
.
_log
(
"Testing: "
,
"."
.
join
((
method_name
.
rsplit
(
"."
,
3
)[
1
:])),
level
=
"info"
)
results
.
append
(
remote_object
.
__getattr__
(
method_name
.
rsplit
(
"."
,
1
)[
1
])())
self
.
_log
(
"Test passed successfully"
,
level
=
"info"
)
return
results
class
SettingsdTestCase
(
TestCase
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
self
.
autotest_
=
SettingsdTests
()
self
.
modules_list_
=
[
"common_info"
,
"date_time"
,
"dnsmasq_config"
,
"example"
,
"local_groups"
,
"local_users"
,
"network"
,
"nss_roles"
,
"ntp_config"
,
"package_updates"
,
"rtorrentd_config"
,
"ssl"
,
"statistics"
,
"system_services"
]
def
test_auto
(
self
):
for
module_
in
self
.
modules_list_
:
for
res
in
self
.
autotest_
.
test_module
(
module_
):
self
.
assertIsNotNone
(
res
)
def
test_time_systemClo
с
k_setUtcTime
(
self
):
self
.
assertIsInstance
(
self
.
autotest_
.
run_method
(
"date_time"
,
"setUtcTime"
,
5
,
6
,
12
,
10
,
2019
,
0
),
int
)
def
test_time_zone_setTimeZone
(
self
):
def
test_
(
entity
):
entity
.
autotest_
.
run_method
(
"date_time"
,
"setTimeZone"
,
"+5"
)
return
"Success"
self
.
assertEqual
(
test_
(
self
),
"Success"
)
def
test_dnsmasq_simple_setServers
(
self
):
pass
def
test_dnsmasq_simple_setInterfaces
(
self
):
pass
def
test_dnsmasq_simple_setExceptInterfaces
(
self
):
pass
def
test_dnsmasq_simple_setRange
(
self
):
pass
def
test_dnsmasq_simple_addStaticHost
(
self
):
pass
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment