def test_init(self, mockldap3):
# initialize and then check expected behavior against
# mock ldap3
LDAPSearch()
test_servers = []
for test_server in self.ldap_servers:
mockldap3.Server.assert_any_call(test_server,
get_info=mockldap3.ALL, use_ssl=True)
# initialized servers are collected into server pool
servers = [mockldap3.Server.return_value
for test_server in self.ldap_servers]
mockldap3.ServerPool.assert_called_with(servers,
mockldap3.ROUND_ROBIN, active=True, exhaust=5)
# server pool is used for connection
mockldap3.Connection.assert_called_with(mockldap3.ServerPool.return_value,
auto_bind=True)
with override_settings(PUCAS_LDAP={
'SERVERS': self.ldap_servers,
'BIND_DN': self.dn,
'BIND_PASSWORD': self.password,
}):
LDAPSearch()
# server pool is used for connection, now with password
mockldap3.Connection.assert_called_with(mockldap3.ServerPool.return_value,
auto_bind=True, user=self.dn, password=self.password)
with pytest.raises(LDAPException):
mockldap3.Connection.side_effect = LDAPException
LDAPSearch()
评论列表
文章目录