Fakultas Ilmu Komputer UI

Commit fb4be1c0 authored by Rayza Arasj Mahardhika's avatar Rayza Arasj Mahardhika
Browse files

Exercise/personal commentary

parent cd4c7d2f
......@@ -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
......
......@@ -14,5 +14,7 @@
<tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr>
{% endfor %}
</table>
<p>{{ commentary }}</p>
</body>
</html>
......@@ -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):
......
......@@ -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(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment