[Django]-How to test "render to template" functions in django? (TDD)

49👍

One could test the following:

  1. Response code
  2. Template used
  3. Template contains some specific text

The code would look something like this:

    from django.test import Client, TestCase
    from django.urls import reverse
    
    class TestPage(TestCase):
    
       def setUp(self):
           self.client = Client()
    
       def test_index_page(self):
           url = reverse('index')
           response = self.client.get(url)
           self.assertEqual(response.status_code, 200)
           self.assertTemplateUsed(response, 'index.html')
           self.assertContains(response, 'Company Name XYZ')
👤super9

Leave a comment