20 lines
782 B
Python
Raw Normal View History

from django.test import TestCase
from django.urls import resolve
from django.http import HttpRequest
from lists.views import home_page
class HomePageTest(TestCase):
def test_root_url_resolves_to_home_page_view(self):
found = resolve('/')
self.assertEqual(found.func, home_page)
def test_home_page_returns_correct_html(self):
"""
2020-11-07 21:05:22 +11:00
1. Instead of manually creating HttpRequest object and calling view function to get response, pass in URL to `self.client.get()` and get response directly
3. `.assertTemplateUsed` is the test method that Django Test Case provides. it checks whether template was used to render a response
"""
2020-11-07 21:05:22 +11:00
response = self.client.get('/') #1
self.assertTemplateUsed(response, 'home.html') #3