[9217] | 1 | # Tests for local startup functions. |
---|
| 2 | import os |
---|
| 3 | import shutil |
---|
| 4 | import tempfile |
---|
| 5 | import unittest |
---|
| 6 | from zope.app.wsgi import WSGIPublisherApplication |
---|
[11949] | 7 | from waeup.ikoba.startup import env_app_factory, env_debug_app_factory |
---|
[9217] | 8 | |
---|
| 9 | ZOPE_CONF_TEMPL = ''' |
---|
| 10 | site-definition %s |
---|
| 11 | |
---|
| 12 | <zodb> |
---|
| 13 | <mappingstorage /> |
---|
| 14 | </zodb> |
---|
| 15 | |
---|
| 16 | <eventlog> |
---|
| 17 | <logfile> |
---|
| 18 | path STDOUT |
---|
| 19 | </logfile> |
---|
| 20 | </eventlog> |
---|
| 21 | ''' |
---|
| 22 | |
---|
| 23 | class 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 |
---|