Reputation:
I am writing a suite of tests for an app.
In a number of places I use Django's handy "assertTemplateUsed". This works for all templates except, as far as I see for templates loaded via template tags (as inclusion_tag objects).
Is there an alternative way I assert template is used, when it is loaded via a template tag? I can of course check for strings in the template, but check for use of the template would be a better solution.
Upvotes: 5
Views: 541
Reputation: 1846
Try catching the template_rendered
signal, which is available during testing.
From the docs:
django.test.signals.template_rendered
Sent when the test system renders a template. This signal is not emitted during normal operation of a Django server – it is only available during testing.
Arguments sent with this signal:
sender
The Template object which was rendered.
template
Same as sender
context
The Context with which the template was rendered.
Upvotes: 2