Пример #1
0
 def test_load_overlong_key(self):
     warnings_state = get_warnings_state()
     warnings.filterwarnings('ignore',
                             category=CacheKeyWarning)
     self.session._session_key = (string.ascii_letters + string.digits) * 20
     self.assertEqual(self.session.load(), {})
     restore_warnings_state(warnings_state)
Пример #2
0
 def test_load_overlong_key(self):
     warnings_state = get_warnings_state()
     warnings.filterwarnings('ignore',
                             category=CacheKeyWarning)
     self.session._session_key = (string.ascii_letters + string.digits) * 20
     self.assertEqual(self.session.load(), {})
     restore_warnings_state(warnings_state)
Пример #3
0
    def test_invalid_keys(self):
        """
        All the builtin backends (except memcached, see below) should warn on
        keys that would be refused by memcached. This encourages portable
        caching code without making it too difficult to use production backends
        with more liberal key rules. Refs #6447.

        """
        # mimic custom ``make_key`` method being defined since the default will
        # never show the below warnings
        def func(key, *args):
            return key

        old_func = self.cache.key_func
        self.cache.key_func = func
        # On Python 2.6+ we could use the catch_warnings context
        # manager to test this warning nicely. Since we can't do that
        # yet, the cleanest option is to temporarily ask for
        # CacheKeyWarning to be raised as an exception.
        _warnings_state = get_warnings_state()
        warnings.simplefilter("error", CacheKeyWarning)

        try:
            # memcached does not allow whitespace or control characters in keys
            self.assertRaises(CacheKeyWarning, self.cache.set, 'key with spaces', 'value')
            # memcached limits key length to 250
            self.assertRaises(CacheKeyWarning, self.cache.set, 'a' * 251, 'value')
        finally:
            restore_warnings_state(_warnings_state)
            self.cache.key_func = old_func
Пример #4
0
 def setUp(self):
     self._warnings_state = get_warnings_state()
     warnings.filterwarnings("ignore",
                             category=DeprecationWarning,
                             module='django.contrib.syndication.views')
     warnings.filterwarnings("ignore",
                             category=DeprecationWarning,
                             module='django.contrib.syndication.feeds')
Пример #5
0
    def setUp(self):
        pkg_resources._provider_factories[MockLoader] = MockProvider

        self.empty_egg = create_egg("egg_empty", {})
        self.egg_1 = create_egg("egg_1", {
            os.path.normcase('templates/y.html') : StringIO.StringIO("y"),
            os.path.normcase('templates/x.txt') : StringIO.StringIO("x"),
        })
        self._old_installed_apps = settings.INSTALLED_APPS
        settings.INSTALLED_APPS = []
        self._warnings_state = get_warnings_state()
        warnings.simplefilter("ignore", PendingDeprecationWarning)
Пример #6
0
    def setUp(self):
        from django.test.utils import get_warnings_state
        import warnings
        self._warnings_state = get_warnings_state()
        warnings.filterwarnings('ignore', category=DeprecationWarning,
                                module='django.template.defaulttags')

        self.old_static_url = settings.STATIC_URL
        self.old_media_url = settings.MEDIA_URL
        settings.STATIC_URL = u"/static/"

        settings.MEDIA_URL = u"/media/"
Пример #7
0
    def setUp(self):
        pkg_resources._provider_factories[MockLoader] = MockProvider

        self.empty_egg = create_egg("egg_empty", {})
        self.egg_1 = create_egg("egg_1", {
            os.path.normcase('templates/y.html') : StringIO.StringIO("y"),
            os.path.normcase('templates/x.txt') : StringIO.StringIO("x"),
        })
        self._old_installed_apps = settings.INSTALLED_APPS
        settings.INSTALLED_APPS = []
        self._warnings_state = get_warnings_state()
        warnings.filterwarnings("ignore", category=DeprecationWarning,
                                module='django.template.loaders.eggs')
Пример #8
0
    def setUp(self):
        pkg_resources._provider_factories[MockLoader] = MockProvider

        self.empty_egg = create_egg("egg_empty", {})
        self.egg_1 = create_egg(
            "egg_1",
            {
                os.path.normcase("templates/y.html"): StringIO.StringIO("y"),
                os.path.normcase("templates/x.txt"): StringIO.StringIO("x"),
            },
        )
        self._old_installed_apps = settings.INSTALLED_APPS
        settings.INSTALLED_APPS = []
        self._warnings_state = get_warnings_state()
        warnings.filterwarnings("ignore", category=DeprecationWarning, module="django.template.loaders.eggs")
Пример #9
0
    def test_raw_post_data_returns_body(self):
        """
        HttpRequest.raw_post_body should be the same as HttpRequest.body
        """
        payload = 'Hello There!'
        request = WSGIRequest({
            'REQUEST_METHOD': 'POST',
            'CONTENT_LENGTH': len(payload),
            'wsgi.input': StringIO(payload)
        })

        warnings_state = get_warnings_state()
        warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.http')
        try:
            self.assertEqual(request.body, request.raw_post_data)
        finally:
            restore_warnings_state(warnings_state)
