Since updating from Django 1.7.x to Django 1.8.x, my tests fail when checking for the right template. I'm using a ResearchFactory:
class AdminUnitTest(TestCase):
"""Sets up the testing environment for an admin"""
def setUp(self):
self.factory = RequestFactory()
user = User.objects.create_user(
username="cj123",
email="chuck.jones@acme.edu",
password="xxx",
first_name="Chuck",
last_name="Jones"
)
admin = Staff.objects.create(user=user, role='admin')
self.user = user
The actual test then looks like this:
class YearViewTest(AdminUnitTest):
def test_year_view_uses_right_template(self):
request = self.factory.get('/year_view/all')
request.user = self.user
response = year_view(request, 'all')
self.assertTemplateUsed(response, 'year_view.html')
This approach worked perfectly fine, until the update to 1.8. Since then I get the following error:
ValueError: assertTemplateUsed() and assertTemplateNotUsed() are only usable on responses fetched using the Django test Client.
In Django's source code (http://ift.tt/1M9dfas) I can only find this condition raising the error I get:
if template_name is not None and response is not None and not hasattr(response, 'templates'):
raise ValueError(
"assertTemplateUsed() and assertTemplateNotUsed() are only "
"usable on responses fetched using the Django test Client."
)
I struggle to see where my error there is. Can anyone help me?
Aucun commentaire:
Enregistrer un commentaire