summaryrefslogtreecommitdiff
path: root/tests/template_tests/test_context.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-02-22 13:25:01 -0500
committerTim Graham <timograham@gmail.com>2016-02-23 08:08:55 -0500
commitcdbd8745f6c550422170a6ae5928c0b679fab0df (patch)
tree5b0b5beecf16b992bbb84fd5fc524164208761ba /tests/template_tests/test_context.py
parent269b5f262cef88cb595b21a76e707b41ee4ed627 (diff)
Fixed #26263 -- Deprecated Context.has_key()
Diffstat (limited to 'tests/template_tests/test_context.py')
-rw-r--r--tests/template_tests/test_context.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/template_tests/test_context.py b/tests/template_tests/test_context.py
index 87b2016aa5..2fa7715d27 100644
--- a/tests/template_tests/test_context.py
+++ b/tests/template_tests/test_context.py
@@ -1,11 +1,13 @@
# -*- 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
+from django.test import RequestFactory, SimpleTestCase, ignore_warnings
+from django.utils.deprecation import RemovedInDjango20Warning
class ContextTests(SimpleTestCase):
@@ -182,6 +184,26 @@ 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.assertEqual(a.has_key('a'), True)
+ self.assertEqual(a.has_key('b'), False)
+ self.assertEqual(b.has_key('a'), True)
+ self.assertEqual(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)
+
class RequestContextTests(SimpleTestCase):