Пример #10
0
    def test_raw_post_data_returns_body(self):
        """
        HttpRequest.raw_post_body should be the same as HttpRequest.body
        """
        payload = 'Hello There!'
        request = WSGIRequest({
            'REQUEST_METHOD': 'POST',
            'CONTENT_LENGTH': len(payload),
            'wsgi.input': StringIO(payload)
        })

        warnings_state = get_warnings_state()
        warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.http')
        try:
            self.assertEqual(request.body, request.raw_post_data)
        finally:
            restore_warnings_state(warnings_state)
Пример #11
0
    def test_filter_added(self):
        """
        Test that debug-false filter is added to mail_admins handler if it has
        no filters.

        """
        config = copy.deepcopy(OLD_LOGGING)

        warnings_state = get_warnings_state()
        warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.conf')
        try:
            compat_patch_logging_config(config)
        finally:
            restore_warnings_state(warnings_state)

        self.assertEqual(
            config["handlers"]["mail_admins"]["filters"],
            ['require_debug_false'])
Пример #12
0
    def test_POST_connection_error(self):
        """
        If wsgi.input.read() raises an exception while trying to read() the
        POST, the exception should be identifiable (not a generic IOError).
        """
        class ExplodingStringIO(StringIO):
            def read(self, len=0):
                raise IOError("kaboom!")

        payload = 'name=value'
        request = WSGIRequest({'REQUEST_METHOD': 'POST',
                               'CONTENT_LENGTH': len(payload),
                               'wsgi.input': ExplodingStringIO(payload)})

        warnings_state = get_warnings_state()
        warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.http')
        try:
            with self.assertRaises(UnreadablePostError):
                request.raw_post_data
        finally:
            restore_warnings_state(warnings_state)
Пример #13
0
    def test_invalid_keys(self):
        """
        All the builtin backends (except memcached, see below) should warn on
        keys that would be refused by memcached. This encourages portable
        caching code without making it too difficult to use production backends
        with more liberal key rules. Refs #6447.

        """
        # On Python 2.6+ we could use the catch_warnings context
        # manager to test this warning nicely. Since we can't do that
        # yet, the cleanest option is to temporarily ask for
        # CacheKeyWarning to be raised as an exception.
        _warnings_state = get_warnings_state()
        warnings.simplefilter("error", CacheKeyWarning)

        try:
            # memcached does not allow whitespace or control characters in keys
            self.assertRaises(CacheKeyWarning, self.cache.set, 'key with spaces', 'value')
            # memcached limits key length to 250
            self.assertRaises(CacheKeyWarning, self.cache.set, 'a' * 251, 'value')
        finally:
            restore_warnings_state(_warnings_state)
Пример #14
0
 def setUp(self):
     self._warnings_state = get_warnings_state()
     warnings.filterwarnings("ignore", category=DeprecationWarning,
                             module='django.contrib.syndication.views')
     warnings.filterwarnings("ignore", category=DeprecationWarning,
                             module='django.contrib.syndication.feeds')
Пример #15
0
 def save_warnings_state(self):
     self._warnings_state = get_warnings_state()
Пример #16
0
 def setUp(self):
     self.warning_state = get_warnings_state()
     warnings.filterwarnings('ignore',
                             category=PendingDeprecationWarning,
                             module='django.views.decorators.cache')
Пример #17
0
 def setUp(self):
     self._warnings_state = get_warnings_state()
     warnings.filterwarnings('ignore', category=DeprecationWarning,
                             module='django.contrib.formtools.utils')
Пример #18
0
 def setUp(self):
     self.warning_state = get_warnings_state()
     warnings.filterwarnings('ignore', category=DeprecationWarning,
                             module='django.views.decorators.cache')
Пример #19
0
 def setUp(self):
     self._warnings_state = get_warnings_state()
     warnings.filterwarnings('ignore',
                             category=DeprecationWarning,
                             module='django.test.simple')
Пример #20
0
 def setUp(self):
     self.warning_state = get_warnings_state()
     self.old_settings_module = settings.SETTINGS_MODULE
     settings.SETTINGS_MODULE = 'regressiontests'
     self.old_locale_paths = settings.LOCALE_PATHS
Пример #21
0
 def save_warnings_state(self):
     """
     Saves the state of the warnings module
     """
     self._warnings_state = get_warnings_state()
Пример #22
0
 def save_warnings_state(self):
     self._warnings_state = get_warnings_state()
Пример #23
0
 def setUp(self):
     self._warnings_state = get_warnings_state()
     warnings.filterwarnings('ignore',
                             category=DeprecationWarning,
                             module='django.contrib.formtools.utils')
Пример #24
0
 def save_warnings_state(self):
     """
     Saves the state of the warnings module
     """
     self._warnings_state = get_warnings_state()
Пример #25
0
 def setUp(self):
     self._warnings_state = get_warnings_state()
     warnings.filterwarnings('ignore', category=DeprecationWarning,
                             module='django.test.simple')