Fix tests

This commit is contained in:
Ludovic Stephan 2020-08-03 14:54:58 +02:00
parent 7931f50611
commit 8fa07bb845
4 changed files with 17 additions and 10 deletions

View file

@ -135,7 +135,8 @@ Clipper = namedtuple("Clipper", ["clipper", "fullname", "mail"])
class LDAPSearch(SearchUnit):
ldap_server_url = getattr(settings, "LDAP_SERVER_URL", None)
domain_component = "dc=spi,dc=ens,dc=fr"
search_fields = ["cn", "uid", "mail"]
search_fields = ["cn", "uid"]
attr_list = ["cn", "uid", "mail"]
verbose_name = _("Comptes clippers")
@ -172,7 +173,7 @@ class LDAPSearch(SearchUnit):
try:
ldap_obj = ldap.initialize(self.ldap_server_url)
res = ldap_obj.search_s(
self.domain_component, ldap.SCOPE_SUBTREE, query, self.search_fields
self.domain_component, ldap.SCOPE_SUBTREE, query, self.attr_list
)
return [
Clipper(

View file

@ -34,8 +34,15 @@ class MockLDAPMixin:
def mockLDAP(self, results):
entries = [
("whatever", {"cn": [name.encode("utf-8")], "uid": [uid.encode("utf-8")]})
for uid, name in results
(
"whatever",
{
"cn": [name.encode("utf-8")],
"uid": [uid.encode("utf-8")],
"mail": [mail.encode("utf-8")],
},
)
for uid, name, mail in results
]
# Mock ldap object whose `search_s` method always returns the same results.
mock_ldap_obj = mock.Mock()