[PATCH 3 of 4 saem_ref] [test] Associate user to authority in security test setup

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Apr 12 09:07:45 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1491978956 -7200
#      Wed Apr 12 08:35:56 2017 +0200
# Node ID 640ee7534e097d84f9c30d91d714749ec20d1ee2
# Parent  e945a9931564701d19912a702fed5f9ccfe4a1a9
[test] Associate user to authority in security test setup

diff --git a/test/test_security.py b/test/test_security.py
--- a/test/test_security.py
+++ b/test/test_security.py
@@ -31,13 +31,17 @@ class NonManagerUserTC(CubicWebTC):
     login = u'bob'
 
     def setup_database(self):
         with self.admin_access.cnx() as cnx:
             self.create_user(cnx, self.login, ('users', ))
-            testutils.authority_with_naa(cnx)
+            authority = testutils.authority_with_naa(cnx)
+            cnx.execute('SET U authority O WHERE U login %(login)s, O eid %(o)s',
+                        {'login': self.login, 'o': authority.eid})
             cnx.commit()
 
+        self.authority_eid = authority.eid
+
     def test_create_update_authorityrecord(self):
         with self.new_access(self.login).cnx() as cnx:
             arecord = testutils.authority_record(cnx, name=u'a')
             cnx.commit()
             arecord.cw_set(record_id=u'123')
@@ -77,18 +81,12 @@ class NonManagerUserTC(CubicWebTC):
             cnx.commit()
             admin_scheme.cw_set(code_keyword_type=type_concept)
             cnx.commit()
 
     def test_create_update_agent_in_own_organization(self):
-        with self.admin_access.cnx() as cnx:
-            org = testutils.authority_with_naa(cnx)
-            cnx.execute('SET U authority O WHERE U login %(login)s, O eid %(o)s',
-                        {'login': self.login, 'o': org.eid})
-            cnx.commit()
-            authority_eid = org.eid
         with self.new_access(self.login).cnx() as cnx:
-            agent = testutils.agent(cnx, u'bob', authority=authority_eid)
+            agent = testutils.agent(cnx, u'bob', authority=self.authority_eid)
             cnx.commit()
             agent.cw_set(name=u'bobby')
             cnx.commit()
 
     def test_cannot_create_organizationunit(self):


More information about the saem-devel mailing list