示例#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
文件: tests.py 项目: 15580056814/hue
 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
文件: tests.py 项目: atizo/django
    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
文件: loaders.py 项目: ssaltzman/POET
    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
文件: tests.py 项目: GdZ/scriptfile
    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
文件: tests.py 项目: mick/django
    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
文件: tests.py 项目: mick/django
    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
文件: tests.py 项目: mick/django
 def setUp(self):
     self.warning_state = get_warnings_state()
     warnings.filterwarnings('ignore', category=DeprecationWarning,
                             module='django.views.decorators.cache')
示例#19
0
文件: tests.py 项目: girum11/hang
 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
文件: utils.py 项目: 101studio/django
 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
文件: tests.py 项目: 101studio/django
 def setUp(self):
     self._warnings_state = get_warnings_state()
     warnings.filterwarnings('ignore', category=DeprecationWarning,
                             module='django.test.simple')