Commit 65296116 authored by Jondy Zhao's avatar Jondy Zhao

Add testcase skeleton;

Add docs for netuse method;
parent 01dca258
...@@ -134,6 +134,7 @@ netuse_user_info(PyObject *self, PyObject *args) ...@@ -134,6 +134,7 @@ netuse_user_info(PyObject *self, PyObject *args)
static PyObject * static PyObject *
netuse_map_drive(PyObject *self, PyObject *args) netuse_map_drive(PyObject *self, PyObject *args)
{ {
PyErr_SetString(PyExc_RuntimeError, "Not Implemented");
return NULL; return NULL;
} }
...@@ -144,8 +145,8 @@ netuse_usage_report(PyObject *self, PyObject *args) ...@@ -144,8 +145,8 @@ netuse_usage_report(PyObject *self, PyObject *args)
PyObject *retvalue = NULL; PyObject *retvalue = NULL;
DWORD bitmasks; DWORD bitmasks;
char chdrive = '@'; char chdrive = '@';
char drivepath[4] = { 'A', ':', '\\', 0 }; char drivepath[] = { 'A', ':', '\\', 0 };
char drivename[3] = { 'A', ':', 0 }; char drivename[] = { 'A', ':', 0 };
ULARGE_INTEGER lFreeBytesAvailable; ULARGE_INTEGER lFreeBytesAvailable;
ULARGE_INTEGER lTotalNumberOfBytes; ULARGE_INTEGER lTotalNumberOfBytes;
ULARGE_INTEGER lTotalNumberOfFreeBytes; ULARGE_INTEGER lTotalNumberOfFreeBytes;
...@@ -198,7 +199,7 @@ netuse_usage_report(PyObject *self, PyObject *args) ...@@ -198,7 +199,7 @@ netuse_usage_report(PyObject *self, PyObject *args)
&cchBuff &cchBuff
); );
if (dwResult == NO_ERROR) { if (dwResult == NO_ERROR) {
if (servername) { if (serverlen) {
if ((cchBuff < serverlen + 3) || if ((cchBuff < serverlen + 3) ||
(strncmp(servername, szRemoteName+2, serverlen) != 0) || (strncmp(servername, szRemoteName+2, serverlen) != 0) ||
(szRemoteName[serverlen + 2] != '\\') (szRemoteName[serverlen + 2] != '\\')
...@@ -282,9 +283,11 @@ static PyMethodDef NetUseMethods[] = { ...@@ -282,9 +283,11 @@ static PyMethodDef NetUseMethods[] = {
netuse_usage_report, netuse_usage_report,
METH_VARARGS, METH_VARARGS,
( (
"usagereport()\n\n" "usagereport(servername='')\n\n"
"Return a tuple to report all the mapped drive information:\n" "Return a tuple to report all the net drive information:\n"
"(user, domain, drive, usage, total).\n" "(drive, remote, available, free, total).\n"
"If servername is not empty, then only net drives in the specified server\n"
"are returned.\n"
) )
}, },
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
......
# -*- coding: utf-8 -*-
import sys
import os
import tempfile
import shutil
import netuse
import unittest
class BaseTestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
class NetUsageTests(BaseTestCase):
def test_user_info(self):
u = netuse.userinfo()
self.assertEquals(len(u), 3)
self.assertEquals(u, [])
def test_usage_report(self):
r = netuse.usagereport()
self.assertEquals(len(r), 0)
self.assertEquals(r, [])
def test_usage_report_server(self):
r = netuse.usagereport('myserver')
self.assertEquals(len(r), 0)
self.assertEquals(r, [])
if __name__ == "__main__":
# unittest.main()
loader = unittest.TestLoader()
# loader.testMethodPrefix = 'test_'
suite = loader.loadTestsFromTestCase(NetUsageTests)
unittest.TextTestRunner(verbosity=2).run(suite)
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