tests.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:django-pucas 作者: Princeton-CDH 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号