[tests] modification du prototype de attrify

This commit is contained in:
Nicolas Dandrimont 2010-10-16 18:32:14 +02:00
parent 9adc0b7732
commit b9f9096077
2 changed files with 28 additions and 30 deletions

View file

@ -35,57 +35,53 @@ import unittest
from lc_ldap_tests import LDAPTest from lc_ldap_tests import LDAPTest
from attributs import * from attributs import *
def attrify_light(val, champ):
"""Transforme une valeur en objet Attr avec un LDIF minimaliste"""
return attrify(val, champ, {champ: [val]})
class nomTest(LDAPTest): class nomTest(LDAPTest):
"""Tests sur l'attribut nom""" """Tests sur l'attribut nom"""
tests = ["acceptNom"] tests = ["acceptNom"]
def acceptNom(self): def acceptNom(self):
"""Accepte les noms de la liste définie""" """Accepte les noms de la liste définie"""
attrify_light(u"Dandrimont", "nom") self.attrify_light(u"Dandrimont", "nom")
attrify_light(u"D'Andrimont", "nom") self.attrify_light(u"D'Andrimont", "nom")
attrify_light(u"Parret-Fréaud", "nom") self.attrify_light(u"Parret-Fréaud", "nom")
attrify_light(u"Space Man", "nom") self.attrify_light(u"Space Man", "nom")
self.assertRaises(Exception, attrify_light, "Stringman", "nom") self.assertRaises(Exception, self.attrify_light, "Stringman", "nom")
self.assertRaises(Exception, attrify_light, u" Spaceman", "nom") self.assertRaises(Exception, self.attrify_light, u" Spaceman", "nom")
self.assertRaises(Exception, attrify_light, u"Spéciaux!?", "nom") self.assertRaises(Exception, self.attrify_light, u"Spéciaux!?", "nom")
class prenomTest(LDAPTest): class prenomTest(LDAPTest):
"""Tests sur l'attribut prenom""" """Tests sur l'attribut prenom"""
tests = ["acceptPrenom"] tests = ["acceptPrenom"]
def acceptPrenom(self): def acceptPrenom(self):
"""Accepte les prénoms de la liste définie""" """Accepte les prénoms de la liste définie"""
attrify_light(u"Nicolas", "prenom") self.attrify_light(u"Nicolas", "prenom")
attrify_light(u"Gérard", "prenom") self.attrify_light(u"Gérard", "prenom")
attrify_light(u"John-Éric", "prenom") self.attrify_light(u"John-Éric", "prenom")
attrify_light(u"Charles Jean", "prenom") self.attrify_light(u"Charles Jean", "prenom")
self.assertRaises(Exception, attrify_light, "String", "prenom") self.assertRaises(Exception, self.attrify_light, "String", "prenom")
self.assertRaises(Exception, attrify_light, u" Space", "prenom") self.assertRaises(Exception, self.attrify_light, u" Space", "prenom")
self.assertRaises(Exception, attrify_light, u"Spéciaux!?", "prenom") self.assertRaises(Exception, self.attrify_light, u"Spéciaux!?", "prenom")
class telTest(LDAPTest): class telTest(LDAPTest):
"""Tests sur l'attribut tel""" """Tests sur l'attribut tel"""
tests = ["acceptTel", "normalizeTel"] tests = ["acceptTel", "normalizeTel"]
def acceptTel(self): def acceptTel(self):
"""Accepte les numéros de la liste définie""" """Accepte les numéros de la liste définie"""
attrify_light(u"01 23 45 67 89", "tel") self.attrify_light(u"01 23 45 67 89", "tel")
attrify_light(u"0000000000", "tel") self.attrify_light(u"0000000000", "tel")
attrify_light(u"00 33 1 23 45 67 89", "tel") self.attrify_light(u"00 33 1 23 45 67 89", "tel")
attrify_light(u"+42 (0) 1 23456789", "tel") self.attrify_light(u"+42 (0) 1 23456789", "tel")
self.assertRaises(Exception, attrify_light, "", "tel") self.assertRaises(Exception, self.attrify_light, "", "tel")
self.assertRaises(Exception, attrify_light, u"caracteres?!", "tel") self.assertRaises(Exception, self.attrify_light, u"caracteres?!", "tel")
def normalizeTel(self): def normalizeTel(self):
"""Normalise correctement les numéros de téléphone""" """Normalise correctement les numéros de téléphone"""
attr = attrify_light(u"01 23 45 67 89", "tel") attr = self.attrify_light(u"01 23 45 67 89", "tel")
self.assertEqual(str(attr), "0123456789") self.assertEqual(str(attr), "0123456789")
attr = attrify_light(u"0000000000", "tel") attr = self.attrify_light(u"0000000000", "tel")
self.assertEqual(str(attr), "0000000000") self.assertEqual(str(attr), "0000000000")
attr = attrify_light(u"00 33 1 23 45 67 89", "tel") attr = self.attrify_light(u"00 33 1 23 45 67 89", "tel")
self.assertEqual(str(attr), "0033123456789") self.assertEqual(str(attr), "0033123456789")
attr = attrify_light(u"+42 (0) 1 23456789", "tel") attr = self.attrify_light(u"+42 (0) 1 23456789", "tel")
self.assertEqual(str(attr), "0042123456789") self.assertEqual(str(attr), "0042123456789")

View file

@ -32,7 +32,7 @@
import unittest import unittest
from lc_ldap import * from lc_ldap import attrify, lc_ldap_test
class LDAPTest(unittest.TestCase): class LDAPTest(unittest.TestCase):
"""Classe de base pour les tests nécessitant la base LDAP""" """Classe de base pour les tests nécessitant la base LDAP"""
@ -40,4 +40,6 @@ class LDAPTest(unittest.TestCase):
"""Déclare une connexion à la base LDAP de tests""" """Déclare une connexion à la base LDAP de tests"""
self.ldap = lc_ldap_test() self.ldap = lc_ldap_test()
def attrify_light(self, val, champ):
"""Transforme une valeur en objet Attr avec un LDIF minimaliste"""
return attrify(val, champ, {champ: [val]}, self.ldap)