tests.py 807 B

1234567891011121314151617181920212223242526
  1. from django.urls import resolve
  2. from django.test import TestCase
  3. from django.http import HttpRequest
  4. from django.template.loader import render_to_string
  5. from lists.views import home_page
  6. class HomePageTest(TestCase):
  7. def test_root_url_resolves_to_home_page_view(self):
  8. found = resolve('/')
  9. self.assertEqual(found.func, home_page)
  10. def test_home_page_returns_correct_html(self):
  11. response = self.client.get('/')
  12. # The Manual Way of doing it:
  13. html = response.content.decode('utf8')
  14. self.assertTrue(html.startswith('<html>'))
  15. self.assertIn('<title>To-Do lists</title>', html)
  16. self.assertTrue(html.strip().endswith('</html>'))
  17. # Using Django's Builtin Testing Client:
  18. self.assertTemplateUsed(response, 'home.html')