Loading django/template/context.py +10 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,16 @@ class BaseContext(object): new_context._reset_dicts(values) return new_context def __eq__(self, other): """ Compares two contexts by comparing theirs 'dicts' attributes. """ if isinstance(other, BaseContext): return self.dicts[-1] == other.dicts[-1] # if it's not comparable return false return False class Context(BaseContext): "A stack container for variable context" Loading tests/template_tests/test_context.py +5 −0 Original line number Diff line number Diff line Loading @@ -49,3 +49,8 @@ class ContextTests(TestCase): with self.assertRaises(KeyError): test_context['fruit'] self.assertIsNone(test_context.get('fruit')) def test_context_comparable(self): test_data = {'x': 'y', 'v': 'z', 'd': {'o': object, 'a': 'b'}} self.assertEquals(Context(test_data), Context(test_data)) tests/template_tests/tests.py +13 −0 Original line number Diff line number Diff line Loading @@ -1928,6 +1928,19 @@ class RequestContextTests(unittest.TestCase): # [builtins, supplied context, context processor] self.assertEqual(len(ctx.dicts), 3) @override_settings(TEMPLATE_CONTEXT_PROCESSORS=()) def test_context_comparable(self): test_data = {'x': 'y', 'v': 'z', 'd': {'o': object, 'a': 'b'}} # test comparing RequestContext to prevent problems if somebody # adds __eq__ in the future request = RequestFactory().get('/') self.assertEquals( RequestContext(request, dict_=test_data), RequestContext(request, dict_=test_data) ) class SSITests(TestCase): def setUp(self): Loading Loading
django/template/context.py +10 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,16 @@ class BaseContext(object): new_context._reset_dicts(values) return new_context def __eq__(self, other): """ Compares two contexts by comparing theirs 'dicts' attributes. """ if isinstance(other, BaseContext): return self.dicts[-1] == other.dicts[-1] # if it's not comparable return false return False class Context(BaseContext): "A stack container for variable context" Loading
tests/template_tests/test_context.py +5 −0 Original line number Diff line number Diff line Loading @@ -49,3 +49,8 @@ class ContextTests(TestCase): with self.assertRaises(KeyError): test_context['fruit'] self.assertIsNone(test_context.get('fruit')) def test_context_comparable(self): test_data = {'x': 'y', 'v': 'z', 'd': {'o': object, 'a': 'b'}} self.assertEquals(Context(test_data), Context(test_data))
tests/template_tests/tests.py +13 −0 Original line number Diff line number Diff line Loading @@ -1928,6 +1928,19 @@ class RequestContextTests(unittest.TestCase): # [builtins, supplied context, context processor] self.assertEqual(len(ctx.dicts), 3) @override_settings(TEMPLATE_CONTEXT_PROCESSORS=()) def test_context_comparable(self): test_data = {'x': 'y', 'v': 'z', 'd': {'o': object, 'a': 'b'}} # test comparing RequestContext to prevent problems if somebody # adds __eq__ in the future request = RequestFactory().get('/') self.assertEquals( RequestContext(request, dict_=test_data), RequestContext(request, dict_=test_data) ) class SSITests(TestCase): def setUp(self): Loading