1 # -*- coding: iso-8859-1 -*- |
|
2 """unit tests for cubicweb.web.application |
|
3 |
|
4 :organization: Logilab |
|
5 :copyright: 2001-2011 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
|
6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
7 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
|
8 """ |
|
9 from cubicweb.devtools.testlib import CubicWebTC |
|
10 from cubicweb.web import InvalidSession |
|
11 |
|
12 class SessionTC(CubicWebTC): |
|
13 |
|
14 def test_session_expiration(self): |
|
15 sm = self.app.session_handler.session_manager |
|
16 # make is if the web session has been opened by the session manager |
|
17 sm._sessions[self.cnx.sessionid] = self.websession |
|
18 sessionid = self.websession.sessionid |
|
19 self.assertEqual(len(sm._sessions), 1) |
|
20 self.assertEqual(self.websession.sessionid, self.websession.cnx.sessionid) |
|
21 # fake the repo session is expiring |
|
22 self.repo.close(sessionid) |
|
23 try: |
|
24 # fake an incoming http query with sessionid in session cookie |
|
25 # don't use self.request() which try to call req.set_session |
|
26 req = self.requestcls(self.vreg) |
|
27 self.assertRaises(InvalidSession, sm.get_session, req, sessionid) |
|
28 self.assertEqual(len(sm._sessions), 0) |
|
29 finally: |
|
30 # avoid error in tearDown by telling this connection is closed... |
|
31 self.cnx._closed = True |
|
32 |
|
33 if __name__ == '__main__': |
|
34 from logilab.common.testlib import unittest_main |
|
35 unittest_main() |
|