#13092: ContextList objects do not support "in" operator
-------------------------------+--------------------------------------------
 Reporter:  anonymous          |       Owner:  nobody    
   Status:  new                |   Milestone:            
Component:  Testing framework  |     Version:  SVN       
 Keywords:  ContextList        |       Stage:  Unreviewed
Has_patch:  1                  |  
-------------------------------+--------------------------------------------
 When running tests, if a single template is used to product a response to
 an HTTP request, then the test client's response context object is a
 regular Context (django.template.Context) object. When multiple templates
 are used, however, then the test client's response context object will be
 a django.test.utils.ContextList object instead.

 The !ContextList class tries to emulate a Context object for dictionary-
 style lookups, so that tests which reference response.context['key'] will
 still work. However, !ContextList does not implement _contains_, so
 expressions of the form "'key' in request.context", which would be true
 when only a single template is used, become false as soon as a second
 template is introduced.

 For example, with this template:

 {{{
 <h1>No Content here</h1>
 }}}

 And this view:

 {{{
 #!python
 from django.shortcuts import render_to_response
 def view(request):
     return render_to_response("test_template.html", { "foo": "bar" })
 }}}

 Then a test which says:

 {{{
 #!python
 class SimpleTest(TestCase):
     def test_context(self):
         response = self.client.get("/test_url/")
         self.assertTrue("foo" in response.context)
 }}}

 will succeed, but if the template is changed to this:

 {{{
 {% extends "base.html" %}
 <h1>No content here</h1>
 }}}

 then the same test will fail. I'm attaching a patch which fixes this, as
 well as a two line patch for the Context/ContextList tests.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13092>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to