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)
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
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')
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)
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/"
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')
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")
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)
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'])
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)
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)
def save_warnings_state(self): self._warnings_state = get_warnings_state()
def setUp(self): self.warning_state = get_warnings_state() warnings.filterwarnings('ignore', category=PendingDeprecationWarning, module='django.views.decorators.cache')
def setUp(self): self._warnings_state = get_warnings_state() warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.contrib.formtools.utils')
def setUp(self): self.warning_state = get_warnings_state() warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.views.decorators.cache')
def setUp(self): self._warnings_state = get_warnings_state() warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.test.simple')
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
def save_warnings_state(self): """ Saves the state of the warnings module """ self._warnings_state = get_warnings_state()