From 326bde9db75c36ea2621002115bc449abcbd5bd1 Mon Sep 17 00:00:00 2001
From: Rayza Arasj Mahardhika <rayza.arasj@ui.ac.id>
Date: Wed, 25 Sep 2019 22:48:25 +0700
Subject: [PATCH 1/5] add unit test for personal commentary

---
 lists/tests.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lists/tests.py b/lists/tests.py
index 07e1265..d46b2fd 100644
--- a/lists/tests.py
+++ b/lists/tests.py
@@ -41,6 +41,19 @@ class HomePageTest(TestCase):
         self.assertIn('itemey 1', response.content.decode())
         self.assertIn('itemey 2', response.content.decode())
 
+    def test_display_correct_personal_commentary(self):
+        cases = [
+            (0, 'yey, waktunya berlibur'),
+            (4, 'sibuk tapi santai'),
+            (5, 'oh tidak')
+        ]
+
+        for item_count, commentary in cases:
+            for i in range(item_count):
+                Item.objects.create(text='itemey {}'.format(i))
+            response = self.client.get('/')
+            self.assertIn(commentary, response.content.decode())
+
 class AboutPageTest(TestCase):
 
     def test_about_url_resolves_to_about_page_view(self):
-- 
GitLab


From bf4599946e0ce3f772f2b29daae42f72229918ce Mon Sep 17 00:00:00 2001
From: Rayza Arasj Mahardhika <rayza.arasj@ui.ac.id>
Date: Wed, 25 Sep 2019 23:01:18 +0700
Subject: [PATCH 2/5] implement personal commentary

---
 lists/templates/home.html |  2 ++
 lists/views.py            | 10 +++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lists/templates/home.html b/lists/templates/home.html
index d350608..f947610 100644
--- a/lists/templates/home.html
+++ b/lists/templates/home.html
@@ -14,5 +14,7 @@
         <tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr>
       {% endfor %}
     </table>
+
+    <p>{{ commentary }}</p>
   </body>
 </html>
diff --git a/lists/views.py b/lists/views.py
index e3e0ebb..00f469b 100644
--- a/lists/views.py
+++ b/lists/views.py
@@ -3,13 +3,21 @@ from django.shortcuts import redirect, render
 
 from lists.models import Item
 
+def get_commentary(item_count):
+    if (item_count == 0):
+        return 'yey, waktunya berlibur'
+    elif (item_count < 5):
+        return 'sibuk tapi santai'
+    elif (item_count >= 5):
+        return 'oh tidak'
+
 def home_page(request):
     if request.method == 'POST':
         Item.objects.create(text=request.POST['item_text'])
         return redirect('/')
 
     items = Item.objects.all()
-    return render(request, 'home.html', {'items': items})
+    return render(request, 'home.html', {'items': items, 'commentary': get_commentary(len(items))})
 
 def about_page(request):
     return HttpResponse(
-- 
GitLab


From cdd9652f832f9803f7a28c83664a9e82c6264728 Mon Sep 17 00:00:00 2001
From: Rayza Arasj Mahardhika <rayza.arasj@ui.ac.id>
Date: Wed, 25 Sep 2019 23:07:35 +0700
Subject: [PATCH 3/5] refactor test to use constants

---
 lists/tests.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lists/tests.py b/lists/tests.py
index d46b2fd..777aa44 100644
--- a/lists/tests.py
+++ b/lists/tests.py
@@ -2,7 +2,8 @@ from django.urls import resolve, reverse
 from django.test import TestCase
 from django.http import HttpRequest
 
-from lists.views import home_page, about_page
+from lists.views import home_page, about_page, \
+    COMMENTARY_ZERO, COMMENTARY_LESS_THAN_FIVE, COMMENTARY_MORE_THAN_EQUAL_FIVE
 from lists.models import Item
 
 class HomePageTest(TestCase):
@@ -43,9 +44,9 @@ class HomePageTest(TestCase):
 
     def test_display_correct_personal_commentary(self):
         cases = [
-            (0, 'yey, waktunya berlibur'),
-            (4, 'sibuk tapi santai'),
-            (5, 'oh tidak')
+            (0, COMMENTARY_ZERO),
+            (4, COMMENTARY_LESS_THAN_FIVE),
+            (5, COMMENTARY_MORE_THAN_EQUAL_FIVE)
         ]
 
         for item_count, commentary in cases:
-- 
GitLab


From 8c4f705f63395f75f620cf5fa20f8c808116be32 Mon Sep 17 00:00:00 2001
From: Rayza Arasj Mahardhika <rayza.arasj@ui.ac.id>
Date: Wed, 25 Sep 2019 23:08:26 +0700
Subject: [PATCH 4/5] refactor implementation to use constants

---
 lists/views.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lists/views.py b/lists/views.py
index 00f469b..e3b10a7 100644
--- a/lists/views.py
+++ b/lists/views.py
@@ -3,13 +3,17 @@ from django.shortcuts import redirect, render
 
 from lists.models import Item
 
+COMMENTARY_ZERO = 'yey, waktunya berlibur'
+COMMENTARY_LESS_THAN_FIVE = 'sibuk tapi santai'
+COMMENTARY_MORE_THAN_EQUAL_FIVE = 'oh tidak'
+
 def get_commentary(item_count):
     if (item_count == 0):
-        return 'yey, waktunya berlibur'
+        return COMMENTARY_ZERO
     elif (item_count < 5):
-        return 'sibuk tapi santai'
+        return COMMENTARY_LESS_THAN_FIVE
     elif (item_count >= 5):
-        return 'oh tidak'
+        return COMMENTARY_MORE_THAN_EQUAL_FIVE
 
 def home_page(request):
     if request.method == 'POST':
-- 
GitLab


From 96ed446265e116d72d76079b61cb9f87717cf0d6 Mon Sep 17 00:00:00 2001
From: Rayza Arasj Mahardhika <rayza.arasj@ui.ac.id>
Date: Wed, 25 Sep 2019 23:25:05 +0700
Subject: [PATCH 5/5] remove gitlab ci for python migrate

---
 .gitlab-ci.yml | 2 --
 1 file changed, 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2d7e1ff..246597c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,8 +11,6 @@ Deployment:
     - dpl --provider=heroku --app=$HEROKU_APPNAME --api-key=$HEROKU_APIKEY
     - export HEROKU_API_KEY=$HEROKU_APIKEY
     - heroku run --app $HEROKU_APPNAME migrate
-    - heroku run bash
-    - ./manage.py migrate
   environment:
     name: production
     url: $HEROKU_APP_HOST
-- 
GitLab