]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pyldb: Add tests for ldb.Message containment testing
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Sat, 25 Sep 2021 01:48:57 +0000 (13:48 +1200)
committerStefan Metzmacher <metze@samba.org>
Thu, 28 Oct 2021 08:58:16 +0000 (08:58 +0000)
These tests verify that the 'in' operator on ldb.Message is consistent
with indexing and the get() method. This means that the 'dn' element
should always be present, lookups should be case-insensitive, and use of
an invalid type should result in a TypeError.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14845
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14848

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit 865fe238599a732360b77e06e592cb85d459acf8)

lib/ldb/tests/python/api.py
selftest/knownfail.d/pyldb [new file with mode: 0644]

index bcb01e15f56dafc5c757b6c056fe6aa68f7d24f3..675b5859af8ff64644e8c4a57dc164d63e241951 100755 (executable)
@@ -3177,6 +3177,29 @@ class LdbMsgTests(TestCase):
     def test_get_unknown_text(self):
         self.assertEqual(None, self.msg.text.get("lalalala"))
 
+    def test_contains(self):
+        self.msg['foo'] = ['bar']
+        self.assertIn('foo', self.msg)
+
+        self.msg['Foo'] = ['bar']
+        self.assertIn('Foo', self.msg)
+
+    def test_contains_case(self):
+        self.msg['foo'] = ['bar']
+        self.assertIn('Foo', self.msg)
+
+        self.msg['Foo'] = ['bar']
+        self.assertIn('foo', self.msg)
+
+    def test_contains_dn(self):
+        self.assertIn('dn', self.msg)
+
+    def test_contains_dn_case(self):
+        self.assertIn('DN', self.msg)
+
+    def test_contains_invalid(self):
+        self.assertRaises(TypeError, lambda: None in self.msg)
+
     def test_msg_diff(self):
         l = ldb.Ldb()
         msgs = l.parse_ldif("dn: foo=bar\nfoo: bar\nbaz: do\n\ndn: foo=bar\nfoo: bar\nbaz: dont\n")
diff --git a/selftest/knownfail.d/pyldb b/selftest/knownfail.d/pyldb
new file mode 100644 (file)
index 0000000..34bdac4
--- /dev/null
@@ -0,0 +1,4 @@
+^ldb.python.api.LdbMsgTests.test_contains_case
+^ldb.python.api.LdbMsgTests.test_contains_dn
+^ldb.python.api.LdbMsgTests.test_contains_dn_case
+^ldb.python.api.LdbMsgTests.test_contains_invalid