[test.py] utilisation de contexts pour les écritures de la base ldap
This commit is contained in:
parent
15f92fbf21
commit
0e9404ae93
1 changed files with 21 additions and 20 deletions
17
test.py
17
test.py
|
@ -79,6 +79,7 @@ def keys_of_list_of_dict(l, type=''):
|
||||||
keys = keys.union(item.attrs.keys())
|
keys = keys.union(item.attrs.keys())
|
||||||
try:
|
try:
|
||||||
if item.mode in ['w', 'rw']:
|
if item.mode in ['w', 'rw']:
|
||||||
|
with item:
|
||||||
item.save()
|
item.save()
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
anime.reinit()
|
anime.reinit()
|
||||||
|
@ -124,7 +125,7 @@ def tests_machines(parent_dn, realm_list, ipsec=False):
|
||||||
mldif = borne_ldif
|
mldif = borne_ldif
|
||||||
else:
|
else:
|
||||||
mldif = machine_ldif
|
mldif = machine_ldif
|
||||||
machine = conn.newMachine(parent_dn, realm, mldif)
|
with conn.newMachine(parent_dn, realm, mldif) as machine:
|
||||||
if ipsec: machine['ipsec'] = u'auto'
|
if ipsec: machine['ipsec'] = u'auto'
|
||||||
machine.create()
|
machine.create()
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
@ -135,7 +136,7 @@ def tests_machines(parent_dn, realm_list, ipsec=False):
|
||||||
print OK
|
print OK
|
||||||
anim("Suppression d'une machines %s" % realm)
|
anim("Suppression d'une machines %s" % realm)
|
||||||
try:
|
try:
|
||||||
machine = conn.search(u'mid=%s' % machine['mid'][0], mode='rw')[0]
|
with conn.search(u'mid=%s' % machine['mid'][0], mode='rw')[0] as machine:
|
||||||
machine.delete()
|
machine.delete()
|
||||||
del(machine)
|
del(machine)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
@ -196,7 +197,7 @@ print "Instanciation"
|
||||||
|
|
||||||
anim("Creation d'un adherent")
|
anim("Creation d'un adherent")
|
||||||
try:
|
try:
|
||||||
adherent = conn.newAdherent(adherent_ldif)
|
with conn.newAdherent(adherent_ldif) as adherent:
|
||||||
adherent.create()
|
adherent.create()
|
||||||
except Exception:
|
except Exception:
|
||||||
print ERREUR
|
print ERREUR
|
||||||
|
@ -223,7 +224,7 @@ tests_machines(variables.base_dn, ["bornes"])
|
||||||
|
|
||||||
anim("Creation d'un club")
|
anim("Creation d'un club")
|
||||||
try:
|
try:
|
||||||
club = conn.newClub(club_ldif)
|
with conn.newClub(club_ldif) as club:
|
||||||
club['responsable'] = unicode(adherent['aid'][0])
|
club['responsable'] = unicode(adherent['aid'][0])
|
||||||
club.create()
|
club.create()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -236,7 +237,7 @@ else:
|
||||||
|
|
||||||
anim("Suppression d'un club")
|
anim("Suppression d'un club")
|
||||||
try:
|
try:
|
||||||
club = conn.search(u'cid=%s' % club['cid'][0], mode='rw')[0]
|
with conn.search(u'cid=%s' % club['cid'][0], mode='rw')[0] as club:
|
||||||
club.delete()
|
club.delete()
|
||||||
except Exception:
|
except Exception:
|
||||||
print ERREUR
|
print ERREUR
|
||||||
|
@ -250,7 +251,7 @@ else:
|
||||||
|
|
||||||
anim("Creation d'une facture")
|
anim("Creation d'une facture")
|
||||||
try:
|
try:
|
||||||
facture = conn.newFacture(adherent.dn, facture_ldif)
|
with conn.newFacture(adherent.dn, facture_ldif) as facture:
|
||||||
facture.create()
|
facture.create()
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print ERREUR
|
print ERREUR
|
||||||
|
@ -260,7 +261,7 @@ else:
|
||||||
print OK
|
print OK
|
||||||
anim("Suppression d'une facture")
|
anim("Suppression d'une facture")
|
||||||
try:
|
try:
|
||||||
facture = conn.search(u'fid=%s' % facture['fid'][0], mode='rw')[0]
|
with conn.search(u'fid=%s' % facture['fid'][0], mode='rw')[0] as facture:
|
||||||
facture.delete()
|
facture.delete()
|
||||||
except Exception:
|
except Exception:
|
||||||
print ERREUR
|
print ERREUR
|
||||||
|
@ -275,7 +276,7 @@ else:
|
||||||
if adherent:
|
if adherent:
|
||||||
anim("Suppression d'un adherent")
|
anim("Suppression d'un adherent")
|
||||||
try:
|
try:
|
||||||
adherent = conn.search(u'aid=%s' % adherent['aid'][0], mode='rw')[0]
|
with conn.search(u'aid=%s' % adherent['aid'][0], mode='rw')[0] as adherent:
|
||||||
adherent.delete()
|
adherent.delete()
|
||||||
except Exception:
|
except Exception:
|
||||||
print ERREUR
|
print ERREUR
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue