source: main/waeup.kofa/trunk/src/waeup/kofa/tests/test_beaker.py @ 17867

Last change on this file since 17867 was 17280, checked in by uli, 2 years ago

Upgrade dolmen.beaker dependency. Requires new buildout run.

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1# We test beaker functionality, although we have no beaker-related code
2# anymore. All configuration is done in ZCML snippets in
3# site.zcml/ftesting.zcml now.
4# The dolmen.beaker package is developed on: https://github.com/trollfot/dolmen.beaker
5from dolmen.beaker.interfaces import ISessionConfig
6from zope.component import queryUtility
7from zope.component.hooks import setSite
8from zope.publisher.browser import TestRequest
9from zope.session.interfaces import ISession
10from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
11
12
13class BeakerTests(FunctionalTestCase):
14    # Beaker-related tests.
15
16    layer = FunctionalLayer
17
18    def test_beaker_session(self):
19        # Make sure we get a beaker session when asking for ISession.
20        try:
21            import dolmen.beaker
22        except ImportError:
23            # no beaker installed, no test
24            return
25        setSite(self.getRootFolder()) # needed to start transaction
26        request = TestRequest()
27        session = ISession(request)  # this is a Zope session
28        self.assertTrue(session.__module__.startswith('dolmen.beaker'))
29        self.assertTrue(session.get("_path", None) is not None)
30        return
31
32    def test_beaker_session_values(self):
33        # Ensure we get also a beaker session
34        # (which is part of a Zope session)
35        try:
36            import dolmen.beaker
37        except ImportError:
38            # no beaker installed, no test
39            return
40        setSite(self.getRootFolder()) # needed to start transaction
41        config = ISessionConfig
42        request = TestRequest()
43        session = ISession(request).session
44        self.assertEqual(session.__module__, "beaker.session")
45        self.assertTrue(session.get("_path", None) is not None)
46        return
47
48    def test_beaker_config_accessible(self):
49        # The session config is set in site.zcml / ftesting.zcml
50        # See beakerSession directive
51        # See https://github.com/trollfot/dolmen.beaker/blob/master/src/dolmen/beaker/zcml.py
52        # for options
53        config = queryUtility(ISessionConfig)
54        self.assertEqual(config.get("key"), "waeup.kofa.session.id")
55        self.assertEqual(config.get("timeout"), 3600)
Note: See TracBrowser for help on using the repository browser.