Fix tests
This commit is contained in:
parent
7931f50611
commit
8fa07bb845
4 changed files with 17 additions and 10 deletions
|
@ -47,7 +47,6 @@ class TestRegistrationView(TestCase):
|
||||||
def test_get(self, mock_messages):
|
def test_get(self, mock_messages):
|
||||||
user = User.objects.create_user(username="toto")
|
user = User.objects.create_user(username="toto")
|
||||||
url = reverse("bds:user.update", args=(user.id,))
|
url = reverse("bds:user.update", args=(user.id,))
|
||||||
print(url)
|
|
||||||
client = Client()
|
client = Client()
|
||||||
|
|
||||||
# Anonymous GET
|
# Anonymous GET
|
||||||
|
|
|
@ -329,15 +329,15 @@ class RegistrationAutocompleteViewTests(MockLDAPMixin, ViewTestCaseMixin, TestCa
|
||||||
self._test("wy bd", [self.u2], [self.m1], [])
|
self._test("wy bd", [self.u2], [self.m1], [])
|
||||||
|
|
||||||
def test_clipper(self):
|
def test_clipper(self):
|
||||||
mock_ldap = self.mockLDAP([("uid", "first last")])
|
mock_ldap = self.mockLDAP([("uid", "first last", "mail")])
|
||||||
|
|
||||||
self._test("aa bb", [], [], [Clipper("uid", "first last")])
|
self._test("aa bb", [], [], [Clipper("uid", "first last", "mail")])
|
||||||
|
|
||||||
mock_ldap.ldap_obj.search_s.assert_called_once_with(
|
mock_ldap.ldap_obj.search_s.assert_called_once_with(
|
||||||
"dc=spi,dc=ens,dc=fr",
|
"dc=spi,dc=ens,dc=fr",
|
||||||
mock_ldap.SCOPE_SUBTREE,
|
mock_ldap.SCOPE_SUBTREE,
|
||||||
"(&(|(cn=*aa*)(uid=*aa*))(|(cn=*bb*)(uid=*bb*)))",
|
"(&(|(cn=*aa*)(uid=*aa*))(|(cn=*bb*)(uid=*bb*)))",
|
||||||
["cn", "uid"],
|
["cn", "uid", "mail"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_clipper_escaped(self):
|
def test_clipper_escaped(self):
|
||||||
|
@ -348,9 +348,9 @@ class RegistrationAutocompleteViewTests(MockLDAPMixin, ViewTestCaseMixin, TestCa
|
||||||
mock_ldap.ldap_obj.search_s.assert_not_called()
|
mock_ldap.ldap_obj.search_s.assert_not_called()
|
||||||
|
|
||||||
def test_clipper_no_duplicate(self):
|
def test_clipper_no_duplicate(self):
|
||||||
self.mockLDAP([("uid", "abc")])
|
self.mockLDAP([("uid", "abc", "mail")])
|
||||||
|
|
||||||
self._test("abc", [self.u1], [], [Clipper("uid", "abc")])
|
self._test("abc", [self.u1], [], [Clipper("uid", "abc", "mail")])
|
||||||
|
|
||||||
self.u1.username = "uid"
|
self.u1.username = "uid"
|
||||||
self.u1.save()
|
self.u1.save()
|
||||||
|
|
|
@ -135,7 +135,8 @@ Clipper = namedtuple("Clipper", ["clipper", "fullname", "mail"])
|
||||||
class LDAPSearch(SearchUnit):
|
class LDAPSearch(SearchUnit):
|
||||||
ldap_server_url = getattr(settings, "LDAP_SERVER_URL", None)
|
ldap_server_url = getattr(settings, "LDAP_SERVER_URL", None)
|
||||||
domain_component = "dc=spi,dc=ens,dc=fr"
|
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")
|
verbose_name = _("Comptes clippers")
|
||||||
|
|
||||||
|
@ -172,7 +173,7 @@ class LDAPSearch(SearchUnit):
|
||||||
try:
|
try:
|
||||||
ldap_obj = ldap.initialize(self.ldap_server_url)
|
ldap_obj = ldap.initialize(self.ldap_server_url)
|
||||||
res = ldap_obj.search_s(
|
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 [
|
return [
|
||||||
Clipper(
|
Clipper(
|
||||||
|
|
|
@ -34,8 +34,15 @@ class MockLDAPMixin:
|
||||||
|
|
||||||
def mockLDAP(self, results):
|
def mockLDAP(self, results):
|
||||||
entries = [
|
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 object whose `search_s` method always returns the same results.
|
||||||
mock_ldap_obj = mock.Mock()
|
mock_ldap_obj = mock.Mock()
|
||||||
|
|
Loading…
Reference in a new issue