Skip to content

Instantly share code, notes, and snippets.

@LouisdeBruijn
Last active April 26, 2020 10:33
Show Gist options
  • Select an option

  • Save LouisdeBruijn/86f29f9a932080d8cf5f34684bfda8d7 to your computer and use it in GitHub Desktop.

Select an option

Save LouisdeBruijn/86f29f9a932080d8cf5f34684bfda8d7 to your computer and use it in GitHub Desktop.
from django.urls import resolve
from django.test import TestCase
from projectname.views import home_page
class HomePageTest(TestCase):
"""Unittesting class for our Django project."""
def test_root_url_resolves_to_home_page_view(self):
"""Test the home page url."""
found = resolve('/')
self.assertEqual(found.func, home_page)
def test_home_page_returns_correct_html(self):
"""Test home_page template."""
response = self.client.get('/')
html = response.content.decode('utf8')
self.assertTrue(html.strip().startswith('<!DOCTYPE HTML>'))
self.assertIn('<html>', html)
self.assertIn('<title>Everything Python</title>', html)
self.assertTrue(html.strip().endswith('</html>'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment