diff --git a/app/tests.py b/app/tests.py index d0b6f0ef833b07f2eff9ed16ac9d7b6592c07b2a..e973b8d8cfcd66a54dae88157b7beed3aae2fa47 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 9aed71efa3076504fe0177ddffb72613a5bc716d..9ab5cf58f420b8eb6c48fabe8335f98410031b39 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 1bd033f90f452aba0003e843299676ccf1bceee7..907747ef7de749ba97d14c8789a378ca79cde2bc 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):