Fakultas Ilmu Komputer UI

Commit ee2fa26e authored by Mika dabelza abi's avatar Mika dabelza abi Committed by I Gusti Putu Agastya Indrayana
Browse files

Revert "[RED] Added tests for Halaman-Katalog"

This reverts commit 4cf6bbca.

[GREEN] Revert wrong commit in the wrong branch
parent 2f01d8e8
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{"name":"Python: Django test","type":"python","request":"launch","program":"${workspaceFolder}\\manage.py","args":["test"],"django":true},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"runserver",
"--noreload"
],
"django": true
}
]
}
\ No newline at end of file
# Generated by Django 3.0.3 on 2020-04-08 12:29
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Materi',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('cover', models.URLField()),
('title', models.CharField(max_length=50)),
('author', models.CharField(max_length=30)),
],
),
]
# Generated by Django 3.0.3 on 2020-04-08 14:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='materi',
name='cover',
field=models.URLField(max_length=1000),
),
]
from django.db import models
# Create your models here.
class Materi(models.Model):
cover = models.URLField(max_length=1000)
title = models.CharField(max_length=50)
author = models.CharField(max_length=30)
\ No newline at end of file
/* .main-header {
background: #FFFFFF;
width: 100%;
position: fixed;
z-index: 1;
padding: 8px 16px;
box-shadow: 2px 2px 2px 2px rgb(0,0,0,0.5)
}
.main-header > div {
display: inline-block;
vertical-align: middle;
}
.main-header__brand {
color: #364F6B;
text-decoration: none;
font-size: 20px;
}
.main-nav {
display: inline-block;
text-align: right;
width: calc(100% - 229px);
vertical-align: middle;
}
.main-nav__items {
margin: 0;
padding: 0;
list-style: none;
}
.main-nav__item {
display: inline-block;
margin: 0 16px;
}
.main-nav__item a {
color: #364F6B;
text-decoration: none;
padding: 3px 0;
}
.main-nav__item-img {
width: 35px;
height: 35px;
vertical-align: middle;
}
@media screen and (max-width: 600px) {
.main-header {
position: relative;
text-align: center;
}
.main-header__brand {
font-size: 1.7rem;
}
.main-nav {
display: block;
text-align: center;
width: 100%;
}
.main-nav__item {
margin: 0;
display: block;
}
.main-nav__item a {
font-size: 1.4rem;
}
.main-nav__item-img {
width: 50px;
height: 50px;
vertical-align: middle;
}
} */
.header {
display: flex;
flex-direction: column;
}
.pageTitle {
color: #5B84B1;
margin: 5px;
}
.description{
color: #5B84B1;
margin: 5px;
}
.searchBar{
margin: 5px;
padding: 0;
display: flex;
}
.searchBar .form-group {
margin: 0px 10px 0px 0px;
padding: 0;
}
.searchBar .btn-cari {
width: 75px;
padding: 0;
border-radius: 2px;
background-color: #ffffff;
color: #5B84B1;
border: none;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
.searchBar .btn:hover{
color: #ffffff;
background-color: #5B84B1;
}
.content {
display: flex;
margin: 5px;
}
.content .sidebar {
padding: 5px 5px 5px 0;
}
.content .sidebar .accordion {
border-radius: 2px;
}
.content .sidebar .accordion .card {
border-radius: 0;
background-color: #ffffff;
}
.content .sidebar .accordion .card .card-header {
padding: 0;
background-color: #5B84B1;
}
.content .sidebar .accordion .card .card-header .btn {
width: 100%;
text-align: left;
color: #ffffff;
border: none;
}
.content .sidebar .accordion .card .card-header .btn:focus{
box-shadow: none;
}
.content .books {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.content .books .book {
display: flex;
margin: 10px;
width: 15rem;
padding: 5px;
border: 1px solid #d4d4d4;
border-radius: 2px;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
.content .books .book .card-body {
padding: 5px;
}
.card-title {
margin-bottom: 5px;
}
.card-text {
margin-bottom: 5px;
}
.btn-book {
width: 75px;
margin-right: 5px;
border-radius: 2px;
background-color: #ffffff;
color: #5B84B1;
border: none;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
.card-body .btn:hover{
color: #ffffff;
background-color: #5B84B1;
}
\ No newline at end of file
books: [
{
cover : 'https://scontent.fbdo6-2.fna.fbcdn.net/v/t1.0-9/60274038_2279638138757984_7988420823012605952_n.jpg?_nc_cat=108&_nc_sid=110474&_nc_oc=AQlRDnDhg1kJjuoXEwYCYWosatAaFqwSiZdMmfbX_ORoTXu7cvJoawUihJPCjHXCqr0&_nc_ht=scontent.fbdo6-2.fna&oh=169b2c36df1a49f6a394208f21d09f7b&oe=5E94FF4E',
title : 'Wahyu',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://scontent.fbdo6-2.fna.fbcdn.net/v/t1.0-9/60274038_2279638138757984_7988420823012605952_n.jpg?_nc_cat=108&_nc_sid=110474&_nc_oc=AQlRDnDhg1kJjuoXEwYCYWosatAaFqwSiZdMmfbX_ORoTXu7cvJoawUihJPCjHXCqr0&_nc_ht=scontent.fbdo6-2.fna&oh=169b2c36df1a49f6a394208f21d09f7b&oe=5E94FF4E',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://static.billboard.com/files/styles/900_wide/public/media/Billie-Eilish-bb12-2019-feat-billboard-strgoia-1240.jpg',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQ8Tc7B5K5dRrho7kzd4LyR7g9s2VKfM2CaTQ3U-PGk-ZhKDu7v',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://media.vanityfair.com/photos/5e2f059bff31f500098c2f0b/2:3/w_887,h_1331,c_limit/Billie-Eilish-Grammys-Curse.jpg',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://nyppagesix.files.wordpress.com/2019/08/billie-eilish-2.jpg?quality=80&strip=all&strip=all',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://www.herworld.co.id/gallery/teaser/Koleksi-XXL-Bershka-x-Billie-Eilish_41_20190917155600.jpg',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://www.herworld.co.id/gallery/teaser/Koleksi-XXL-Bershka-x-Billie-Eilish_41_20190917155600.jpg',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
{
cover : 'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTChEUT2HuZF0a0-Qz_nwQI65zQv8efU4J-bUkjalVLb0Y2TFxh',
title : 'Billie Eilish Fans Starter Pack',
author : 'Saul Andre Lumban Gaol',
},
]
\ No newline at end of file
{% extends 'base.hmtl' %}
{% block content %}
<h1>babababa</h1>
{% endblock content %}
{% extends "base.html" %}
{% load static %}
{% block title %}Digipus Home{% endblock %}
{% block header %}
<link rel="stylesheet" type="text/css" href="{% static 'app/css/katalog_materi.css' %}">
{% endblock header %}
{% block content %}
<div class="container">
<div class="row header">
<div class="col">
<h2 class="pageTitle">Temukan Materi Yang Kamu Mau!</h2>
<p class="description">Cari dengan judul buku, penerbit, atau penulis</p>
<form class="searchBar">
<div class="col-6 form-group">
<input type="email" class="form-control" placeholder="Tulis di sini">
</div>
<button type="submit" class="btn btn-cari">Cari</button>
</form>
</div>
</div>
<div class="row content">
<div class="col-3 sidebar">
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button class="btn collapsed"
type="button"
data-toggle="collapse"
data-target="#collapseOne"
aria-expanded="true"
aria-controls="collapseOne">
Filter
</button>
</h2>
</div>
<div id="collapseOne"
class="collapse"
aria-labelledby="headingOne"
data-parent="#accordionExample">
<div class="card-body">
<p>Kategory test1</p>
<p>Kategory test1</p>
<p>Kategory test1</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h2 class="mb-0">
<button class="btn collapsed" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Sort
</button>
</h2>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body">
<p>Sort test1</p>
<p>Sort test1</p>
<p>Sort test1</p>
</div>
</div>
</div>
</div>
</div>
<div class="col-9 books">
{% for item in materi_list %}
<div class="card book">
<img src={{item.cover}}
class="card-img-top" alt="cover"></img>
<div class="card-body">
<h5 class="card-title">{{item.title}}</h5>
<p class="card-text">{{item.author}}</p>
<button class="btn btn-book">Baca</button>
<button class="btn btn-book">Detail</button>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
{% endblock %}
from django.test import TestCase, Client
from django.urls import resolve
from .views import DaftarKatalog, listMateri
from .models import Materi
from django.core import serializers
import json
class DaftarKatalogTest(TestCase):
def test_daftar_katalog_url_exist(self):
url = "/"
response = Client().get(f'{url}')
self.assertEqual(response.status_code,200)
def test_daftar_katalog_using_daftar_katalog_template(self):
response = Client().get('/')
self.assertTemplateUsed(response, 'app/katalog_materi.html')
def test_daftar_katalog_using_daftar_katalog_func(self):
found = resolve('/')
self.assertEqual(found.func.__name__, DaftarKatalog.as_view().__name__)
def test_fields(self):
materi = Materi()
materi.title = 'tes'
materi.cover = 'https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg'
materi.author = 'input'
materi.save()
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):
self.materi = Materi()
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.save()
client = Client()
queryset = client.get('/list-materi/')
expected_output = json.dumps({"pk": self.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"}})
self.assertJSONEqual(queryset.json()[1:-1], expected_output)
class TemplateLoaderTest(TestCase):
......
......@@ -2,6 +2,10 @@ 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'),
# 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
from django.shortcuts import render, get_object_or_404, redirect
from django.template import loader
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
from django.views.generic import TemplateView
from django.core import serializers
from .models import Materi
class DaftarKatalog(TemplateView):
template_name = "app/katalog_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()
return JsonResponse(serializers.serialize('json', queries), safe=False)
# 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)
# return self.render_to_response(context=context)
def pages(request):
context = {}
......
......@@ -54,7 +54,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware'
'whitenoise.middleware.WhiteNoiseMiddleware',
]
ROOT_URLCONF = 'digipus.urls'
......
......@@ -5,9 +5,10 @@
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Bootstrap CSS -->
{% block header %}
{% endblock header %}
<title>{% block title %}
{% endblock title %}</title>
......
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