[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
41
test.py
41
test.py
|
@ -79,7 +79,8 @@ 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']:
|
||||||
item.save()
|
with item:
|
||||||
|
item.save()
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
anime.reinit()
|
anime.reinit()
|
||||||
print ERREUR
|
print ERREUR
|
||||||
|
@ -124,9 +125,9 @@ 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:
|
||||||
print ERREUR
|
print ERREUR
|
||||||
if show_traceback: print traceback.format_exc()
|
if show_traceback: print traceback.format_exc()
|
||||||
|
@ -135,9 +136,9 @@ 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:
|
||||||
print ERREUR
|
print ERREUR
|
||||||
if show_traceback: print traceback.format_exc()
|
if show_traceback: print traceback.format_exc()
|
||||||
|
@ -196,8 +197,8 @@ 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
|
||||||
print traceback.format_exc()
|
print traceback.format_exc()
|
||||||
|
@ -223,9 +224,9 @@ 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:
|
||||||
print ERREUR
|
print ERREUR
|
||||||
print traceback.format_exc()
|
print traceback.format_exc()
|
||||||
|
@ -236,8 +237,8 @@ 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
|
||||||
print traceback.format_exc()
|
print traceback.format_exc()
|
||||||
|
@ -250,8 +251,8 @@ 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
|
||||||
if show_traceback: print traceback.format_exc()
|
if show_traceback: print traceback.format_exc()
|
||||||
|
@ -260,8 +261,8 @@ 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
|
||||||
print traceback.format_exc()
|
print traceback.format_exc()
|
||||||
|
@ -275,8 +276,8 @@ 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
|
||||||
print traceback.format_exc()
|
print traceback.format_exc()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue