Opened 11 years ago
Closed 10 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: | master |
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)
Change History (9)
Changed 11 years ago by
comment:1 Changed 11 years ago by
Needs documentation: | set |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 Changed 11 years ago by
You probably want to name the file "5333.patch" (i had similar issues earlier)
comment:3 Changed 11 years ago by
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:
- The test cases should check the multiple-context case, not just the single-context case
- 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 Changed 11 years ago by
Keywords: | feature added |
---|
comment:5 Changed 11 years ago by
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 Changed 10 years ago by
Owner: | changed from nobody to Kevin Kubasik |
---|
comment:7 Changed 10 years ago by
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 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Agreed. This one is essentially resolved.
hmmm, not sure why the diff doesn't show in the Trac viewer.