diff options
Diffstat (limited to 'tests/template_tests/test_context.py')
| -rw-r--r-- | tests/template_tests/test_context.py | 24 |
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): |
