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 |
---|
5 | from dolmen.beaker.interfaces import ISessionConfig |
---|
6 | from zope.component import queryUtility |
---|
7 | from zope.component.hooks import setSite |
---|
8 | from zope.publisher.browser import TestRequest |
---|
9 | from zope.session.interfaces import ISession |
---|
10 | from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase |
---|
11 | |
---|
12 | |
---|
13 | class 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) |
---|