diff --git a/attributs_tests.py b/attributs_tests.py index b595d82..44e481b 100755 --- a/attributs_tests.py +++ b/attributs_tests.py @@ -35,57 +35,53 @@ import unittest from lc_ldap_tests import LDAPTest 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): """Tests sur l'attribut nom""" tests = ["acceptNom"] def acceptNom(self): """Accepte les noms de la liste définie""" - attrify_light(u"Dandrimont", "nom") - attrify_light(u"D'Andrimont", "nom") - attrify_light(u"Parret-Fréaud", "nom") - attrify_light(u"Space Man", "nom") - self.assertRaises(Exception, attrify_light, "Stringman", "nom") - self.assertRaises(Exception, attrify_light, u" Spaceman", "nom") - self.assertRaises(Exception, attrify_light, u"Spéciaux!?", "nom") + self.attrify_light(u"Dandrimont", "nom") + self.attrify_light(u"D'Andrimont", "nom") + self.attrify_light(u"Parret-Fréaud", "nom") + self.attrify_light(u"Space Man", "nom") + self.assertRaises(Exception, self.attrify_light, "Stringman", "nom") + self.assertRaises(Exception, self.attrify_light, u" Spaceman", "nom") + self.assertRaises(Exception, self.attrify_light, u"Spéciaux!?", "nom") class prenomTest(LDAPTest): """Tests sur l'attribut prenom""" tests = ["acceptPrenom"] def acceptPrenom(self): """Accepte les prénoms de la liste définie""" - attrify_light(u"Nicolas", "prenom") - attrify_light(u"Gérard", "prenom") - attrify_light(u"John-Éric", "prenom") - attrify_light(u"Charles Jean", "prenom") - self.assertRaises(Exception, attrify_light, "String", "prenom") - self.assertRaises(Exception, attrify_light, u" Space", "prenom") - self.assertRaises(Exception, attrify_light, u"Spéciaux!?", "prenom") + self.attrify_light(u"Nicolas", "prenom") + self.attrify_light(u"Gérard", "prenom") + self.attrify_light(u"John-Éric", "prenom") + self.attrify_light(u"Charles Jean", "prenom") + self.assertRaises(Exception, self.attrify_light, "String", "prenom") + self.assertRaises(Exception, self.attrify_light, u" Space", "prenom") + self.assertRaises(Exception, self.attrify_light, u"Spéciaux!?", "prenom") class telTest(LDAPTest): """Tests sur l'attribut tel""" tests = ["acceptTel", "normalizeTel"] def acceptTel(self): """Accepte les numéros de la liste définie""" - attrify_light(u"01 23 45 67 89", "tel") - attrify_light(u"0000000000", "tel") - attrify_light(u"00 33 1 23 45 67 89", "tel") - attrify_light(u"+42 (0) 1 23456789", "tel") - self.assertRaises(Exception, attrify_light, "", "tel") - self.assertRaises(Exception, attrify_light, u"caracteres?!", "tel") + self.attrify_light(u"01 23 45 67 89", "tel") + self.attrify_light(u"0000000000", "tel") + self.attrify_light(u"00 33 1 23 45 67 89", "tel") + self.attrify_light(u"+42 (0) 1 23456789", "tel") + self.assertRaises(Exception, self.attrify_light, "", "tel") + self.assertRaises(Exception, self.attrify_light, u"caracteres?!", "tel") def normalizeTel(self): """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") - attr = attrify_light(u"0000000000", "tel") + attr = self.attrify_light(u"0000000000", "tel") 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") - attr = attrify_light(u"+42 (0) 1 23456789", "tel") + attr = self.attrify_light(u"+42 (0) 1 23456789", "tel") self.assertEqual(str(attr), "0042123456789") diff --git a/lc_ldap_tests.py b/lc_ldap_tests.py index cc5d9dc..8379e1a 100755 --- a/lc_ldap_tests.py +++ b/lc_ldap_tests.py @@ -32,7 +32,7 @@ import unittest -from lc_ldap import * +from lc_ldap import attrify, lc_ldap_test class LDAPTest(unittest.TestCase): """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""" 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)