[Django]-Django test the correct template used: with self.assertTemplateUsed()

5πŸ‘

βœ…

It is always a good idea to test status_code even with views rendering templates.

Django gives you ability to pass status code of your wish while rendering templates.

Both render() and render_to_response take status as keyword argument so that you can render the page with a status code you think is appropriate for the view.

Thus, you can render templates with any response status code not just 200. This gives you a reason to test status code while using assertTemplateUsed as a context manager.

2πŸ‘

It’s not redundant if you app might send different responses status using the same template. In general cases, using the assertTemplateUsed it’s just fine.

Leave a comment