diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2d7e1ff391d2d98f1a2d868d6a99c4eecbec015a..246597c2e1ee376c785b5a20da35051f9a61f671 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 diff --git a/lists/templates/home.html b/lists/templates/home.html index d3506085da2a0f6d81d5b0a28fdb5fe2c95c666e..f947610f4ed2645ce1c49f265858b2c34f53053d 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/tests.py b/lists/tests.py index 07e1265325f18882828c0e2af774e13b5a83aeed..777aa440aa610cbada1d3a7f75d31e05ecb62b9b 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): @@ -41,6 +42,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, COMMENTARY_ZERO), + (4, COMMENTARY_LESS_THAN_FIVE), + (5, COMMENTARY_MORE_THAN_EQUAL_FIVE) + ] + + 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): diff --git a/lists/views.py b/lists/views.py index e3e0ebb48b29bc4080dbbdb774b83c99d1decd80..e3b10a7f80b57276161959b4826d7a7829416a75 100644 --- a/lists/views.py +++ b/lists/views.py @@ -3,13 +3,25 @@ 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 COMMENTARY_ZERO + elif (item_count < 5): + return COMMENTARY_LESS_THAN_FIVE + elif (item_count >= 5): + return COMMENTARY_MORE_THAN_EQUAL_FIVE + 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(