source: main/waeup.kofa/branches/uli-rm-bootstrap/src/waeup/kofa/tests/test_startup.py @ 17935

Last change on this file since 17935 was 12110, checked in by Henrik Bettermann, 10 years ago

svn propset svn:keywords "Id"

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1# Tests for local startup functions.
2import os
3import shutil
4import tempfile
5import unittest
6from zope.app.wsgi import WSGIPublisherApplication
7from waeup.kofa.startup import env_app_factory, env_debug_app_factory
8
9ZOPE_CONF_TEMPL = '''
10site-definition %s
11
12<zodb>
13  <mappingstorage />
14</zodb>
15
16<eventlog>
17  <logfile>
18    path STDOUT
19  </logfile>
20</eventlog>
21'''
22
23class StartUpTests(unittest.TestCase):
24
25    def setUp(self):
26        self.workdir = tempfile.mkdtemp()
27        self.site_zcml = os.path.join(self.workdir, 'site.zcml')
28        open(self.site_zcml, 'w').write('<configure />')
29        self.zope_conf = os.path.join(self.workdir, 'zope.conf')
30        open(self.zope_conf, 'wb').write(ZOPE_CONF_TEMPL % self.site_zcml)
31        return
32
33    def tearDown(self):
34        shutil.rmtree(self.workdir)
35        for name in ('TEST_FOO', 'TEST_BAR'):
36            if name in os.environ:
37                del os.environ[name]
38        return
39
40    def test_env_app_factory(self):
41        # We can create plain WSGI apps
42        factory = env_app_factory({'zope_conf': self.zope_conf})
43        self.assertTrue(
44            isinstance(factory, WSGIPublisherApplication))
45        return
46
47    def test_env_app_factory_single_env_var(self):
48        # We can create WSGI apps with a single env var set
49        factory = env_app_factory({'zope_conf': self.zope_conf,
50                                   'env_vars': 'TEST_FOO value1'})
51        self.assertEqual(os.environ.get('TEST_FOO', None), 'value1')
52        return
53
54    def test_env_app_factory_multiple_env_vars(self):
55        # We can create WSGI apps with multiple env vars set
56        env_vars = 'TEST_FOO  value1   \n  TEST_BAR  value2'
57        factory = env_app_factory({'zope_conf': self.zope_conf,
58                                   'env_vars': env_vars})
59        self.assertEqual(os.environ.get('TEST_FOO', None), 'value1')
60        self.assertEqual(os.environ.get('TEST_BAR', None), 'value2')
61        return
62
63    def test_env_debug_app_factory(self):
64        # We can create debugger WSGI apps
65        factory = env_debug_app_factory({'zope_conf': self.zope_conf})
66        self.assertTrue(
67            isinstance(factory, WSGIPublisherApplication))
68        return
69        pass
70
71    def test_env_debug_app_factory_single_env_var(self):
72        # We can create debugger WSGI apps with a single env var set
73        factory = env_debug_app_factory({'zope_conf': self.zope_conf,
74                                         'env_vars': 'TEST_FOO value1'})
75        self.assertEqual(os.environ.get('TEST_FOO', None), 'value1')
76        return
Note: See TracBrowser for help on using the repository browser.