diff --git a/lists/templates/home.html b/lists/templates/home.html index e6b05e363e84153190d5a3d0e16e95326dba5b5b..b3c6f4b17c81292d418b3658e6aeca4fb5556190 100644 --- a/lists/templates/home.html +++ b/lists/templates/home.html @@ -1,11 +1,13 @@ To-Do lists +

Jordan M A

+

1506722765

Your To-Do list

- {% csrf_token %} + {% csrf_token %}
@@ -14,5 +16,6 @@ {{ forloop.counter }}: {{ item.text }} {% endfor %} +

{{comment}}

diff --git a/lists/tests.py b/lists/tests.py index 91610b7f18479bf15c0200a421a0253fba71f6f2..38451abc719346607918f0318bab2ee5a9313cb1 100644 --- a/lists/tests.py +++ b/lists/tests.py @@ -17,12 +17,15 @@ class HomePageTest(TestCase): def test_home_page_returns_correct_html(self): request = HttpRequest() # response = home_page(request) # - expected_html = render_to_string('home.html') - self.assertEqual(response.content.decode(), expected_html) + #expected_html = render_to_string('home.html') + #self.assertEqual(response.content.decode(), expected_html) - #self.assertTrue(response.content.startswith(b'')) # - - #self.assertTrue(response.content.strip().endswith(b'')) # + self.assertTrue(response.content.startswith(b'')) # + self.assertIn(b'

Jordan M A

', + response.content) + self.assertIn(b'

1506722765

', + response.content) + self.assertTrue(response.content.strip().endswith(b'')) # def test_home_page_can_save_a_POST_request(self): request = HttpRequest() @@ -56,10 +59,39 @@ class HomePageTest(TestCase): request = HttpRequest() response = home_page(request) - + self.assertIn('itemey 1', response.content.decode()) self.assertIn('itemey 2', response.content.decode()) + def test_home_page_right_comments_when_zero(self): + request = HttpRequest() + response = home_page(request) + self.assertIn(b'

yey, waktunya berlibur

', + response.content) + + def test_home_page_right_comments_when_less_then_five(self): + Item.objects.create(text="itemey 1") + Item.objects.create(text="itemey 2") + Item.objects.create(text="itemey 3") + Item.objects.create(text="itemey 4") + request = HttpRequest() + response = home_page(request) + self.assertIn(b'

sibuk tapi santai

', + response.content) + + def test_home_page_right_comments_when_five_or_more(self): + Item.objects.create(text="itemey 1") + Item.objects.create(text="itemey 2") + Item.objects.create(text="itemey 3") + Item.objects.create(text="itemey 4") + Item.objects.create(text="itemey 5") + + request = HttpRequest() + response = home_page(request) + self.assertIn(b'

oh tidak

', + response.content) + + class ItemModelTest(TestCase): def test_saving_and_retrieving_items(self): first_item = Item() diff --git a/lists/views.py b/lists/views.py index ff3897544a45f44d48de4f4c9d145ecc32ac95aa..c52c1bc9ecbfbd4492cd582c6d966bfee8cb17d0 100644 --- a/lists/views.py +++ b/lists/views.py @@ -3,11 +3,22 @@ from lists.models import Item #def home_page(request): #return HttpResponse('Rumah

Jordan Muhammad Andrianda

1506722765

') - +#{% csrf_token %} def home_page(request): + item = Item() + 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}) - + comment = get_comment(items.count()) + return render(request, 'home.html', {'items': items, 'comment': comment}) + +def get_comment(count): + if count == 0: + comment = "yey, waktunya berlibur" + elif count < 5: + comment = "sibuk tapi santai" + else: + comment = "oh tidak" + return comment diff --git a/readme.md b/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..1d313b40503196f082b7be062bb4a7be2790c831 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +jordan muhammad andrianda +1506722765 +PMPL