diff --git a/src/lists/tests.py b/src/lists/tests.py index 42d2def..e4f737a 100644 --- a/src/lists/tests.py +++ b/src/lists/tests.py @@ -12,16 +12,9 @@ class HomePageTest(TestCase): def test_home_page_returns_correct_html(self): """ - 1. Create an HttpRequest object, which is what Django will see when a user's browser asks for a page - 2. Pass it to `home_page` view, which gives us a response. - 3. Extract `.content` of the response, which are byte value, and should be decoded into string (HTML format) - 4. Check HTML starts and end with tag - 5. Want to find tag in the middle + 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 """ - request = HttpRequest() #1 - response = home_page(request) #2 - html = response.content.decode('utf8') #3 - self.assertTrue(html.startswith('<html>')) #4 - self.assertIn('<title>To-Do lists', html.strip()) #5 - self.assertTrue(html.strip().endswith('')) #4 \ No newline at end of file + response = self.client.get('/') #1 + self.assertTemplateUsed(response, 'home.html') #3 \ No newline at end of file