[test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 24 Feb 2010 10:30:31 +0100
branchstable
changeset 4674 3d509dbb473a
parent 4673 6f8b925a29f4
child 4675 9233a8350420
[test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
devtools/repotest.py
server/test/unittest_msplanner.py
server/test/unittest_querier.py
--- a/devtools/repotest.py	Tue Feb 23 20:23:46 2010 +0100
+++ b/devtools/repotest.py	Wed Feb 24 10:30:31 2010 +0100
@@ -191,15 +191,14 @@
         rqlst.solutions = remove_unused_solutions(rqlst, rqlst.solutions, {}, self.repo.schema)[0]
         return rqlst
 
-    def _user_session(self, groups=('guests',), ueid=None):
+    def user_groups_session(self, *groups):
+        """lightweight session using the current user with hi-jacked groups"""
         # use self.session.user.eid to get correct owned_by relation, unless explicit eid
-        if ueid is None:
-            ueid = self.session.user.eid
-        u = self.repo._build_user(self.session, ueid)
+        u = self.repo._build_user(self.session, self.session.user.eid)
         u._groups = set(groups)
         s = Session(u, self.repo)
         s._threaddata.pool = self.pool
-        return u, s
+        return s
 
     def execute(self, rql, args=None, eid_key=None, build_descr=True):
         return self.o.execute(self.session, rql, args, eid_key, build_descr)
--- a/server/test/unittest_msplanner.py	Tue Feb 23 20:23:46 2010 +0100
+++ b/server/test/unittest_msplanner.py	Wed Feb 24 10:30:31 2010 +0100
@@ -762,7 +762,7 @@
 
     def test_security_has_text(self):
         # use a guest user
-        self.session = self._user_session()[1]
+        self.session = self.user_groups_session('guests')
         self._test('Any X WHERE X has_text "bla"',
                    [('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
                      [self.cards, self.system], None, {'E': 'table0.C0'}, []),
@@ -789,7 +789,7 @@
 
     def test_security_has_text_limit_offset(self):
         # use a guest user
-        self.session = self._user_session()[1]
+        self.session = self.user_groups_session('guests')
         # note: same as the above query but because of the subquery usage, the display differs (not printing solutions for each union)
         self._test('Any X LIMIT 10 OFFSET 10 WHERE X has_text "bla"',
                    [('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
@@ -827,7 +827,7 @@
     def test_security_user(self):
         """a guest user trying to see another user: EXISTS(X owned_by U) is automatically inserted"""
         # use a guest user
-        self.session = self._user_session()[1]
+        self.session = self.user_groups_session('guests')
         self._test('Any X WHERE X login "bla"',
                    [('FetchStep',
                      [('Any X WHERE X login "bla", X is CWUser', [{'X': 'CWUser'}])],
@@ -838,7 +838,7 @@
 
     def test_security_complex_has_text(self):
         # use a guest user
-        self.session = self._user_session()[1]
+        self.session = self.user_groups_session('guests')
         self._test('Any X WHERE X has_text "bla", X firstname "bla"',
                    [('FetchStep', [('Any X WHERE X firstname "bla", X is CWUser', [{'X': 'CWUser'}])],
                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
@@ -852,7 +852,7 @@
 
     def test_security_complex_has_text_limit_offset(self):
         # use a guest user
-        self.session = self._user_session()[1]
+        self.session = self.user_groups_session('guests')
         self._test('Any X LIMIT 10 OFFSET 10 WHERE X has_text "bla", X firstname "bla"',
                    [('FetchStep', [('Any X WHERE X firstname "bla", X is CWUser', [{'X': 'CWUser'}])],
                      [self.ldap, self.system], None, {'X': 'table1.C0'}, []),
@@ -869,7 +869,7 @@
 
     def test_security_complex_aggregat(self):
         # use a guest user
-        self.session = self._user_session()[1]
+        self.session = self.user_groups_session('guests')
         self._test('Any MAX(X)',
                    [('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
                      [self.cards, self.system],  None, {'E': 'table1.C0'}, []),
@@ -914,7 +914,7 @@
 
     def test_security_complex_aggregat2(self):
         # use a guest user
-        self.session = self._user_session()[1]
+        self.session = self.user_groups_session('guests')
         X_ET_ALL_SOLS = []
         for s in X_ALL_SOLS:
             ets = {'ET': 'CWEType'}
@@ -978,7 +978,7 @@
 
     def test_security_3sources(self):
         # use a guest user
-        self.session = self._user_session()[1]
+        self.session = self.user_groups_session('guests')
         self._test('Any X, XT WHERE X is Card, X owned_by U, X title XT, U login "syt"',
                    [('FetchStep',
                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
@@ -996,8 +996,7 @@
     def test_security_3sources_identity(self):
         self.restore_orig_cwuser_security()
         # use a guest user
-        self.session = self._user_session()[1]
-        print self.session
+        self.session = self.user_groups_session('guests')
         self._test('Any X, XT WHERE X is Card, X owned_by U, X title XT, U login "syt"',
                    [('FetchStep',
                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
@@ -1011,7 +1010,7 @@
     def test_security_3sources_identity_optional_var(self):
         self.restore_orig_cwuser_security()
         # use a guest user
-        self.session = self._user_session()[1]
+        self.session = self.user_groups_session('guests')
         self._test('Any X,XT,U WHERE X is Card, X owned_by U?, X title XT, U login L',
                    [('FetchStep',
                      [('Any U,L WHERE U identity 5, U login L, U is CWUser',
@@ -1032,7 +1031,7 @@
 
     def test_security_3sources_limit_offset(self):
         # use a guest user
-        self.session = self._user_session()[1]
+        self.session = self.user_groups_session('guests')
         self._test('Any X, XT LIMIT 10 OFFSET 10 WHERE X is Card, X owned_by U, X title XT, U login "syt"',
                    [('FetchStep',
                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
@@ -1668,7 +1667,7 @@
                     ])
 
     def test_update3(self):
-        anoneid = self._user_session()[1].user.eid
+        anoneid = self.user_groups_session('guests').user.eid
         # since we are adding a in_state relation for an entity in the system
         # source, states should only be searched in the system source as well
         self._test('SET X in_state S WHERE X eid %(x)s, S name "deactivated"',
--- a/server/test/unittest_querier.py	Tue Feb 23 20:23:46 2010 +0100
+++ b/server/test/unittest_querier.py	Wed Feb 24 10:30:31 2010 +0100
@@ -78,7 +78,7 @@
     def test_preprocess_security(self):
         plan = self._prepare_plan('Any ETN,COUNT(X) GROUPBY ETN '
                                   'WHERE X is ET, ET name ETN')
-        plan.session = self._user_session(('users',))[1]
+        plan.session = self.user_groups_session('users')
         union = plan.rqlst
         plan.preprocess(union)
         self.assertEquals(len(union.children), 1)
@@ -158,7 +158,7 @@
 
     def test_preprocess_security_aggregat(self):
         plan = self._prepare_plan('Any MAX(X)')
-        plan.session = self._user_session(('users',))[1]
+        plan.session = self.user_groups_session('users')
         union = plan.rqlst
         plan.preprocess(union)
         self.assertEquals(len(union.children), 1)
@@ -928,7 +928,7 @@
         self.assertEqual(len(rset.rows), 0, rset.rows)
 
     def test_delete_3(self):
-        u, s = self._user_session(('users',))
+        s = self.user_groups_session('users')
         peid, = self.o.execute(s, "INSERT Personne P: P nom 'toto'")[0]
         seid, = self.o.execute(s, "INSERT Societe S: S nom 'logilab'")[0]
         self.o.execute(s, "SET P travaille S")
@@ -959,7 +959,7 @@
         (using cachekey on sql generation returned always the same query for an eid,
         whatever the relation)
         """
-        u, s = self._user_session(('users',))
+        s = self.user_groups_session('users')
         aeid, = self.o.execute(s, 'INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')[0]
         # XXX would be nice if the rql below was enough...
         #'INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y'