Skip to content

Instantly share code, notes, and snippets.

@themartorana
Created March 2, 2011 17:18
Show Gist options
  • Select an option

  • Save themartorana/851307 to your computer and use it in GitHub Desktop.

Select an option

Save themartorana/851307 to your computer and use it in GitHub Desktop.
Get request.context and request.template support back in TestCase using Jinja2
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