Refs #26263 -- Removed deprecated Context.has_key().

This commit is contained in:
Tim Graham 2016-12-31 11:02:10 -05:00
parent bcf3532ede
commit 740f63a3df
3 changed files with 3 additions and 34 deletions

View File

@ -1,9 +1,6 @@
import warnings
from contextlib import contextmanager from contextlib import contextmanager
from copy import copy from copy import copy
from django.utils.deprecation import RemovedInDjango20Warning
# Hard-coded processor for easier use of CSRF protection. # Hard-coded processor for easier use of CSRF protection.
_builtin_context_processors = ('django.template.context_processors.csrf',) _builtin_context_processors = ('django.template.context_processors.csrf',)
@ -90,13 +87,6 @@ class BaseContext(object):
"Delete a variable from the current context" "Delete a variable from the current context"
del self.dicts[-1][key] 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): def __contains__(self, key):
for d in self.dicts: for d in self.dicts:
if key in d: if key in d:

View File

@ -345,3 +345,5 @@ these features.
* ``CommaSeparatedIntegerField`` is removed, except for support in historical * ``CommaSeparatedIntegerField`` is removed, except for support in historical
migrations. migrations.
* The template ``Context.has_key()`` method is removed.

View File

@ -1,13 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import warnings
from django.http import HttpRequest from django.http import HttpRequest
from django.template import ( from django.template import (
Context, Engine, RequestContext, Template, Variable, VariableDoesNotExist, Context, Engine, RequestContext, Template, Variable, VariableDoesNotExist,
) )
from django.template.context import RenderContext from django.template.context import RenderContext
from django.test import RequestFactory, SimpleTestCase, ignore_warnings from django.test import RequestFactory, SimpleTestCase
from django.utils.deprecation import RemovedInDjango20Warning
class ContextTests(SimpleTestCase): class ContextTests(SimpleTestCase):
@ -184,26 +181,6 @@ class ContextTests(SimpleTestCase):
""" """
RequestContext(HttpRequest()).new().new() 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): def test_set_upward(self):
c = Context({'a': 1}) c = Context({'a': 1})
c.set_upward('a', 2) c.set_upward('a', 2)