From 22b29033cda5e831f1b64e258b51edf8d7ed6516 Mon Sep 17 00:00:00 2001 From: Rahmania Astrid Mochtar <rahmania.astrid@ui.ac.id> Date: Wed, 18 Sep 2019 22:18:07 +0700 Subject: [PATCH 1/5] Add app for lists, with deliberately failing unit test --- lists/__init__.py | 0 lists/admin.py | 3 +++ lists/apps.py | 5 +++++ lists/migrations/__init__.py | 0 lists/models.py | 3 +++ lists/tests.py | 8 ++++++++ lists/views.py | 3 +++ 7 files changed, 22 insertions(+) create mode 100644 lists/__init__.py create mode 100644 lists/admin.py create mode 100644 lists/apps.py create mode 100644 lists/migrations/__init__.py create mode 100644 lists/models.py create mode 100644 lists/tests.py create mode 100644 lists/views.py diff --git a/lists/__init__.py b/lists/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lists/admin.py b/lists/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/lists/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/lists/apps.py b/lists/apps.py new file mode 100644 index 0000000..efe43f0 --- /dev/null +++ b/lists/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ListsConfig(AppConfig): + name = 'lists' diff --git a/lists/migrations/__init__.py b/lists/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lists/models.py b/lists/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/lists/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/lists/tests.py b/lists/tests.py new file mode 100644 index 0000000..1776735 --- /dev/null +++ b/lists/tests.py @@ -0,0 +1,8 @@ +from django.test import TestCase + +# Create your tests here. + + +class SmokeTest(TestCase): + def test_bad_maths(self): + self.assertEqual(1 + 1, 3) diff --git a/lists/views.py b/lists/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/lists/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. -- GitLab From 446ace545c9296acb48cf1bddbc91950f4da25c9 Mon Sep 17 00:00:00 2001 From: Rahmania Astrid Mochtar <rahmania.astrid@ui.ac.id> Date: Wed, 18 Sep 2019 22:43:12 +0700 Subject: [PATCH 2/5] First unit test and url mapping, dummy view --- lists/tests.py | 11 ++++++----- lists/views.py | 4 ++++ superlists/urls.py | 6 ++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lists/tests.py b/lists/tests.py index 1776735..2903fa1 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -1,8 +1,9 @@ +from django.urls import resolve from django.test import TestCase +from lists.views import home_page -# Create your tests here. - -class SmokeTest(TestCase): - def test_bad_maths(self): - self.assertEqual(1 + 1, 3) +class HomePageTest(TestCase): + def test_root_url_resolves_to_home_page_view(self): + found = resolve('/') + self.assertEqual(found.func, home_page) diff --git a/lists/views.py b/lists/views.py index 91ea44a..15818ef 100644 --- a/lists/views.py +++ b/lists/views.py @@ -1,3 +1,7 @@ from django.shortcuts import render # Create your views here. + + +def home_page(): + pass diff --git a/superlists/urls.py b/superlists/urls.py index 68b1358..1bc7236 100644 --- a/superlists/urls.py +++ b/superlists/urls.py @@ -14,8 +14,10 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.conf.urls import url +from lists import views urlpatterns = [ - path('admin/', admin.site.urls), + url(r'^admin/', admin.site.urls), + url(r'^$', views.home_page, name='home') ] -- GitLab From 017046b99e78662290d69b3efb101129be56daab Mon Sep 17 00:00:00 2001 From: Rahmania Astrid Mochtar <rahmania.astrid@ui.ac.id> Date: Wed, 18 Sep 2019 22:54:24 +0700 Subject: [PATCH 3/5] Basic view now returns minimal HTML --- lists/tests.py | 9 +++++++++ lists/views.py | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lists/tests.py b/lists/tests.py index 2903fa1..661a005 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -1,5 +1,7 @@ from django.urls import resolve from django.test import TestCase +from django.http import HttpRequest + from lists.views import home_page @@ -7,3 +9,10 @@ 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): + request = HttpRequest() + response = home_page(request) + self.assertTrue(response.content.startswith(b'<html>')) + self.assertIn(b'<title>To-Do lists</title>', response.content) + self.assertTrue(response.content.endswith(b'</html>')) diff --git a/lists/views.py b/lists/views.py index 15818ef..77f4666 100644 --- a/lists/views.py +++ b/lists/views.py @@ -1,7 +1,8 @@ from django.shortcuts import render +from django.http import HttpResponse # Create your views here. -def home_page(): - pass +def home_page(request): + return HttpResponse('<html><title>To-Do lists</title></html>') -- GitLab From 0020287000659aab88abf6b4baa8a884f55b47f6 Mon Sep 17 00:00:00 2001 From: Rahmania Astrid Mochtar <rahmania.astrid@ui.ac.id> Date: Wed, 18 Sep 2019 23:05:32 +0700 Subject: [PATCH 4/5] Simulated failed automated test --- lists/tests.py | 4 ++++ lists/views.py | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lists/tests.py b/lists/tests.py index 661a005..9d39dd1 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -15,4 +15,8 @@ class HomePageTest(TestCase): response = home_page(request) self.assertTrue(response.content.startswith(b'<html>')) self.assertIn(b'<title>To-Do lists</title>', response.content) + self.assertIn(b'<body></body>', response.content) + self.assertIn(b'<h1>Rahmania Astrid Mochtar</h1>', response.content) + self.assertIn(b'<h4>1606828702</h4>', response.content) + self.assertIn(b'<h4>PMPL - B</h4>', response.content) self.assertTrue(response.content.endswith(b'</html>')) diff --git a/lists/views.py b/lists/views.py index 77f4666..f908686 100644 --- a/lists/views.py +++ b/lists/views.py @@ -5,4 +5,11 @@ from django.http import HttpResponse def home_page(request): - return HttpResponse('<html><title>To-Do lists</title></html>') + return HttpResponse('<html> \ + <title>To-Do lists</title> \ + <body> \ + <h1>Rahmania Astrid Mochtar</h1> \ + <h4>1606828702</h4> \ + <h4>PMPL - B</h4> \ + </body> \ + </html>') -- GitLab From d8a0a4ffc7fda28193e7056c0a06d5dbccddeec1 Mon Sep 17 00:00:00 2001 From: Rahmania Astrid Mochtar <rahmania.astrid@ui.ac.id> Date: Wed, 18 Sep 2019 23:06:20 +0700 Subject: [PATCH 5/5] Succeeded in passing tests --- lists/tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lists/tests.py b/lists/tests.py index 9d39dd1..4db1a63 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -15,7 +15,8 @@ class HomePageTest(TestCase): response = home_page(request) self.assertTrue(response.content.startswith(b'<html>')) self.assertIn(b'<title>To-Do lists</title>', response.content) - self.assertIn(b'<body></body>', response.content) + self.assertIn(b'<body>', response.content) + self.assertIn(b'</body>', response.content) self.assertIn(b'<h1>Rahmania Astrid Mochtar</h1>', response.content) self.assertIn(b'<h4>1606828702</h4>', response.content) self.assertIn(b'<h4>PMPL - B</h4>', response.content) -- GitLab