Fakultas Ilmu Komputer UI

Commit 6e580524 authored by Saul Andre's avatar Saul Andre
Browse files

[RED] add urls and templates for detail materi pages

parent c44d8469
{% extends 'base.hmtl' %}
{% extends 'base.html' %}
{% load static %}
{% block header %}
<link rel="stylesheet" type="text/css" href="{% static 'app/css/detail_materi.css' %}">
{% endblock header %}
{% block title %}
Materi
{% endblock title %}
{% block content %}
<h1>babababa</h1>
{% endblock content %}
<h1>bababab</h1>
{% endblock content %}
\ No newline at end of file
from django.test import TestCase, Client
from django.urls import resolve
from .views import DaftarKatalog, listMateri
from .models import Materi
from .models import Materi, Category
from django.core import serializers
import json
......@@ -38,9 +38,14 @@ class DaftarKatalogTest(TestCase):
def test_fungsi_get(self):
self.materi = Materi()
categoryTest = Category.objects.create(name="medis", description="Kategory medis")
self.materi.title = 'Wahyu'
self.materi.cover = 'https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg'
self.materi.author = 'Saul Andre Lumban Gaol'
self.materi.uploader = 'Bayu'
self.materi.publisher = 'Diskominfo Depok'
self.materi.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."
self.materi.categories = categoryTest
self.materi.save()
client = Client()
......@@ -53,7 +58,7 @@ class DaftarKatalogTest(TestCase):
"uploader": "Bayu",
"publisher": "Diskominfo Depok",
"description": "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.",
"category": "#medis"}})
"category": categoryTest}})
unexpected_output = json.dumps({"pk": self.materi.pk, "model": "app.materi",
"fields": {"cover": "",
"title": "",
......@@ -67,7 +72,7 @@ class DaftarKatalogTest(TestCase):
class DetailMateriTest(TestCase):
def test_detail_materi_url_exist(self):
url = "/detail-materi"
url = "/materi/"
response = Client().get(f'{url}')
self.assertEqual(response.status_code,200)
self.assertNotEqual(response.status_code, 404)
......@@ -80,7 +85,7 @@ class DetailMateriTest(TestCase):
found = resolve('/')
self.assertEqual(found.func.__name__, detail_materi.as_view().__name__)
def test_kategori_models_can_create_new_object(self):
def test_category_models_can_create_new_object(self):
test = Category.objects.create(id="1", name="medis", desc="kategori medis")
countData = Category.objects.all().count()
self.assertEqual(1, countData)
......
......@@ -2,10 +2,9 @@ from django.urls import path, re_path
from app import views
urlpatterns = [
# Matches any html file
path("", views.DaftarKatalog.as_view(), name='daftar_katalog'),
# path("detail-materi/", views.DetailMateri.as_view(), name='detail_materi'),
path('materi/', 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'),
path('list-materi/', views.listMateri, name='listMateri'),
]
\ No newline at end of file
......@@ -15,6 +15,17 @@ class DaftarKatalog(TemplateView):
context = self.get_context_data(**kwargs)
context["materi_list"] = Materi.objects.all()
return self.render_to_response(context=context)
class DetailMateri(TemplateView):
template_name = "app/detail_materi.html"
def get_context_data(self, **kwargs):
return super().get_context_data(**kwargs)
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
context["materi_list"] = Materi.objects.all()
return self.render_to_response(context=context)
def listMateri(self):
queries = Materi.objects.all()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment