Skip to content

Commit a1bdf47

Browse files
committed
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 ac5d051 commit a1bdf47

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
@@ -474,6 +474,7 @@ def test_dse(self):
474474
[self.server.suffix.encode('utf-8')]
475475
)
476476

477+
477478
def test_compare_s_true(self):
478479
base = self.server.suffix
479480
l = self._ldap_conn
@@ -565,6 +566,38 @@ def test_slapadd(self):
565566
("myAttribute", b'foobar'),
566567
])
567568

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

569602
class Test01_ReconnectLDAPObject(Test00_SimpleLDAPObject):
570603
"""

0 commit comments

Comments
 (0)