summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tests/python/api.py
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-08-26 15:01:12 +1000
committerAndrew Bartlett <abartlet@samba.org>2009-08-26 15:07:50 +1000
commit3ed33813bb6aa1ca932372c2a2ce36152b6af50b (patch)
tree80b8c725fa331fcb9603bebe99fb45c9c732704e /source4/lib/ldb/tests/python/api.py
parent74218726e89c297eb957b9df989dd42fd1601742 (diff)
downloadsamba-3ed33813bb6aa1ca932372c2a2ce36152b6af50b.tar.gz
samba-3ed33813bb6aa1ca932372c2a2ce36152b6af50b.tar.bz2
samba-3ed33813bb6aa1ca932372c2a2ce36152b6af50b.zip
s4:ldb Add hooks to get/set the flags on a ldb_message_element
Also add tests to prove that we got this correct, and correct the existing tests which used the wrong constants. Andrew Bartlett
Diffstat (limited to 'source4/lib/ldb/tests/python/api.py')
-rwxr-xr-xsource4/lib/ldb/tests/python/api.py44
1 files changed, 39 insertions, 5 deletions
diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py
index d946bf06a5..9bcb225190 100755
--- a/source4/lib/ldb/tests/python/api.py
+++ b/source4/lib/ldb/tests/python/api.py
@@ -195,10 +195,13 @@ class SimpleLdb(unittest.TestCase):
try:
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=modifydelete")
- m["bla"] = ldb.MessageElement([], ldb.CHANGETYPE_DELETE, "bla")
+ m["bla"] = ldb.MessageElement([], ldb.FLAG_MOD_DELETE, "bla")
+ self.assertEquals(ldb.FLAG_MOD_DELETE, m["bla"].flags())
l.modify(m)
rm = l.search(m.dn)[0]
self.assertEquals(1, len(rm))
+ rm = l.search(m.dn, attrs=["bla"])[0]
+ self.assertEquals(0, len(rm))
finally:
l.delete(ldb.Dn(l, "dc=modifydelete"))
@@ -211,7 +214,8 @@ class SimpleLdb(unittest.TestCase):
try:
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=add")
- m["bla"] = ldb.MessageElement(["456"], ldb.CHANGETYPE_ADD, "bla")
+ m["bla"] = ldb.MessageElement(["456"], ldb.FLAG_MOD_ADD, "bla")
+ self.assertEquals(ldb.FLAG_MOD_ADD, m["bla"].flags())
l.modify(m)
rm = l.search(m.dn)[0]
self.assertEquals(2, len(rm))
@@ -219,7 +223,7 @@ class SimpleLdb(unittest.TestCase):
finally:
l.delete(ldb.Dn(l, "dc=add"))
- def test_modify_modify(self):
+ def test_modify_replace(self):
l = ldb.Ldb(filename())
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=modify2")
@@ -228,14 +232,44 @@ class SimpleLdb(unittest.TestCase):
try:
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=modify2")
- m["bla"] = ldb.MessageElement(["456"], ldb.CHANGETYPE_MODIFY, "bla")
+ m["bla"] = ldb.MessageElement(["789"], ldb.FLAG_MOD_REPLACE, "bla")
+ self.assertEquals(ldb.FLAG_MOD_REPLACE, m["bla"].flags())
l.modify(m)
rm = l.search(m.dn)[0]
self.assertEquals(2, len(rm))
- self.assertEquals(["1234"], list(rm["bla"]))
+ self.assertEquals(["789"], list(rm["bla"]))
+ rm = l.search(m.dn, attrs=["bla"])[0]
+ self.assertEquals(1, len(rm))
finally:
l.delete(ldb.Dn(l, "dc=modify2"))
+ def test_modify_flags_change(self):
+ l = ldb.Ldb(filename())
+ m = ldb.Message()
+ m.dn = ldb.Dn(l, "dc=add")
+ m["bla"] = ["1234"]
+ l.add(m)
+ try:
+ m = ldb.Message()
+ m.dn = ldb.Dn(l, "dc=add")
+ m["bla"] = ldb.MessageElement(["456"], ldb.FLAG_MOD_ADD, "bla")
+ self.assertEquals(ldb.FLAG_MOD_ADD, m["bla"].flags())
+ l.modify(m)
+ rm = l.search(m.dn)[0]
+ self.assertEquals(2, len(rm))
+ self.assertEquals(["1234", "456"], list(rm["bla"]))
+
+ #Now create another modify, but switch the flags before we do it
+ m["bla"] = ldb.MessageElement(["456"], ldb.FLAG_MOD_ADD, "bla")
+ m["bla"].set_flags(ldb.FLAG_MOD_DELETE)
+ l.modify(m)
+ rm = l.search(m.dn, attrs=["bla"])[0]
+ self.assertEquals(1, len(rm))
+ self.assertEquals(["1234"], list(rm["bla"]))
+
+ finally:
+ l.delete(ldb.Dn(l, "dc=add"))
+
def test_transaction_commit(self):
l = ldb.Ldb(filename())
l.transaction_start()