From fd8d7bd05d572c3088ed8edf6b83c83c69da6f7e Mon Sep 17 00:00:00 2001
From: Ahmad Fauzan Amirul Isnain <ahmad.fauzan71@ui.ac.id>
Date: Fri, 9 Oct 2020 10:02:56 +0700
Subject: [PATCH] [#117] Bugfix: Error On Detail Materi Page

---
 app/tests.py | 40 +++++++++++++++++++++++++++++++++-------
 app/views.py |  2 +-
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/app/tests.py b/app/tests.py
index 2b65c52..b29a6b6 100644
--- a/app/tests.py
+++ b/app/tests.py
@@ -35,6 +35,11 @@ from .views import (DaftarKatalog, DashboardKontributorView, DetailMateri,
 from app.forms import SuntingProfilForm
 from app.utils.fileManagementUtil import get_random_filename, remove_image_exifdata
 
+from datetime import datetime
+
+import pandas as pd
+
+
 class DaftarKatalogTest(TestCase):
     def test_daftar_katalog_url_exist(self):
         url = "/"
@@ -146,6 +151,16 @@ class DetailMateriTest(TestCase):
         self.materi1 = Materi.objects.first()
         self.url = "/materi/" + str(self.materi1.id) + "/"
 
+        self.materi_with_published_date = Materi.objects.create(title="Materi 1", author="Agas", uploader=self.contributor,
+                                                 publisher="Kelas SC", descriptions="Deskripsi Materi 1",
+                                                 status="APPROVE", cover=self.cover, content=self.content,
+                                                 date_modified=datetime.now(), date_created=datetime.now())
+        self.materi_with_published_date_url = "/materi/" + str(self.materi_with_published_date.id) + "/"
+        VerificationReport.objects.create(report='{"feedback": "Something", "kriteria": [{"title": "Kriteria 1", "status": true},' + \
+            ' {"title": "Kriteria 2", "status": true}, {"title": "Kriteria 3", "status": true}]}', \
+            timestamp="2020-10-09 06:21:33", status="Diterima", materi= self.materi_with_published_date, \
+            user=self.materi_with_published_date.uploader)
+
     def test_detail_materi_url_exist(self):
         response = Client().get(self.url)
         self.assertEqual(response.status_code, 200)
@@ -232,17 +247,28 @@ class DetailMateriTest(TestCase):
         response = self.client.get(self.url)
         self.assertContains(response, 'Citate APA')
 
-    def test_hasil_citasi_APA(self):
+    def test_hasil_citasi_APA_materi_has_no_published_date(self):
         response = self.client.get(self.url)
-        publishedDate = ''
-        if(self.materi1.published_date == None):
-            publishedDate = 'n.d'
-        else :
-            publishedDate = self.materi1.published_date
-        expected = self.materi1.author+' . ('  + publishedDate +') . ' + self.materi1.title +' . '+ self.materi1.publisher
+        expected = self.materi1.author + \
+                   ' . (n.d) . ' + \
+                   self.materi1.title + \
+                   ' . ' + \
+                   self.materi1.publisher
         self.assertIn(expected,
                       response.context["citationAPA"])
 
+    def test_hasil_citasi_APA_materi_has_published_date(self):
+        response = self.client.get(self.materi_with_published_date_url)
+        published_date = self.materi_with_published_date.published_date.strftime('%Y-%m-%d %H:%M')
+        expected = self.materi_with_published_date.author + \
+                   ' . ('  + \
+                   published_date + \
+                   ') . ' + \
+                   self.materi_with_published_date.title + \
+                   ' . ' + \
+                   self.materi_with_published_date.publisher
+        self.assertIn(expected,
+                      response.context["citationAPA"])
 
 class PostsViewTest(TestCase):
 
diff --git a/app/views.py b/app/views.py
index d204493..576858c 100644
--- a/app/views.py
+++ b/app/views.py
@@ -126,7 +126,7 @@ class DetailMateri(TemplateView):
         if(materi.published_date == None):
             publishedDate = 'n.d'
         else :
-            publishedDate = materi.published_date
+            publishedDate = materi.published_date.strftime('%Y-%m-%d %H:%M')
         citationAPA = materi.author+' . ('  + publishedDate +') . ' + materi.title +' . '+materi.publisher
         context["citationAPA"] = citationAPA
         context['materi_rating_score'] = 0
-- 
GitLab