wheezy.web / src / wheezy / web / middleware / tests / test_bootstrap.py

""" Unit tests for ``wheezy.web.middleware.bootstrap``.
"""

import unittest

from mock import Mock
from mock import patch


class BootstrapWebDefaultsTestCase(unittest.TestCase):
    """ Test the ``bootstrap_defaults``.
    """

    def setUp(self):
        from wheezy.web.middleware import bootstrap
        self.patcher = patch.object(bootstrap, 'bootstrap_http_defaults')
        self.patcher.start()
        try:
            from warnings import catch_warnings
            self.ctx = catch_warnings(record=True)
            self.w = self.ctx.__enter__()
        except ImportError:
            self.ctx = None

    def tearDown(self):
        self.patcher.stop()
        if self.ctx:
            self.ctx.__exit__(None, None, None)

    def assert_warning(self, msg):
        if self.ctx:
            assert len(self.w) == 1
            self.assertEquals(msg, str(self.w[-1].message))

    def test_default_options(self):
        """ Ensure required keys exist.
        """
        from wheezy.web.middleware.bootstrap import bootstrap_defaults
        options = {}

        assert None == bootstrap_defaults({})(options)

        required_options = tuple(sorted(options.keys()))
        assert 12 == len(required_options)
        assert ('AUTH_COOKIE', 'AUTH_COOKIE_DOMAIN', 'AUTH_COOKIE_PATH',
                'AUTH_COOKIE_SECURE', 'CONTENT_TYPE', 'ENCODING',
                'RESUBMISSION_NAME', 'XSRF_NAME', 'path_for', 'path_router',
                'ticket', 'translations_manager') == required_options

    def test_path_router(self):
        """ Ensure required keys exist.
        """
        from wheezy.web.middleware.bootstrap import bootstrap_defaults
        mock_path_router = Mock()
        options = {
            'path_router': mock_path_router
        }

        assert None == bootstrap_defaults({
            'signin': 'signin'
        })(options)

        assert tuple(options.keys())

    def test_warnings(self):
        """ Ensure warnings are issued.
        """
        from wheezy.web.middleware.bootstrap import bootstrap_defaults
        options = {
            'ticket': None
        }

        assert None == bootstrap_defaults({})(options)
        self.assert_warning('Bootstrap: render_template is not defined')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.