Created
March 2, 2011 17:18
-
-
Save themartorana/851307 to your computer and use it in GitHub Desktop.
Get request.context and request.template support back in TestCase using Jinja2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from jinja2 import Template as Jinja2Template | |
| from django.test import signals | |
| #note - this code can be run only once | |
| ORIGINAL_JINJA2_RENDERER = Jinja2Template.render | |
| def instrumented_render(template_object, *args, **kwargs): | |
| context = dict(*args, **kwargs) | |
| signals.template_rendered.send( | |
| sender=template_object, | |
| template=template_object, | |
| context=context | |
| ) | |
| return ORIGINAL_JINJA2_RENDERER(template_object, *args, **kwargs) | |
| Jinja2Template.render = instrumented_render |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment