summaryrefslogtreecommitdiff
path: root/source4/scripting/swig
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2006-05-02 05:14:00 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:05:31 -0500
commit684aa5adef7c8f61e626983ef2a79156fcb14f3d (patch)
tree9fcae0a4ad95a433f377b8d8ee3564f5a1e16600 /source4/scripting/swig
parent827cdb949ba22e05f88c03028acb747ca437f4e3 (diff)
downloadsamba-684aa5adef7c8f61e626983ef2a79156fcb14f3d.tar.gz
samba-684aa5adef7c8f61e626983ef2a79156fcb14f3d.tar.bz2
samba-684aa5adef7c8f61e626983ef2a79156fcb14f3d.zip
r15389: Add some better torture tests for LdbMessage.
Fix up behaviour of Ldb.__setitem__() function. It should overwrite the element data. Add wrapper for ldb_msg_sanity_check(). (This used to be commit d67e055f86a62d0e61fd20d75b252a6211618f7b)
Diffstat (limited to 'source4/scripting/swig')
-rwxr-xr-xsource4/scripting/swig/torture/torture_ldb.py81
1 files changed, 73 insertions, 8 deletions
diff --git a/source4/scripting/swig/torture/torture_ldb.py b/source4/scripting/swig/torture/torture_ldb.py
index 311a2b1d66..fe79f4f843 100755
--- a/source4/scripting/swig/torture/torture_ldb.py
+++ b/source4/scripting/swig/torture/torture_ldb.py
@@ -1,18 +1,83 @@
#!/usr/bin/python
+#
+# A torture test for the Python Ldb bindings. Also a short guide on
+# how the API works.
+#
-import Ldb, sys
+from Ldb import *
-def test(cond, msg):
+# Helpers
+
+def t(cond, msg):
+ """Test a condition."""
if not cond:
- print 'FAILED:', msg
- sys.exit(1)
+ raise RuntimeError('FAILED: %s' % msg)
+#
# Torture LdbMessage
+#
+
+m = LdbMessage()
+
+# Empty message
+
+t(m.keys() == [], 'empty msg')
+t(m.dn == None, 'empty dn')
+
+t(m.sanity_check() == LDB_ERR_INVALID_DN_SYNTAX, 'sanity check')
+
+# Test invalid dn
+
+try:
+ m.dn = 'invalid dn'
+except LdbError, arg:
+ if arg[0] != LDB_ERR_INVALID_DN_SYNTAX:
+ raise
+else:
+ t(False, 'LdbError not raised')
+
+# Test valid dn
+
+m.dn = 'name=spotty'
+t(m.dn == 'name=spotty', 'specified dn')
+
+t(m.sanity_check() == LDB_SUCCESS, 'sanity check')
+
+# Test some single-valued attributes
-m = Ldb.LdbMessage()
m['animal'] = 'dog'
m['name'] = 'spotty'
-test(m.keys() == ['animal', 'name'], 'keys() test failed')
-test(m.values() == [['dog'], ['spotty']], 'values() test failed')
-test(m.items() == [('animal', ['dog']), ('name', ['spotty'])], 'items() test failed')
+t(m.keys() == ['animal', 'name'], 'keys() test failed')
+t(m.values() == [['dog'], ['spotty']], 'values() test failed')
+t(m.items() == [('animal', ['dog']), ('name', ['spotty'])],
+ 'items() test failed')
+
+t(m.sanity_check() == LDB_SUCCESS, 'sanity check')
+
+m['animal'] = 'canine'
+t(m['animal'] == ['canine'], 'replace value failed')
+
+# Test a multi-valued attribute
+
+names = ['spotty', 'foot']
+m['name'] = names
+
+t(m['name'] == names, 'multi-valued attr failed')
+
+t(m.sanity_check() == LDB_SUCCESS, 'sanity check')
+
+# Test non-string attributes
+
+try:
+ m['foo'] = 42
+except TypeError:
+ pass
+else:
+ t(False, 'TypeError not raised')
+
+#
+# Torture Ldb
+#
+
+l = Ldb('foo.ldb')