Refs #26263 -- Removed deprecated Context.has_key().
This commit is contained in:
parent
bcf3532ede
commit
740f63a3df
|
@ -1,9 +1,6 @@
|
|||
import warnings
|
||||
from contextlib import contextmanager
|
||||
from copy import copy
|
||||
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
|
||||
# Hard-coded processor for easier use of CSRF protection.
|
||||
_builtin_context_processors = ('django.template.context_processors.csrf',)
|
||||
|
||||
|
@ -90,13 +87,6 @@ class BaseContext(object):
|
|||
"Delete a variable from the current context"
|
||||
del self.dicts[-1][key]
|
||||
|
||||
def has_key(self, key):
|
||||
warnings.warn(
|
||||
"%s.has_key() is deprecated in favor of the 'in' operator." % self.__class__.__name__,
|
||||
RemovedInDjango20Warning
|
||||
)
|
||||
return key in self
|
||||
|
||||
def __contains__(self, key):
|
||||
for d in self.dicts:
|
||||
if key in d:
|
||||
|
|
|
@ -345,3 +345,5 @@ these features.
|
|||
|
||||
* ``CommaSeparatedIntegerField`` is removed, except for support in historical
|
||||
migrations.
|
||||
|
||||
* The template ``Context.has_key()`` method is removed.
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import warnings
|
||||
|
||||
from django.http import HttpRequest
|
||||
from django.template import (
|
||||
Context, Engine, RequestContext, Template, Variable, VariableDoesNotExist,
|
||||
)
|
||||
from django.template.context import RenderContext
|
||||
from django.test import RequestFactory, SimpleTestCase, ignore_warnings
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
from django.test import RequestFactory, SimpleTestCase
|
||||
|
||||
|
||||
class ContextTests(SimpleTestCase):
|
||||
|
@ -184,26 +181,6 @@ class ContextTests(SimpleTestCase):
|
|||
"""
|
||||
RequestContext(HttpRequest()).new().new()
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango20Warning)
|
||||
def test_has_key(self):
|
||||
a = Context({'a': 1})
|
||||
b = RequestContext(HttpRequest(), {'a': 1})
|
||||
msg = "Context.has_key() is deprecated in favor of the 'in' operator."
|
||||
msg2 = "RequestContext.has_key() is deprecated in favor of the 'in' operator."
|
||||
|
||||
with warnings.catch_warnings(record=True) as warns:
|
||||
warnings.simplefilter('always')
|
||||
self.assertIs(a.has_key('a'), True)
|
||||
self.assertIs(a.has_key('b'), False)
|
||||
self.assertIs(b.has_key('a'), True)
|
||||
self.assertIs(b.has_key('b'), False)
|
||||
|
||||
self.assertEqual(len(warns), 4)
|
||||
self.assertEqual(str(warns[0].message), msg)
|
||||
self.assertEqual(str(warns[1].message), msg)
|
||||
self.assertEqual(str(warns[2].message), msg2)
|
||||
self.assertEqual(str(warns[3].message), msg2)
|
||||
|
||||
def test_set_upward(self):
|
||||
c = Context({'a': 1})
|
||||
c.set_upward('a', 2)
|
||||
|
|
Loading…
Reference in New Issue