summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2013-05-13 17:38:29 +0100
committerAnssi Kääriäinen <akaariai@gmail.com>2013-06-01 00:04:06 +0300
commitfa7cb4ef3cc5f4c3514857bd25b43d31815eba94 (patch)
tree9f16661defc860f807bbebc25b74f7f8116e2321 /tests
parent5090c7b58bd3c774daf17a13d7408968f0ee8da0 (diff)
Fixed #20404 -- Added a keys() method to ContextList.
It's useful to be able to list all the (flattened) keys of a ContextList, to help you figure out why the variable that's supposed to be there is not. No .values() or .items() added as the definition for those aren't clear. The patch is Chris Wilson's patch from pull request 1065 with some modifications by committer.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_client_regress/tests.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
index 654f65235a..dc656c127d 100644
--- a/tests/test_client_regress/tests.py
+++ b/tests/test_client_regress/tests.py
@@ -6,9 +6,8 @@ from __future__ import unicode_literals
import os
-from django.conf import settings
from django.core.urlresolvers import reverse
-from django.template import (TemplateDoesNotExist, TemplateSyntaxError,
+from django.template import (TemplateSyntaxError,
Context, Template, loader)
import django.template.context
from django.test import Client, TestCase
@@ -897,6 +896,21 @@ class ContextTests(TestCase):
except KeyError as e:
self.assertEqual(e.args[0], 'does-not-exist')
+ def test_contextlist_keys(self):
+ c1 = Context()
+ c1.update({'hello': 'world', 'goodbye': 'john'})
+ c1.update({'hello': 'dolly', 'dolly': 'parton'})
+ c2 = Context()
+ c2.update({'goodbye': 'world', 'python': 'rocks'})
+ c2.update({'goodbye': 'dolly'})
+
+ l = ContextList([c1, c2])
+ # None, True and False are builtins of BaseContext, and present
+ # in every Context without needing to be added.
+ self.assertEqual(set(['None', 'True', 'False', 'hello', 'goodbye',
+ 'python', 'dolly']),
+ l.keys())
+
def test_15368(self):
# Need to insert a context processor that assumes certain things about
# the request instance. This triggers a bug caused by some ways of