From f0cb6b3349a52893544fc4f9f1c9c6e86a7bb2c7 Mon Sep 17 00:00:00 2001 From: Muhammad Indra Ramadhan Date: Thu, 22 Oct 2020 23:28:24 +0700 Subject: [PATCH 1/2] [RED] Add test to get comment count --- app/tests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/tests.py b/app/tests.py index 653a373..357be91 100644 --- a/app/tests.py +++ b/app/tests.py @@ -441,6 +441,20 @@ class DetailMateriTest(TestCase): comment_like_counter = LikeComment.objects.filter(comment=comment, session_id=session_id).count() self.assertEqual(comment_like_counter, 0) + def test_detail_materi_contains_comment_count(self): + url = self.url + self.client.login(**self.contributor_credential) + + response = self.client.get(url) + self.assertContains(response, "Komentar (0)") + + self.client.post( + url, {"comment": "This is new comment by Contributor"}) + self.client.post( + url, {"comment": "This is new comment by Contributor"}) + response = self.client.get(url) + self.assertContains(response, "Komentar (2)") + def test_detail_materi_contains_form_comment(self): self.client.login(**self.contributor_credential) response = self.client.get(self.url) -- GitLab From bec9e6ba4cd6a02adc41c6c1b9ae114f19852ac4 Mon Sep 17 00:00:00 2001 From: Muhammad Indra Ramadhan Date: Thu, 22 Oct 2020 23:44:45 +0700 Subject: [PATCH 2/2] [GREEN] Implement comment count on detail materi --- app/models.py | 5 +++++ app/templates/app/detail_materi.html | 1 + 2 files changed, 6 insertions(+) diff --git a/app/models.py b/app/models.py index a656e06..e9342e0 100644 --- a/app/models.py +++ b/app/models.py @@ -99,6 +99,11 @@ class Materi(models.Model): def like_count(self): count = Like.objects.filter(materi=self).count() return count + + @property + def comment_count(self): + count = Comment.objects.filter(materi=self).count() + return count @property def is_like(self): diff --git a/app/templates/app/detail_materi.html b/app/templates/app/detail_materi.html index 577e65b..8543206 100644 --- a/app/templates/app/detail_materi.html +++ b/app/templates/app/detail_materi.html @@ -268,6 +268,7 @@ {% if materi_data.status == "APPROVE" %}
+

Komentar ({{ materi_data.comment_count }})

{% if is_authenticated %}
-- GitLab