Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Boxiang Sun
slapos.package
Commits
df39a86c
Commit
df39a86c
authored
May 29, 2013
by
Jondy Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add testcases for netreport module
parent
d43a8995
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
25 deletions
+122
-25
windows/netreport/README
windows/netreport/README
+5
-0
windows/netreport/setup.py
windows/netreport/setup.py
+13
-5
windows/netreport/src/tests.py
windows/netreport/src/tests.py
+104
-20
No files found.
windows/netreport/README
View file @
df39a86c
...
...
@@ -32,6 +32,11 @@ Then run test:
$ cd src
$ make test
Before test netreport.py,
$ easy_install lxml
$ ln -s /opt/git/slapos.core
Use Cases
=========
...
...
windows/netreport/setup.py
View file @
df39a86c
...
...
@@ -18,7 +18,6 @@ def get_description():
VERSION
=
"0.1.1"
if
sys
.
platform
.
startswith
(
"cygwin"
):
def
get_winver
():
...
...
@@ -42,10 +41,10 @@ else:
def
main
():
setup_args
=
dict
(
name
=
'netreport'
,
name
=
'net
drive.
report'
,
version
=
VERSION
,
download_url
=
'http://'
,
description
=
'A tool used to report the usage of net
resourc
e in the Windows'
,
description
=
'A tool used to report the usage of net
driv
e in the Windows'
,
long_description
=
get_description
(),
keywords
=
[
'netdrive'
,],
scripts
=
[
'src/netreport.py'
],
...
...
@@ -54,8 +53,17 @@ def main():
maintainer
=
'Jondy Zhao'
,
maintainer_email
=
'jondy.zhao@nexedi.com'
,
url
=
'http://'
,
platforms
=
'Platform Independent'
,
license
=
'License :: OSI Approved :: BSD License'
,
license
=
'GPLv3'
,
zip_safe
=
False
,
install_requires
=
[
'lxml'
,
'slapos.core'
,
],
entry_points
=
{
'console_scripts'
:
[
'netdrive-reporter = netreport:main'
,
],
}
)
if
extensions
is
not
None
:
setup_args
[
"ext_modules"
]
=
extensions
...
...
windows/netreport/src/tests.py
View file @
df39a86c
...
...
@@ -4,57 +4,141 @@ import sys
import
os
import
tempfile
import
shutil
import
datetime
sys
.
path
.
insert
(
0
,
'slapos.core'
)
sys
.
path
.
insert
(
0
,
os
.
getcwd
())
import
test.test_support
netuse
=
test
.
test_support
.
import_module
(
'netuse'
)
real_netuse
=
test
.
test_support
.
import_module
(
'netuse'
)
netreport
=
test
.
test_support
.
import_module
(
'netreport'
)
threading
=
test
.
test_support
.
import_module
(
'threading'
)
import
unittest
class
BaseTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
_threads
=
test
.
test_support
.
threading_setup
()
def
tearDown
(
self
):
test
.
test_support
.
threading_cleanup
(
*
self
.
_threads
)
test
.
test_support
.
reap_children
()
class
NetUsageTests
(
BaseTestCase
):
class
NetUseTests
(
unittest
.
TestCase
):
def
test_user_info
(
self
):
u
=
netuse
.
userInfo
()
self
.
assertEquals
(
len
(
u
),
3
)
self
.
assertEquals
(
u
,
[]
)
r
=
real_
netuse
.
userInfo
()
self
.
assertEquals
(
len
(
r
),
3
)
self
.
assertEquals
(
r
,
(
'JONDY'
,
'JONDY'
,
'Administrator'
)
)
def
test_usage_report
(
self
):
r
=
netuse
.
usageReport
()
r
=
real_
netuse
.
usageReport
()
self
.
assertEquals
(
len
(
r
),
0
)
self
.
assertEquals
(
r
,
[])
def
test_usage_report_server
(
self
):
r
=
netuse
.
usageReport
(
'myserver'
)
r
=
real_
netuse
.
usageReport
(
'myserver'
)
self
.
assertEquals
(
len
(
r
),
0
)
self
.
assertEquals
(
r
,
[])
def
test_usage_report_server_is_none
(
self
):
r
=
netuse
.
usageReport
(
None
)
r
=
real_netuse
.
usageReport
(
)
self
.
assertEquals
(
len
(
r
),
0
)
self
.
assertEquals
(
r
,
[])
def
test_usage_report_one_share_folder_to_many_drive
(
self
):
r
=
netuse
.
usageReport
(
None
)
r
=
real_netuse
.
usageReport
(
)
self
.
assertEquals
(
len
(
r
),
0
)
self
.
assertEquals
(
r
,
[])
def
test_usage_report_share_subfolder
(
self
):
r
=
netuse
.
usageReport
(
None
)
r
=
real_netuse
.
usageReport
(
)
self
.
assertEquals
(
len
(
r
),
0
)
self
.
assertEquals
(
r
,
[])
class
BaseTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
_threads
=
test
.
test_support
.
threading_setup
()
self
.
_db_file
=
'/tmp/mytest.db'
options
=
{
'master_url'
:
'http://localhost:12006'
,
'computer_id'
:
'COMP-1500'
,
'server_name'
:
''
,
'report_interval'
:
300
,
'data_file'
:
self
.
_db_file
,
}
self
.
reporter
=
netreport
.
NetDriveUsageReporter
(
options
)
self
.
db
=
self
.
reporter
.
_db
def
tearDown
(
self
):
test
.
test_support
.
threading_cleanup
(
*
self
.
_threads
)
test
.
test_support
.
reap_children
()
self
.
db
.
close
()
if
os
.
path
.
exists
(
self
.
_db_file
):
os
.
remove
(
self
.
_db_file
)
class
NetReportTests
(
BaseTestCase
):
def
test_parse_argument
(
self
):
argv_orig
=
sys
.
argv
[:]
sys
.
argv
=
[
'me'
,
'--master-url'
,
'http://127.0.0.1'
,
'--computer-id'
,
'COMP-1500'
,
'--cert-file'
,
'~/certificate'
,
'--key-file'
,
'~/key'
,
'--report-interval'
,
'500'
,
'--data-file'
,
'/tmp/myreporter'
,
]
opts
=
netreport
.
parseArgumentTuple
()
self
.
assertEquals
(
opts
,
{
'cert_file'
:
'~/certificate'
,
'computer_id'
:
'COMP-1500'
,
'data_file'
:
'/tmp/myreporter'
,
'key_file'
:
'~/key'
,
'master_url'
:
'http://127.0.0.1'
,
'report_interval'
:
'500'
,
'server_name'
:
''
}
)
sys
.
argv
[:]
=
argv_orig
def
test_init_config
(
self
):
self
.
reporter
.
initializeConfigData
()
self
.
assertEquals
(
self
.
reporter
.
_config_id
,
1
)
self
.
assertEquals
(
self
.
reporter
.
_domain_account
,
'JONDY
\
\
Administrator'
)
self
.
assertEquals
(
self
.
reporter
.
_report_date
,
datetime
.
date
.
today
().
isoformat
())
def
test_insert_report
(
self
):
self
.
reporter
.
initializeConfigData
()
t
=
datetime
.
datetime
.
now
().
isoformat
()
self
.
reporter
.
insertUsageReport
(
t
,
500
)
def
test_send_all_report
(
self
):
self
.
reporter
.
initializeConfigData
()
self
.
reporter
.
sendAllReport
()
def
test_generate_daily_report_no_data
(
self
):
self
.
reporter
.
initializeConfigData
()
self
.
reporter
.
insertUsageReport
(
'2011-01-02 12:23:32'
,
500
)
xml
=
self
.
reporter
.
generateDailyReport
(
1
,
'COMP-1500'
,
'SERVER
\
\
JONDY'
,
'2021-03-05'
,
)
self
.
assertEquals
(
xml
,
None
)
def
test_generate_daily_report_no_data
(
self
):
self
.
reporter
.
initializeConfigData
()
self
.
reporter
.
insertUsageReport
(
'2011-01-02 12:23:32'
,
500
)
report_date
=
'2021-03-05'
config_id
=
self
.
reporter
.
_config_id
q
=
self
.
db
.
execute
q
(
"INSERT INTO net_drive_usage "
"(config_id, drive_letter, remote_folder, "
" start, duration, usage_bytes )"
" VALUES (?, ?, ?, ?, ?, ?)"
,
(
config_id
,
'E:'
,
r'\
Se
rver\
P
ath'
,
'2021-03-05 12:23:30'
,
300
,
1000
))
xml
=
self
.
reporter
.
generateDailyReport
(
config_id
,
self
.
reporter
.
computer_id
,
'JONDY
\
\
Adminstrator'
,
report_date
,
)
self
.
assertEquals
(
xml
,
"<?xml version='1.0' encoding='utf-8'?>
\
n
<report><computer>COMP-1500</computer><account>JONDY
\
\
Adminstrator</account><date>2021-03-05</date><usage>300000.0</usage><details/></report>"
)
if
__name__
==
"__main__"
:
# unittest.main()
loader
=
unittest
.
TestLoader
()
# loader.testMethodPrefix = 'test_'
suite
=
loader
.
loadTestsFromTestCase
(
NetUsageTests
)
unittest
.
TextTestRunner
(
verbosity
=
2
).
run
(
suite
)
suite1
=
loader
.
loadTestsFromTestCase
(
NetUseTests
)
suite2
=
loader
.
loadTestsFromTestCase
(
NetReportTests
)
alltests
=
unittest
.
TestSuite
([
suite1
,
suite2
])
unittest
.
TextTestRunner
(
verbosity
=
2
).
run
(
alltests
)
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