Skip to content

Commit 4e90e3b

Browse files
jkoenigerJohannes Königer
authored andcommitted
test: Test valid and invalid attrlist parameters
Add tests test_valid_attrlist_parameter_types and test_invalid_attrlist_parameter_types which test the behaviour when passing different Python types. All iterables which return only strings should pass, everything else should raise a TypeError.
1 parent 2f0135c commit 4e90e3b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Tests/t_ldapobject.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ def test_dse(self):
478478
[self.server.suffix.encode('utf-8')]
479479
)
480480

481+
481482
def test_compare_s_true(self):
482483
base = self.server.suffix
483484
l = self._ldap_conn
@@ -569,6 +570,38 @@ def test_slapadd(self):
569570
("myAttribute", b'foobar'),
570571
])
571572

573+
def test_valid_attrlist_parameter_types(self):
574+
"""Tests the case when a valid parameter type is passed to search_ext
575+
576+
Any iterable which only contains strings should not raise any errors.
577+
"""
578+
579+
l = self._ldap_conn
580+
581+
valid_attrlist_parameters = [{"a": "2"}, ["a", "b"], {}, set(), set(["a", "b"])]
582+
583+
for attrlist in valid_attrlist_parameters:
584+
out = l.search_ext(
585+
"%s" % self.server.suffix, ldap.SCOPE_SUBTREE, attrlist=attrlist
586+
)
587+
588+
def test_invalid_attrlist_parameter_types(self):
589+
"""Tests the case when an invalid parameter type is passed to search_ext
590+
591+
Any object type that is either not a interable or does contain something
592+
that isn't a string should raise a TypeError. The exception is the string type itself.
593+
"""
594+
595+
invalid_attrlist_parameters = [{1: 2}, 0, object(), "string"]
596+
597+
l = self._ldap_conn
598+
599+
for attrlist in invalid_attrlist_parameters:
600+
with self.assertRaises(TypeError):
601+
l.search_ext(
602+
"%s" % self.server.suffix, ldap.SCOPE_SUBTREE, attrlist=attrlist
603+
)
604+
572605

573606
class Test01_ReconnectLDAPObject(Test00_SimpleLDAPObject):
574607
"""

0 commit comments

Comments
 (0)