While waiting for the patch in ticket #13092 (ContextList objects do
not support "in" operator) to land in Django (hopefully by 1.3), I've
been using a trivial custom method, assertContextContains, to see if
the Context/ContextList of a response object contains a certain key or
a certain key/value pair. I've found this a lot less brittle than
looking at response contents with assert(Not)Contains.

When the fix for #13092 lands in trunk, asserting context contents
will be trivially doable like this:

self.assert_('varname' in response.context)

or, for values:

self.assert_('varname' in response.context and
response.context[varname] == somevalue)

I'd like to get some core dev feedback on whether this pattern should
be codified into official assertContext(Not)Contains methods in
django.test.testcases.TransactionTestCase. I volunteer to create the
ticket and submit the patch with the proper msg_prefix plumbing and
some docs and tests, if the idea gets traction.

With a little more work, I can probably make the method accept lists
(for lists of keys to check) and dictionaries (to check for multiple
key/value pairs) while I'm at it, though at this point the method
signature probably needs a bit more thought.

IMHO, a method like this would nicely complement the existing
assertions; they already cover what templates got rendered and what
the contents and form errors of the responses were, so an assertion to
see what contexts produced those responses out of those templates
seems like a logical addition. But what do you think? Is it worth the
effort?

- JK Laiho

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

Reply via email to