Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#17604 closed New feature (fixed)

Make use of assertTemplateUsed and assertTemplateNotUsed as ContextManagers

Reported by: Gregor Müllegger Owned by: Gregor Müllegger
Component: Testing framework Version: 1.3
Severity: Normal Keywords: assertTemplateUsed, assertTemplateNotUsed, contextmanager
Cc: kmike84@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It can be useful to use the assertTemplateUsed assertion on a limited block of code via a context manager instead on a request:

with self.assertTemplateUsed('template_used/base.html'):
    render_to_string('template_used/base.html')

This is something that already proofed useful in the soc2011/form-rendering branch. It's implemented there and is well tested: https://github.com/gregmuellegger/django/blob/soc2011/form-rendering/django/test/testcases.py#L720

Same is true for assertTemplateNotUsed.

Attachments (2)

17604-assertTemplateUsed.1.diff (12.9 KB ) - added by Gregor Müllegger 13 years ago.
17604-assertTemplateUsed.2.diff (13.0 KB ) - added by Gregor Müllegger 13 years ago.
merged with trunk

Download all attachments as: .zip

Change History (10)

comment:1 by Gregor Müllegger, 13 years ago

The feature is implemented here: https://github.com/gregmuellegger/django/tree/t17604-assertTemplateUsed
The compare view: https://github.com/gregmuellegger/django/compare/master...t17604-assertTemplateUsed

Would be good if anyone could in particular review the docs, since my english is not the best at the moment.

by Gregor Müllegger, 13 years ago

comment:2 by Gregor Müllegger, 13 years ago

Has patch: set

comment:3 by Mikhail Korobov, 13 years ago

Cc: kmike84@… added

comment:4 by Julien Phalip, 13 years ago

Triage Stage: UnreviewedAccepted

by Gregor Müllegger, 13 years ago

merged with trunk

comment:5 by Carl Meyer, 13 years ago

Patch needs improvement: set

I'm seeing three errors and one failure in the tests with the latest patch: http://paste.pocoo.org/show/543635/

comment:6 by Gregor Müllegger, 13 years ago

Patch needs improvement: unset

Did you applied the patch with "patch -p1 < t17604-assertTemplateUsed.2.diff"? I tried so and had the same problem, since it doesn't create the two empty files:

tests/regressiontests/test_utils/templates/template_used/base.html
tests/regressiontests/test_utils/templates/template_used/alternative.html

Use git apply t17604-assertTemplateUsed.2.diff instead or create those empty files by hand.
Sorry, I don't know how to make the patch work otherwise :-(

comment:7 by Carl Meyer, 13 years ago

Resolution: fixed
Status: newclosed

In [17412]:

Fixed #17604 - Added context-manager capability to assertTemplateUsed and assertTemplateNotUsed. Thanks Greg Müllegger.

comment:8 by Carl Meyer, 13 years ago

Oops, my bad :-) Thanks for the pointer on getting the patch applied properly.

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