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