tests: adds tests for ldap dao
This commit is contained in:
parent
736a441186
commit
c4e8a9c7cc
3 changed files with 41 additions and 1 deletions
|
|
@ -116,7 +116,6 @@ class LdapDao(AuthLdapBase):
|
|||
return ldap_conn
|
||||
|
||||
def fetch_all(self, ldap_filter: str = "(objectClass=*)", attributes: List[str] = None) -> Optional[List[dict]]:
|
||||
# TODO: add pagination
|
||||
ldap_conn = None
|
||||
try:
|
||||
if attributes is None:
|
||||
|
|
|
|||
0
rhodecode/authentication/tests/services/__init__.py
Normal file
0
rhodecode/authentication/tests/services/__init__.py
Normal file
41
rhodecode/authentication/tests/services/test_ldap_dao.py
Normal file
41
rhodecode/authentication/tests/services/test_ldap_dao.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import unittest
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
import ldap
|
||||
|
||||
from rhodecode.authentication.plugins.services.ldap_dao import LdapDao
|
||||
from rhodecode.lib.diff_match_patch import patch_obj
|
||||
|
||||
|
||||
@patch("rhodecode.authentication.plugins.services.ldap_dao.ldap")
|
||||
class TestLdapDao(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self._server_list = "test_srv1,test_srv2,test_srv3"
|
||||
self._base_dn = "test_dn"
|
||||
self.ldap_dao = LdapDao(
|
||||
server=self._server_list,
|
||||
base_dn=self._base_dn,
|
||||
)
|
||||
|
||||
@patch.object(LdapDao, "_get_ldap_conn")
|
||||
def test_fetch_all_from_ldap_server(self, _get_ldap_conn_mock, ldap_mock):
|
||||
conn = MagicMock()
|
||||
no_objects_in_ldap_server = []
|
||||
conn.search_ext_s.return_value = no_objects_in_ldap_server
|
||||
|
||||
_get_ldap_conn_mock.return_value = conn
|
||||
|
||||
returned_value = self.ldap_dao.fetch_all()
|
||||
|
||||
conn.search_ext_s.assert_called_once_with(self._base_dn, 2, "(objectClass=*)", attrlist=["*", "+"])
|
||||
|
||||
assert returned_value == no_objects_in_ldap_server
|
||||
|
||||
@patch.object(LdapDao, "_get_ldap_conn")
|
||||
def test_fetch_all_release_connection(self, _get_ldap_conn_mock, ldap_mock):
|
||||
conn = MagicMock()
|
||||
_get_ldap_conn_mock.return_value = conn
|
||||
|
||||
self.ldap_dao.fetch_all()
|
||||
|
||||
conn.unbind_s.assert_called_once()
|
||||
Loading…
Add table
Add a link
Reference in a new issue