Test HttpResponse template attribute needlessly hard to use
|Reported by:||Carl Meyer||Owned by:||Carl Meyer|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||no||Patch needs improvement:||yes|
template attribute of the response objects returned by Django's test client might be a single template object or might be a list of template objects, depending whether template inheritance was used. If one tries to write tests that are usable in the presence of user-overridden templates, this results in noisy boilerplate in the tests:
response = client.get('/') try: template_name = response.template.name except AttributeError: template_name = response.template.name
There's no need for all this: the attribute should simply always be a list, sometimes of length 1.
I would suggest that a new attribute
templates could be added which is always a list, and the old attribute
template could go through the usual deprecation cycle.
I'll work on a patch if this approach is accepted in principle.
Change History (9)
comment:2 Changed 7 years ago by
|Owner:||changed from nobody to Carl Meyer|
|Version:||1.1 → SVN|