Spaces:
Sleeping
Sleeping
Commit ·
bb76786
1
Parent(s): 30aec8b
First unit test and view function
Browse files- lists/tests.py +10 -3
- lists/views.py +3 -2
lists/tests.py
CHANGED
|
@@ -1,6 +1,13 @@
|
|
| 1 |
from django.test import TestCase
|
|
|
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
-
class
|
| 5 |
-
def
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from django.test import TestCase
|
| 2 |
+
from django.http import HttpRequest
|
| 3 |
+
from lists.views import home_page
|
| 4 |
|
| 5 |
|
| 6 |
+
class HomePageTest(TestCase):
|
| 7 |
+
def test_home_page_returns_correct_html(self):
|
| 8 |
+
request = HttpRequest()
|
| 9 |
+
response = home_page(request)
|
| 10 |
+
html = response.content.decode("utf8")
|
| 11 |
+
self.assertIn("<title>To-Do lists</title>", html)
|
| 12 |
+
self.assertTrue(html.startswith("<html>"))
|
| 13 |
+
self.assertTrue(html.endswith("</html>"))
|
lists/views.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
-
from django.
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
| 1 |
+
from django.http import HttpResponse
|
| 2 |
|
| 3 |
+
def home_page(request):
|
| 4 |
+
return HttpResponse("<html><title>To-Do lists</title></html>")
|