By Ingeniweb. A Django site.
Juin 13, 2008
» Mock For ldap


Hi !

I work at the present time to an project with a lot data provided by an ldap server. The schema of this ldap is really elaborate . To reproduce it in a real ldap server is very difficult. How can I test my terrific code witch consist on an specific vocabularies and a set of PAS plugins ?

The response : a mock ldap object that give to my eggs a real API for ldap.

You can found it here : http://products.ingeniweb.com/catalog/iw.mock.ldap

The goal of this egg : testing component witch use ldap server without ldap. But also provide some good data in order to have some good test. So iw.mock.ldap read an real ldif file and you can search via ldap api (search_s).

It’s not perfect but for me I found very easy to test ldap component.

So how use it ?

In your buildout

[buildout]
eggs =

iw.mock.ldap

[zinstance]

eggs =

iw.mock.ldap

zcml =

iw.mock.ldap

After in you’re project where you want have some test you create a structure like that::

path-to-your-egg/mock
path-to-your-egg/mock/__init__.py
path-to-your-egg/mock/data.ldif

In __init__.py you put this boiler code::

import sys

from zope.interface import implements
from zope.component import adapts
from zope.component import provideAdapter

from iw.mock.ldap.interfaces import ILdifFile
from iw.mock.ldap.interfaces import ILdifReader
import iw.mock

class LdifFile(object):

implements(ILdifFile)
adapts(ILdifReader)

def __init__(self, context):
self.context = context

def open(self):
return file(os.path.join(os.path.dirname(__file__),’data.ldif’))

provideAdapter(LdifFile)

sys.path.insert(0, os.path.dirname(iw.mock.__file__))
from iw.mock import ldap
reload(ldap)


You can also register your adapter in an zcml (example test.zcml)

<configure xmlns=”http://namespaces.zope.org/zope”>
<adapter factory=”.mock.LdifFile”/>
</configure>

And now in you’re test you import path-to-your-egg/mock and all connections and request ldap pass
by iw.mock.ldap and use your data in data.ldif

Juin 9, 2008
Bertrand Mathieu
bertrand
Paste here is about »
» Buildout, ploneldap and ldap products (2)

In my previous post I described how to get a buildout part to get PloneLDAP with an up-to-date LDAPUserFolder. Things are even simpler now since all involved products have been released as eggs. So just list theses in your buildout along with other eggs:

eggs =
...
Products.LDAPUserFolder
Products.LDAPMultiPlugins
Products.PloneLDAP

Second important thing: LDAPUserFolder 2.9 has been released. If you used 2.9-beta you must upgrade, since an important bug related to the negative cache has been fixed. PloneLDAP documents usage with LDAPUserFolder 2.8, but 2.9 is definitely worth it: The negative cache feature avoids doing too many ldap request, especially useless/unsuccessful ones! Many thanks to Jens Vagelpohl (http://www.dataflake.org/software/ldapuserfolder).

Avril 22, 2008
Bertrand Mathieu
bertrand
Paste here is about »
» Buildout, ploneldap and ldap products

UPDATE: all products are available as eggs. See this post.

PloneLDAP is a great product, but its bundle ships a not so recent version of LDAPUserFolder. LDAPUserFolder and LDAPMultiPlugins download urls are both ending with "/download". That seems to confuse plone.recipe.distros, because it installs just one of them. Furthermore, at plone.org PloneLDAP single product (as opposed to PloneLDAP bundle) download url ends with... a space! (%20).
So we have uploaded theses tarballs on release.ingeniweb.com. Here is a working part for buildout:


[ldap_products]
recipe = plone.recipe.distros
urls =
http://release.ingeniweb.com/third-party-dist/LDAPUserFolder-2.9-beta.tgz
http://release.ingeniweb.com/third-party-dist/LDAPMultiPlugins-1.5.tgz
http://release.ingeniweb.com/third-party-dist/PloneLDAP-1.0.tar.gz