[Fix] test security use cnx instead of request
authorNoe Gaumont <ngaumont@logilab.fr>
Fri, 12 Apr 2019 09:37:09 +0200
changeset 199 a793b5493eda
parent 198 474c8a28e45b
child 200 5c43ce22f938
[Fix] test security use cnx instead of request
test/unittest_security.py
--- a/test/unittest_security.py	Fri Apr 12 09:22:36 2019 +0200
+++ b/test/unittest_security.py	Fri Apr 12 09:37:09 2019 +0200
@@ -2,16 +2,16 @@
 
 class SecurityTC(CubicWebTC):
     def setup_database(self):
-        req = self.request()
-        cwgroup = self.execute('Any U WHERE U is ET, U name "CWGroup"').get_entity(0,0)
-        self.classif1 = self.request().create_entity('Classification', name=u"classif1", classifies=cwgroup)
-        self.kw1 = req.create_entity('Keyword', name=u'kw1', included_in=self.classif1)
+        with self.admin_access.cnx() as cnx:
+            cwgroup = cnx.execute('Any U WHERE U is ET, U name "CWGroup"').one()
+            self.classif1_eid = cnx.create_entity('Classification', name=u"classif1", classifies=cwgroup).eid
+            self.kw1_eid = cnx.create_entity('Keyword', name=u'kw1', included_in=self.classif1_eid).eid
+            cnx.commit()
 
     def test_nonregr_keyword_selection_as_guest(self):
-        self.login('anon')
-        self.execute('Any X ORDERBY Z WHERE X modification_date Z, K eid %(k)s, K applied_to X', {'k':self.kw1.eid})
+        with self.new_access("anon").cnx() as cnx:
+            cnx.execute('Any X ORDERBY Z WHERE X modification_date Z, K eid %(k)s, K applied_to X', {'k': self.kw1_eid})
 
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main
     unittest_main()
-