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)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 28 Sep 2021 09:44:35 +0000 (09:44 +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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/tests/python/api.py
selftest/knownfail.d/pyldb [new file with mode: 0644]

index d8a7bd542692532cfe7f51678ba759292857db18..bf6f7ef993da51b69fb2f079fa423eed37e8881d 100755 (executable)
@@ -3203,6 +3203,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