Pārlūkot izejas kodu

Basic View now returns Minimal HTML

david 5 gadi atpakaļ
vecāks
revīzija
ffd1f3d86f
2 mainītis faili ar 16 papildinājumiem un 3 dzēšanām
  1. 13 2
      lists/tests.py
  2. 3 1
      lists/views.py

+ 13 - 2
lists/tests.py

@@ -1,10 +1,21 @@
 from django.urls import resolve
 from django.test import TestCase
+from django.http import HttpRequest
 
 from lists.views import home_page
 
+
 class HomePageTest(TestCase):
 
-    def test_url_resolves_to_home_page(self):
+    def test_root_url_resolves_to_home_page_view(self):
         found = resolve('/')
-        self.assertEqual(found.func, home_page)
+        self.assertEqual(found.func, home_page)
+
+
+    def test_home_page_returns_correct_html(self):
+        request = HttpRequest()
+        response = home_page(request)
+        html = response.content.decode('utf8')
+        self.assertTrue(html.startswith('<html>'))
+        self.assertIn('<title>To-Do lists</title>', html)
+        self.assertTrue(html.endswith('</html>'))

+ 3 - 1
lists/views.py

@@ -1,5 +1,7 @@
 from django.shortcuts import render
+from django.http import HttpResponse
+
 
 # Create your views here.
 def home_page(request):
-    pass
+    return HttpResponse('<html><title>To-Do lists</title></html>')