[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())
|
||||
try:
|
||||
if item.mode in ['w', 'rw']:
|
||||
item.save()
|
||||
with item:
|
||||
item.save()
|
||||
except Exception as error:
|
||||
anime.reinit()
|
||||
print ERREUR
|
||||
|
@ -124,9 +125,9 @@ def tests_machines(parent_dn, realm_list, ipsec=False):
|
|||
mldif = borne_ldif
|
||||
else:
|
||||
mldif = machine_ldif
|
||||
machine = conn.newMachine(parent_dn, realm, mldif)
|
||||
if ipsec: machine['ipsec'] = u'auto'
|
||||
machine.create()
|
||||
with conn.newMachine(parent_dn, realm, mldif) as machine:
|
||||
if ipsec: machine['ipsec'] = u'auto'
|
||||
machine.create()
|
||||
except Exception as error:
|
||||
print ERREUR
|
||||
if show_traceback: print traceback.format_exc()
|
||||
|
@ -135,9 +136,9 @@ def tests_machines(parent_dn, realm_list, ipsec=False):
|
|||
print OK
|
||||
anim("Suppression d'une machines %s" % realm)
|
||||
try:
|
||||
machine = conn.search(u'mid=%s' % machine['mid'][0], mode='rw')[0]
|
||||
machine.delete()
|
||||
del(machine)
|
||||
with conn.search(u'mid=%s' % machine['mid'][0], mode='rw')[0] as machine:
|
||||
machine.delete()
|
||||
del(machine)
|
||||
except Exception as error:
|
||||
print ERREUR
|
||||
if show_traceback: print traceback.format_exc()
|
||||
|
@ -196,8 +197,8 @@ print "Instanciation"
|
|||
|
||||
anim("Creation d'un adherent")
|
||||
try:
|
||||
adherent = conn.newAdherent(adherent_ldif)
|
||||
adherent.create()
|
||||
with conn.newAdherent(adherent_ldif) as adherent:
|
||||
adherent.create()
|
||||
except Exception:
|
||||
print ERREUR
|
||||
print traceback.format_exc()
|
||||
|
@ -223,9 +224,9 @@ tests_machines(variables.base_dn, ["bornes"])
|
|||
|
||||
anim("Creation d'un club")
|
||||
try:
|
||||
club = conn.newClub(club_ldif)
|
||||
club['responsable'] = unicode(adherent['aid'][0])
|
||||
club.create()
|
||||
with conn.newClub(club_ldif) as club:
|
||||
club['responsable'] = unicode(adherent['aid'][0])
|
||||
club.create()
|
||||
except Exception:
|
||||
print ERREUR
|
||||
print traceback.format_exc()
|
||||
|
@ -236,8 +237,8 @@ else:
|
|||
|
||||
anim("Suppression d'un club")
|
||||
try:
|
||||
club = conn.search(u'cid=%s' % club['cid'][0], mode='rw')[0]
|
||||
club.delete()
|
||||
with conn.search(u'cid=%s' % club['cid'][0], mode='rw')[0] as club:
|
||||
club.delete()
|
||||
except Exception:
|
||||
print ERREUR
|
||||
print traceback.format_exc()
|
||||
|
@ -250,8 +251,8 @@ else:
|
|||
|
||||
anim("Creation d'une facture")
|
||||
try:
|
||||
facture = conn.newFacture(adherent.dn, facture_ldif)
|
||||
facture.create()
|
||||
with conn.newFacture(adherent.dn, facture_ldif) as facture:
|
||||
facture.create()
|
||||
except Exception as error:
|
||||
print ERREUR
|
||||
if show_traceback: print traceback.format_exc()
|
||||
|
@ -260,8 +261,8 @@ else:
|
|||
print OK
|
||||
anim("Suppression d'une facture")
|
||||
try:
|
||||
facture = conn.search(u'fid=%s' % facture['fid'][0], mode='rw')[0]
|
||||
facture.delete()
|
||||
with conn.search(u'fid=%s' % facture['fid'][0], mode='rw')[0] as facture:
|
||||
facture.delete()
|
||||
except Exception:
|
||||
print ERREUR
|
||||
print traceback.format_exc()
|
||||
|
@ -275,8 +276,8 @@ else:
|
|||
if adherent:
|
||||
anim("Suppression d'un adherent")
|
||||
try:
|
||||
adherent = conn.search(u'aid=%s' % adherent['aid'][0], mode='rw')[0]
|
||||
adherent.delete()
|
||||
with conn.search(u'aid=%s' % adherent['aid'][0], mode='rw')[0] as adherent:
|
||||
adherent.delete()
|
||||
except Exception:
|
||||
print ERREUR
|
||||
print traceback.format_exc()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue