From c26baf1f2f5fb1e9ebf5fe4e3d17280787c5a95a Mon Sep 17 00:00:00 2001
From: Saul Andre <saulandreee@gmail.com>
Date: Wed, 22 Apr 2020 23:38:38 +0700
Subject: [PATCH] [GREEN] remove get function to get JSONResponse

---
 app/tests.py | 73 ++++++++++++++--------------------------------------
 app/urls.py  |  1 -
 app/views.py |  4 ---
 3 files changed, 20 insertions(+), 58 deletions(-)

diff --git a/app/tests.py b/app/tests.py
index d0b6f0e..e973b8d 100644
--- a/app/tests.py
+++ b/app/tests.py
@@ -1,6 +1,6 @@
 from django.test import TestCase, Client
 from django.urls import resolve
-from .views import DaftarKatalog, listMateri, DetailMateri
+from .views import DaftarKatalog, DetailMateri
 from .models import Materi, Category, Comment
 from django.core import serializers
 import json
@@ -30,67 +30,34 @@ class DaftarKatalogTest(TestCase):
         resp = Materi.objects.get(id = materi.id)
         self.assertEqual(resp,materi)
     
-    
-    def test_resolution(self):
-        resolver = resolve('/list-materi/')
-        self.assertEqual(resolver.func, listMateri)
-
-
-    def test_fungsi_get(self):
-        materi = Materi.objects.create(id=1, title="wahyu",
-                                        cover='https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg',
-                                        author='Saul Andre Lumban Gaol',
-                                        uploader= "Bayu",
-                                        publisher='Diskominfo Depok',
-                                        descriptions="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
-                                        )
-        materi.save()
-        objectsCategory = Category.objects.create(name="medis", description="Kategory medis")
-        objectsComment = Comment.objects.create(user="saul", profile="ffffff", comment="inicoments")
-        categoryQueryToJson = serializers.serialize('json', Category.objects.all())
-        commentQueryToJson = serializers.serialize('json', Comment.objects.all())
-        materi.categories.add(objectsCategory)
-        materi.comments.add(objectsComment)
-        client = Client()
-
-        print(serializers.serialize('json', Materi.objects.all()))
-        
-        queryset = client.get('/list-materi/')
-        
-        expected_output = json.dumps({"pk": materi.pk, "model": "app.materi", 
-                                    "fields": {"cover": "https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg", 
-                                    "title": "Wahyu", 
-                                    "author": "Saul Andre Lumban Gaol",
-                                    "uploader": "Bayu",
-                                    "publisher": "Diskominfo Depok",
-                                    "descriptions": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
-                                    "categories": [1],
-                                    "comments": [1]}})
-        unexpected_output = json.dumps({"pk": materi.pk, "model": "app.materi", 
-                                    "fields": {"cover": "", 
-                                    "title": "", 
-                                    "author": "",
-                                    "uploader": "",
-                                    "publisher": "",
-                                    "descriptions": "",
-                                    "categories": [],
-                                    "comments": []}})
-        self.assertJSONEqual(queryset.json()[1:-1], expected_output)
-        self.assertJSONNotEqual(queryset.json()[1:-1], unexpected_output)
-
 class DetailMateriTest(TestCase):
     def test_detail_materi_url_exist(self):
-        url = "/materi/"
-        response = Client().get(f'{url}')
+        materi = Materi.objects.create(title="wahyu",
+                                cover='https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg',
+                                author='Saul Andre Lumban Gaol',
+                                uploader= "Bayu",
+                                publisher='Diskominfo Depok',
+                                descriptions="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
+                                )
+        url = "/materi/" + str(materi.id) + "/"
+        response = Client().get(url)
         self.assertEqual(response.status_code,200)
         self.assertNotEqual(response.status_code, 404)
 
     def test_detail_materi_using_detail_materi_template(self):
-        response = Client().get('/materi/')
+        materi = Materi.objects.create(title="wahyu",
+                                cover='https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg',
+                                author='Saul Andre Lumban Gaol',
+                                uploader= "Bayu",
+                                publisher='Diskominfo Depok',
+                                descriptions="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
+                                )
+        url = "/materi/" + str(materi.id) + "/"
+        response = Client().get(url)
         self.assertTemplateUsed(response, 'app/detail_materi.html')
     
     def test_detail_materi_using_detail_materi_func(self):
-        found = resolve('/materi/')
+        found = resolve('/materi/1/')
         self.assertEqual(found.func.__name__, DetailMateri.as_view().__name__)
 
     def test_category_models_can_create_new_object(self):
diff --git a/app/urls.py b/app/urls.py
index 9aed71e..9ab5cf5 100644
--- a/app/urls.py
+++ b/app/urls.py
@@ -4,7 +4,6 @@ from app import views
 urlpatterns = [
     path("", views.DaftarKatalog.as_view(), name='daftar_katalog'),
     path('materi/<slug:slug>/', views.DetailMateri.as_view(), name='detailMateri'),
-    path('list-materi/', views.listMateri, name='listMateri'),
     # Matches any html file 
     re_path(r'^.*\.html', views.pages, name='pages'),
 ]
\ No newline at end of file
diff --git a/app/views.py b/app/views.py
index 1bd033f..907747e 100644
--- a/app/views.py
+++ b/app/views.py
@@ -29,10 +29,6 @@ class DetailMateri(TemplateView):
         context["materi_data"] = get_object_or_404(Materi, pk=kwargs['slug'])
         print(context["materi_data"])
         return self.render_to_response(context=context)
-    
-def listMateri(self):
-    queries = Materi.objects.all()
-    return JsonResponse(serializers.serialize('json', queries), safe=False)
 
 
 # class DetailMateri(TemplateView):
-- 
GitLab