Opened 17 years ago

Closed 16 years ago

#5333 closed (fixed)

add an assertContext method to Django's TestCase

Reported by: Gary Wilson Owned by: Kevin Kubasik
Component: Testing framework Version: dev
Severity: Keywords: feature
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

A method for testing that a context used for rendering a response contains a specified value. To be used as:

self.assertContext(response, variable_name, value)

Attachments (1)

5333.diff (11.9 KB ) - added by Gary Wilson 17 years ago.

Download all attachments as: .zip

Change History (9)

by Gary Wilson, 17 years ago

Attachment: 5333.diff added

comment:1 by Gary Wilson, 17 years ago

Needs documentation: set
Triage Stage: UnreviewedDesign decision needed

hmmm, not sure why the diff doesn't show in the Trac viewer.

comment:2 by Johan Bergström, 17 years ago

You probably want to name the file "5333.patch" (i had similar issues earlier)

comment:3 by Russell Keith-Magee, 17 years ago

My hesitation here (and the reason I didn't include a 'context assert' in the first place) is that assertContext does an Equals test, but doesn't provide a way to do any other assertion - NotEquals, True, False, LessThan, etc. We could get around this by adding assertContextEquals, assertContextNotEquals, and so on, but that is really just duplicating the underlying assertion API. This is certainly possible, but I'm not convinced it is the best approach.

An alternate approach would be to provide a utility function to get the value of a context variable from the list of contexts in a response. This would allow the use of all the standard assert methods. However, I'm not entirely sure where such a utility function should go. Putting it on the TestCase itself rubs me the wrong way.

I'm open to suggestions (or to comments that I'm just round-the-twist crazy).

For future reference, some feedback on the patch itself:

  1. The test cases should check the multiple-context case, not just the single-context case
  2. If possible, it would also be good to provide the 'trailing space' parts of the patch separately to the new assertion+tests. As is, there is a lot of noise in the patch from all the whitespace stripping changes, which is an impediment to the immediate understanding of the patch.

comment:4 by Philippe Raoult, 17 years ago

Keywords: feature added

comment:5 by Malcolm Tredinnick, 16 years ago

I prefer the approach Russell's talking about in comment 3. A nice way to check the value that would be used if I rendered "foo" from the context that understands context are sometimes like an onion (does that mean they're also like an ogre?).

I don't think such a function should live on TestCase, since that would hurt doctests. It has no class dependencies, so just make it a utility function. A standalone function that accepts a context and a variable name would seem to do the trick.

comment:6 by Kevin Kubasik, 16 years ago

Owner: changed from nobody to Kevin Kubasik

comment:7 by Julien Phalip, 16 years ago

Since [10084] it is possible to easily access/control any variable in the response's context, so I presume this assertContext method is not really needed anymore. Shall this ticket be closed?

comment:8 by Russell Keith-Magee, 16 years ago

Resolution: fixed
Status: newclosed

Agreed. This one is essentially resolved.

Note: See TracTickets for help on using tickets.
Back to Top