Created
March 21, 2011 22:05
-
-
Save felipe-prenholato/880318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from ldapdb.models.fields import CharField, ImageField, IntegerField, ListField | |
import ldapdb.models | |
class LdapUser(ldapdb.models.Model): | |
""" | |
Class for representing an LDAP user entry. | |
""" | |
# LDAP meta-data | |
base_dn = "dc=goldfarb,dc=corp" | |
object_classes = ['user'] | |
username = CharField(db_column='sAMAccountName',unique=True) | |
first_name = CharField(db_column='givenName') | |
last_name = CharField(db_column='sn') | |
full_name = CharField(db_column='cn') | |
email = CharField(db_column='mail',unique=True,primary_key=True) | |
def __unicode__(self): | |
return u"%s (%s)" % (self.full_name,self.username) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./manage.py test ldap_connector | |
No fixtures found. | |
search_s filter and attributes: (&(objectClass=user)(sAMAccountName=*teste.ad*)) ['sAMAccountName', 'givenName', 'sn', 'cn', 'mail'] | |
. | |
search_s filter and attributes: (&(objectClass=user)(sAMAccountName=teste.ad01)) ['sAMAccountName', 'givenName', 'sn', 'cn', 'mail'] | |
. | |
search_s filter and attributes: (&(objectClass=user)(sAMAccountName=*teste.ad*)) ['sAMAccountName', 'givenName', 'sn', 'cn', 'mail'] | |
search_s filter and attributes: (&(objectClass=user)([email protected])) ['sAMAccountName', 'givenName', 'sn', 'cn', 'mail'] | |
modifications list for teste.ad01 (teste.ad01) [(2, 'givenName', ['Teste 01']), (2, 'sn', ['Ad 01'])] | |
E | |
====================================================================== | |
ERROR: Test update in users from 01 to 05 | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "/home/felipe/projects/portal/portal/ldap_connector/tests.py", line 36, in test_update | |
user.save() | |
File "/home/felipe/projects/portal/lib/python2.6/site-packages/ldapdb/models/base.py", line 153, in save | |
ldapdb.connection.rename_s(self.dn, self.build_rdn()) | |
File "/home/felipe/projects/portal/lib/python2.6/site-packages/ldapdb/__init__.py", line 89, in rename_s | |
return cursor.connection.rename_s(dn.encode(self.charset), newrdn.encode(self.charset)) | |
File "/home/felipe/projects/portal/lib/python2.6/site-packages/ldap/ldapobject.py", line 369, in rename_s | |
return self.result(msgid,all=1,timeout=self.timeout) | |
File "/home/felipe/projects/portal/lib/python2.6/site-packages/ldap/ldapobject.py", line 422, in result | |
res_type,res_data,res_msgid = self.result2(msgid,all,timeout) | |
File "/home/felipe/projects/portal/lib/python2.6/site-packages/ldap/ldapobject.py", line 426, in result2 | |
res_type, res_data, res_msgid, srv_ctrls = self.result3(msgid,all,timeout) | |
File "/home/felipe/projects/portal/lib/python2.6/site-packages/ldap/ldapobject.py", line 432, in result3 | |
ldap_result = self._ldap_call(self._l.result3,msgid,all,timeout) | |
File "/home/felipe/projects/portal/lib/python2.6/site-packages/ldap/ldapobject.py", line 96, in _ldap_call | |
result = func(*args,**kwargs) | |
UNWILLING_TO_PERFORM: {'info': '00002077: SvcErr: DSID-031B0D85, problem 5003 (WILL_NOT_PERFORM), data 0\n', 'desc': 'Server is unwilling to perform'} | |
---------------------------------------------------------------------- | |
Ran 3 tests in 2.054s | |
FAILED (errors=1) | |
Destroying test database 'default'... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from models import LdapUser | |
from django.test import TestCase | |
class UserTestCase(TestCase): | |
def test_get(self): | |
""" Test to get users teste.ad01 """ | |
user = LdapUser.objects.get(username='teste.ad01') | |
self.assertEquals(user.first_name,'teste.ad01') | |
self.assertEquals(user.last_name,'') | |
self.assertEquals(user.email,'[email protected]') | |
def test_filter(self): | |
""" Test filter in users from 01 to 05 """ | |
users = LdapUser.objects.filter(username__icontains='teste.ad').order_by('username') | |
for i,user in enumerate(users,1): | |
self.assertEquals(user.first_name,'teste.ad0%s' % i) | |
self.assertEquals(user.last_name,'') | |
self.assertEquals(user.email,'teste.ad0%[email protected]' % i) | |
def test_update(self): | |
""" Test update in users from 01 to 05 """ | |
users = LdapUser.objects.filter(username__icontains='teste.ad').order_by('username') | |
for i,user in enumerate(users,1): | |
self.assertEquals(user.first_name,'teste.ad0%s' % i) | |
self.assertEquals(user.last_name,'') | |
self.assertEquals(user.email,'teste.ad0%[email protected]' % i) | |
user.first_name = "Teste 0%s" % i | |
user.last_name = "Ad 0%s" % i | |
user.save() | |
user = LdapUser.objects.get(username=user.username) | |
self.assertEquals(user.first_name,"Teste 0%s" % i) | |
self.assertEquals(user.last_name,"Ad 0%s" % i) | |
self.assertEquals(user.email,'teste.ad0%[email protected]' % i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment