mirror of
https://github.com/samba-team/samba.git
synced 2025-07-26 03:42:04 +03:00
python: Use samba.tests.TestCase, make sure base class tearDown and
setUp methods are called, fix formatting.
This commit is contained in:
@ -30,9 +30,10 @@ from testtools.testcase import TestCase, TestSkipped
|
||||
|
||||
|
||||
class LdbTestCase(TestCase):
|
||||
|
||||
"""Trivial test case for running tests against a LDB."""
|
||||
|
||||
def setUp(self):
|
||||
super(LdbTestCase, self).setUp()
|
||||
self.filename = os.tempnam()
|
||||
self.ldb = samba.Ldb(self.filename)
|
||||
|
||||
@ -63,14 +64,16 @@ class SubstituteVarTestCase(TestCase):
|
||||
self.assertEquals("", samba.substitute_var("", {}))
|
||||
|
||||
def test_nothing(self):
|
||||
self.assertEquals("foo bar", samba.substitute_var("foo bar", {"bar": "bla"}))
|
||||
self.assertEquals("foo bar",
|
||||
samba.substitute_var("foo bar", {"bar": "bla"}))
|
||||
|
||||
def test_replace(self):
|
||||
self.assertEquals("foo bla", samba.substitute_var("foo ${bar}", {"bar": "bla"}))
|
||||
self.assertEquals("foo bla",
|
||||
samba.substitute_var("foo ${bar}", {"bar": "bla"}))
|
||||
|
||||
def test_broken(self):
|
||||
self.assertEquals("foo ${bdkjfhsdkfh sdkfh ",
|
||||
samba.substitute_var("foo ${bdkjfhsdkfh sdkfh ", {"bar": "bla"}))
|
||||
samba.substitute_var("foo ${bdkjfhsdkfh sdkfh ", {"bar": "bla"}))
|
||||
|
||||
def test_unknown_var(self):
|
||||
self.assertEquals("foo ${bla} gsff",
|
||||
@ -78,7 +81,8 @@ class SubstituteVarTestCase(TestCase):
|
||||
|
||||
def test_check_all_substituted(self):
|
||||
samba.check_all_substituted("nothing to see here")
|
||||
self.assertRaises(Exception, samba.check_all_substituted, "Not subsituted: ${FOOBAR}")
|
||||
self.assertRaises(Exception, samba.check_all_substituted,
|
||||
"Not subsituted: ${FOOBAR}")
|
||||
|
||||
|
||||
class LdbExtensionTests(TestCaseInTempDir):
|
||||
@ -88,7 +92,8 @@ class LdbExtensionTests(TestCaseInTempDir):
|
||||
l = samba.Ldb(path)
|
||||
try:
|
||||
l.add({"dn": "foo=dc", "bar": "bla"})
|
||||
self.assertEquals("bla", l.searchone(basedn=ldb.Dn(l, "foo=dc"), attribute="bar"))
|
||||
self.assertEquals("bla",
|
||||
l.searchone(basedn=ldb.Dn(l, "foo=dc"), attribute="bar"))
|
||||
finally:
|
||||
del l
|
||||
os.unlink(path)
|
||||
|
@ -16,5 +16,5 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
|
||||
|
@ -19,31 +19,32 @@
|
||||
#
|
||||
|
||||
from samba.dcerpc import ClientConnection
|
||||
from unittest import TestCase
|
||||
from samba.tests import env_loadparm
|
||||
import samba.tests
|
||||
|
||||
|
||||
class BareTestCase(TestCase):
|
||||
class BareTestCase(samba.tests.TestCase):
|
||||
|
||||
def test_bare(self):
|
||||
# Connect to the echo pipe
|
||||
x = ClientConnection("ncalrpc:localhost[DEFAULT]",
|
||||
("60a15ec5-4de8-11d7-a637-005056a20182", 1), lp_ctx=env_loadparm())
|
||||
("60a15ec5-4de8-11d7-a637-005056a20182", 1),
|
||||
lp_ctx=samba.tests.env_loadparm())
|
||||
self.assertEquals("\x01\x00\x00\x00", x.request(0, chr(0) * 4))
|
||||
|
||||
def test_alter_context(self):
|
||||
x = ClientConnection("ncalrpc:localhost[DEFAULT]",
|
||||
("12345778-1234-abcd-ef00-0123456789ac", 1), lp_ctx=env_loadparm())
|
||||
("12345778-1234-abcd-ef00-0123456789ac", 1),
|
||||
lp_ctx=samba.tests.env_loadparm())
|
||||
y = ClientConnection("ncalrpc:localhost",
|
||||
("60a15ec5-4de8-11d7-a637-005056a20182", 1),
|
||||
basis_connection=x, lp_ctx=env_loadparm())
|
||||
basis_connection=x, lp_ctx=samba.tests.env_loadparm())
|
||||
x.alter_context(("60a15ec5-4de8-11d7-a637-005056a20182", 1))
|
||||
# FIXME: self.assertEquals("\x01\x00\x00\x00", x.request(0, chr(0) * 4))
|
||||
|
||||
def test_two_connections(self):
|
||||
x = ClientConnection("ncalrpc:localhost[DEFAULT]",
|
||||
("60a15ec5-4de8-11d7-a637-005056a20182", 1), lp_ctx=env_loadparm())
|
||||
("60a15ec5-4de8-11d7-a637-005056a20182", 1),
|
||||
lp_ctx=samba.tests.env_loadparm())
|
||||
y = ClientConnection("ncalrpc:localhost",
|
||||
("60a15ec5-4de8-11d7-a637-005056a20182", 1),
|
||||
basis_connection=x, lp_ctx=env_loadparm())
|
||||
basis_connection=x, lp_ctx=samba.tests.env_loadparm())
|
||||
self.assertEquals("\x01\x00\x00\x00", y.request(0, chr(0) * 4))
|
||||
|
@ -17,13 +17,13 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
import unittest
|
||||
from samba.dcerpc import misc
|
||||
import samba.tests
|
||||
|
||||
text1 = "76f53846-a7c2-476a-ae2c-20e2b80d7b34"
|
||||
text2 = "344edffa-330a-4b39-b96e-2c34da52e8b1"
|
||||
|
||||
class GUIDTests(unittest.TestCase):
|
||||
class GUIDTests(samba.tests.TestCase):
|
||||
|
||||
def test_str(self):
|
||||
guid = misc.GUID(text1)
|
||||
@ -45,7 +45,7 @@ class GUIDTests(unittest.TestCase):
|
||||
self.assertEquals(guid1, guid2)
|
||||
|
||||
|
||||
class PolicyHandleTests(unittest.TestCase):
|
||||
class PolicyHandleTests(samba.tests.TestCase):
|
||||
|
||||
def test_init(self):
|
||||
x = misc.policy_handle(text1, 1)
|
||||
|
@ -24,6 +24,7 @@ from samba.tests import RpcInterfaceTestCase
|
||||
class WinregTests(RpcInterfaceTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(WinregTests, self).setUp()
|
||||
self.conn = winreg.winreg("ncalrpc:", self.get_loadparm(),
|
||||
self.get_credentials())
|
||||
|
||||
|
@ -19,13 +19,13 @@
|
||||
|
||||
from samba.dcerpc import echo
|
||||
from samba.ndr import ndr_pack, ndr_unpack
|
||||
import unittest
|
||||
from samba.tests import RpcInterfaceTestCase
|
||||
from samba.tests import RpcInterfaceTestCase, TestCase
|
||||
|
||||
|
||||
class RpcEchoTests(RpcInterfaceTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(RpcEchoTests, self).setUp()
|
||||
self.conn = echo.rpcecho("ncalrpc:", self.get_loadparm())
|
||||
|
||||
def test_two_contexts(self):
|
||||
@ -59,7 +59,7 @@ class RpcEchoTests(RpcInterfaceTestCase):
|
||||
self.assertEquals(None, self.conn.server_name)
|
||||
|
||||
|
||||
class NdrEchoTests(unittest.TestCase):
|
||||
class NdrEchoTests(TestCase):
|
||||
|
||||
def test_info1_push(self):
|
||||
x = echo.info1()
|
||||
|
@ -32,6 +32,7 @@ def toArray((handle, array, num_entries)):
|
||||
class SamrTests(RpcInterfaceTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SamrTests, self).setUp()
|
||||
self.conn = samr.samr("ncalrpc:", self.get_loadparm())
|
||||
|
||||
def test_connect5(self):
|
||||
|
@ -23,6 +23,7 @@ from samba.tests import RpcInterfaceTestCase
|
||||
class UnixinfoTests(RpcInterfaceTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(UnixinfoTests, self).setUp()
|
||||
self.conn = unixinfo.unixinfo("ncalrpc:", self.get_loadparm())
|
||||
|
||||
def test_getpwuid(self):
|
||||
|
@ -17,11 +17,10 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
import unittest
|
||||
|
||||
from samba.netcmd import Command
|
||||
import samba.tests
|
||||
|
||||
class CommandTests(unittest.TestCase):
|
||||
class CommandTests(samba.tests.TestCase):
|
||||
|
||||
def test_name(self):
|
||||
class cmd_foo(Command):
|
||||
|
@ -20,8 +20,7 @@
|
||||
import os
|
||||
from samba.provision import setup_secretsdb, findnss
|
||||
import samba.tests
|
||||
from samba.tests import env_loadparm
|
||||
import unittest
|
||||
from samba.tests import env_loadparm, TestCase
|
||||
|
||||
setup_dir = "setup"
|
||||
def setup_path(file):
|
||||
@ -42,8 +41,9 @@ class ProvisionTestCase(samba.tests.TestCaseInTempDir):
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
class FindNssTests(unittest.TestCase):
|
||||
class FindNssTests(TestCase):
|
||||
"""Test findnss() function."""
|
||||
|
||||
def test_nothing(self):
|
||||
def x(y):
|
||||
raise KeyError
|
||||
|
@ -24,8 +24,8 @@ from samba.samba3 import (WinsDatabase, SmbpasswdFile, ACB_NORMAL,
|
||||
from samba.tests import TestCase
|
||||
import os
|
||||
|
||||
DATADIR=os.path.join(os.path.dirname(__file__), "../../../../../testdata/samba3")
|
||||
print "Samba 3 data dir: %s" % DATADIR
|
||||
DATADIR = os.path.join(os.path.dirname(__file__),
|
||||
"../../../../../testdata/samba3")
|
||||
|
||||
class RegistryTestCase(TestCase):
|
||||
|
||||
@ -35,6 +35,7 @@ class RegistryTestCase(TestCase):
|
||||
|
||||
def tearDown(self):
|
||||
self.registry.close()
|
||||
super(RegistryTestCase, self).tearDown()
|
||||
|
||||
def test_length(self):
|
||||
self.assertEquals(28, len(self.registry))
|
||||
|
@ -17,7 +17,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from samba.shares import SharesContainer
|
||||
from unittest import TestCase
|
||||
from samba.tests import TestCase
|
||||
|
||||
|
||||
class MockService(object):
|
||||
|
@ -21,6 +21,7 @@ from samba.upgrade import import_wins
|
||||
from samba.tests import LdbTestCase
|
||||
|
||||
class WinsUpgradeTests(LdbTestCase):
|
||||
|
||||
def test_upgrade(self):
|
||||
winsdb = {
|
||||
"FOO#20": (200, ["127.0.0.1", "127.0.0.2"], 0x60)
|
||||
|
@ -20,7 +20,7 @@
|
||||
import samba.xattr_native, samba.xattr_tdb
|
||||
from samba.dcerpc import xattr
|
||||
from samba.ndr import ndr_pack
|
||||
from testtools.testcase import TestCase, TestSkipped
|
||||
from samba.tests import TestCase, TestSkipped
|
||||
import random
|
||||
import os
|
||||
|
||||
|
Reference in New Issue
Block a user