2020-10-15 17:43:46 +11:00
|
|
|
from django.test import TestCase
|
2020-11-06 12:32:21 +11:00
|
|
|
from django.urls import resolve
|
2020-11-07 15:23:42 +11:00
|
|
|
from django.http import HttpRequest
|
|
|
|
|
2020-11-06 12:32:21 +11:00
|
|
|
from lists.views import home_page
|
2020-10-15 17:43:46 +11:00
|
|
|
|
2020-11-06 12:32:21 +11:00
|
|
|
class HomePageTest(TestCase):
|
2020-10-15 17:47:38 +11:00
|
|
|
|
2020-11-06 12:32:21 +11:00
|
|
|
def test_root_url_resolves_to_home_page_view(self):
|
|
|
|
found = resolve('/')
|
2020-11-07 15:23:42 +11:00
|
|
|
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 15:23:42 +11:00
|
|
|
"""
|
|
|
|
|
2020-11-07 21:05:22 +11:00
|
|
|
response = self.client.get('/') #1
|
|
|
|
self.assertTemplateUsed(response, 'home.html') #3
|