[testlib] rework request building in init_authentication
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 24 Jun 2013 12:41:27 +0200
changeset 9039 488255d1cf3b
parent 9038 1b972d81eda4
child 9040 3c85e734ce00
[testlib] rework request building in init_authentication The previous code was building a full authenticated request and tried to undo the authentication afterward. The new code just create a bare Request with no authenticated session linked yet. This is much closer of what the actual authentication process does.
devtools/testlib.py
web/test/unittest_application.py
--- a/devtools/testlib.py	Mon Jun 24 12:39:25 2013 +0200
+++ b/devtools/testlib.py	Mon Jun 24 12:41:27 2013 +0200
@@ -768,17 +768,14 @@
 
     def init_authentication(self, authmode, anonuser=None):
         self.set_auth_mode(authmode, anonuser)
-        req = self.request(url='login')
-        origsession = req.session
-        req.session = req.cnx = None
-        del req.execute # get back to class implementation
+        req = self.requestcls(self.vreg, url='login')
         sh = self.app.session_handler
         authm = sh.session_manager.authmanager
         authm.anoninfo = self.vreg.config.anonymous_user()
         authm.anoninfo = authm.anoninfo[0], {'password': authm.anoninfo[1]}
         # not properly cleaned between tests
         self.open_sessions = sh.session_manager._sessions = {}
-        return req, origsession
+        return req, self.websession
 
     def assertAuthSuccess(self, req, origsession, nbsessions=1):
         sh = self.app.session_handler
--- a/web/test/unittest_application.py	Mon Jun 24 12:39:25 2013 +0200
+++ b/web/test/unittest_application.py	Mon Jun 24 12:41:27 2013 +0200
@@ -338,7 +338,7 @@
         clear_cache(req, 'get_authorization')
         self.assertTrue('__login' in form)
         self.assertTrue('__password' in form)
-        self.assertEqual(req.cnx, None)
+        self.assertFalse(req.cnx) # Mock cnx are False
         req.form['__login'] = self.admlogin
         req.form['__password'] = self.admpassword
         self.assertAuthSuccess(req, origsession)