Fakultas Ilmu Komputer UI

Commit 3e835f1b authored by Saul Andre's avatar Saul Andre
Browse files

[RED] Create new test for category and comments models, and finishing layout

parent 6e580524
No preview for this file type
# Generated by Django 3.0.3 on 2020-04-21 08:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0003_auto_20200418_1452'),
]
operations = [
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('user', models.CharField(default='423a22c748b647d58f725be4ad1ffefb', max_length=100)),
('profile', models.CharField(default='795364', max_length=100)),
('comment', models.CharField(default='comments', max_length=200)),
],
),
migrations.AlterField(
model_name='materi',
name='author',
field=models.CharField(default='author', max_length=30),
),
migrations.AlterField(
model_name='materi',
name='descriptions',
field=models.CharField(default='descriptions', max_length=300),
),
migrations.AlterField(
model_name='materi',
name='publisher',
field=models.CharField(default='publiser', max_length=30),
),
migrations.AlterField(
model_name='materi',
name='title',
field=models.CharField(default='title', max_length=50),
),
migrations.AlterField(
model_name='materi',
name='uploader',
field=models.CharField(default='uploader', max_length=30),
),
migrations.AddField(
model_name='materi',
name='comments',
field=models.ManyToManyField(to='app.Comment'),
),
]
# Generated by Django 3.0.3 on 2020-04-21 09:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0004_auto_20200421_1557'),
]
operations = [
migrations.AlterField(
model_name='comment',
name='profile',
field=models.CharField(default='bdaac0', max_length=100),
),
migrations.AlterField(
model_name='comment',
name='user',
field=models.CharField(default='22daa04c12aa4fc7878d6e3a84eec095', max_length=100),
),
migrations.AlterField(
model_name='materi',
name='descriptions',
field=models.CharField(default='descriptions', max_length=200),
),
]
# Generated by Django 3.0.3 on 2020-04-21 09:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0005_auto_20200421_1625'),
]
operations = [
migrations.AlterField(
model_name='comment',
name='comment',
field=models.CharField(default='comments', max_length=150),
),
migrations.AlterField(
model_name='comment',
name='profile',
field=models.CharField(default='4cee3b', max_length=100),
),
migrations.AlterField(
model_name='comment',
name='user',
field=models.CharField(default='b2ea05df58014e768c7bafda3140e365', max_length=100),
),
migrations.AlterField(
model_name='materi',
name='descriptions',
field=models.TextField(default='descriptions'),
),
]
# Generated by Django 3.0.3 on 2020-04-21 14:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0006_auto_20200421_1633'),
]
operations = [
migrations.AddField(
model_name='materi',
name='verified',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='comment',
name='profile',
field=models.CharField(default='e0ff7f', max_length=100),
),
migrations.AlterField(
model_name='comment',
name='user',
field=models.CharField(default='bd48a042721144bf80b64c2284c39f03', max_length=100),
),
]
from django.db import models
import uuid
import random
# Create your models here.
def getRandomColor():
color = "%06x" % random.randint(0, 0xFFFFFF)
return color
def getRandomUserId():
userId = uuid.uuid4().hex
return userId
class Category(models.Model):
name = models.CharField(max_length=20)
description = models.CharField(max_length=20)
......@@ -8,11 +18,25 @@ class Category(models.Model):
def __str__(self):
return self.name
class Comment(models.Model):
user = models.CharField(max_length = 100, default= getRandomUserId())
profile = models.CharField(max_length = 100, default= getRandomColor())
comment = models.CharField(max_length = 150, default= 'comments')
def __str__(self):
return self.user
class Materi(models.Model):
cover = models.URLField(max_length=1000)
title = models.CharField(max_length=50, default='SOME STRING')
author = models.CharField(max_length=30, default='SOME STRING')
uploader = models.CharField(max_length=30, default='SOME STRING')
publisher = models.CharField(max_length=30, default='SOME STRING')
descriptions = models.CharField(max_length=300, default='SOME STRING')
categories = models.ManyToManyField(Category)
\ No newline at end of file
title = models.CharField(max_length=50, default='title')
author = models.CharField(max_length=30, default='author')
uploader = models.CharField(max_length=30, default='uploader')
publisher = models.CharField(max_length=30, default='publiser')
descriptions = models.TextField(default='descriptions')
verified = models.BooleanField(default=False)
categories = models.ManyToManyField(Category)
comments = models.ManyToManyField(Comment)
......@@ -10,5 +10,139 @@ Materi
{% endblock title %}
{% block content %}
<h1>bababab</h1>
<div class="container">
<div class="row materi-data">
<div class="col col-3 cover">
<img src="https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg" alt="cover">
</div>
<div class="col col-6 offset-md-1 book">
<h2>Billie Eilish Starter Pack</h2>
<p>kategory</p>
<div class="info-wrapper">
<div class="info" id="1">
<dt class="col col-4">
<p class="info-name">Penulis</p>
</dt>
<dd>
<p class="info-content">Saul Andre Lumban Gaol</p>
</dd>
</div>
<div class="info" id="1">
<dt class="col col-4">
<p class="info-name">Penerbit</p>
</dt>
<dd>
<p class="info-content">Gramedia</p>
</dd>
</div>
<div class="info" id="1">
<dt class="col col-4">
<p class="info-name">Jumlah Halaman</p>
</dt>
<dd>
<p class="info-content">62 Halaman</p>
</dd>
</div>
<div class="info" id="1">
<dt class="col col-4">
<p class="info-name">Ukuran File</p>
</dt>
<dd>
<p class="info-content">5 Mb</p>
</dd>
</div>
</div>
<button class="btn btn-link btn-book shadow-sm p-2 mb-1 bg-white rounded">Baca</button>
<button class="btn btn-link btn-book shadow-sm p-2 mb-1 bg-white rounded">Unduh</button>
<button class="btn btn-link btn-book shadow-sm p-2 mb-1 bg-white rounded">Bagikan</button>
</div>
</div>
<div class="row menu-wrapper">
<nav class="navbar navbar-expand-sm">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#section1">Deskripsi</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#section2">Komentar</a>
</li>
</ul>
</nav>
<div id="section1" class="container-fluid description-wrapper">
<h1>Deskripsi</h1>
<div class="col col-8 description">
<p>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.</p>
<p>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.</p>
<p>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.</p>
</div>
</div>
<div id="section2" class="container-fluid comments-wrapper">
<h1>Komentar</h1>
<div class="add-comments col col-8 ">
<form>
<div class="form-group">
<textarea placeholder="komentar..."
class="form-control mb-2"
id="exampleFormControlTextarea1"
rows="3">
</textarea>
<button type="submit" class="btn btn-book shadow-sm p-2 mb-1 bg-white rounded">Confirm identity</button>
</div>
</form>
</div>
<div class="col col-8 comment shadow-sm p-3 mb-1 bg-white rounded">
<div class="user">
<span class="profile"></span>
<p><b>user1</b></p>
</div>
<p class="text">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.</p>
</div>
<div class="col col-8 comment shadow-sm p-3 mb-1 bg-white rounded">
<div class="user">
<span class="profile"></span>
<p><b>user2</b></p>
</div>
<p class="text">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.</p>
</div>
<div class="col col-8 comment shadow-sm p-3 mb-1 bg-white rounded">
<div class="user">
<span class="profile"></span>
<p><b>user3</b></p>
</div>
<p class="text">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.</p>
</div>
<div class="col col-8 comment shadow-sm p-3 mb-1 bg-white rounded">
<div class="user">
<span class="profile"></span>
<p><b>user4</b></p>
</div>
<p class="text">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.</p>
</div>
</div>
<!-- <div class="col col-12">
<nav id="navbar-example2" class="navbar ">
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link" href="#fat">Deskripsi</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#mdo">Komentar</a>
</li>
</ul>
</nav>
</div>
<div class="col col-8 offset-md-1">
<div data-spy="scroll" data-target="#navbar-example2" data-offset="0">
<div class="description-wrapper">
<h4 id="fat">Deskripsi</h4>
<p>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.</p>
<p>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.</p>
<p>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.</p>
</div>
</div>
</div> -->
</div>
</div>
{% 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, Category
from .views import DaftarKatalog, listMateri, DetailMateri
from .models import Materi, Category, Comment
from django.core import serializers
import json
......@@ -37,36 +37,44 @@ 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()
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": self.materi.pk, "model": "app.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",
"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": categoryTest}})
unexpected_output = json.dumps({"pk": self.materi.pk, "model": "app.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.",
"categories": [1],
"comments": [1]}})
unexpected_output = json.dumps({"pk": materi.pk, "model": "app.materi",
"fields": {"cover": "",
"title": "",
"author": "",
"uploader": "",
"publisher": "",
"description": "",
"category": ""}})
"descriptions": "",
"categories": [],
"comments": []}})
self.assertJSONEqual(queryset.json()[1:-1], expected_output)
self.assertJSONNotEqual(queryset.json()[1:-1], unexpected_output)
......@@ -77,22 +85,30 @@ class DetailMateriTest(TestCase):
self.assertEqual(response.status_code,200)
self.assertNotEqual(response.status_code, 404)
def test_detail_materi_using_daftar_katalog_template(self):
response = Client().get('/')
def test_detail_materi_using_detail_materi_template(self):
response = Client().get('/materi/')
self.assertTemplateUsed(response, 'app/detail_materi.html')
def test_detail_materi_using_detail_materi_func(self):
found = resolve('/')
self.assertEqual(found.func.__name__, detail_materi.as_view().__name__)
found = resolve('/materi/')
self.assertEqual(found.func.__name__, DetailMateri.as_view().__name__)
def test_category_models_can_create_new_object(self):
test = Category.objects.create(id="1", name="medis", desc="kategori medis")
test = Category.objects.create(id="1", name="medis", description="kategori medis")
countData = Category.objects.all().count()
self.assertEqual(1, countData)
self.assertNotEqual(0, countData)
self.assertEqual(test.__str__(), "medis")
self.assertNotEqual(test.__str__(), "saul")
def test_comment_models_can_create_new_object(self):
test = Comment.objects.create(user="saul", profile="121212", comment= "232323")
countData = Comment.objects.all().count()
self.assertEqual(1, countData)
self.assertNotEqual(0, countData)
self.assertEqual(test.__str__(), "saul")
self.assertNotEqual(test.__str__(), "userlain")
class TemplateLoaderTest(TestCase):
def test_template_loader_url_exist(self):
url = "/test-page.html"
......
......@@ -260,7 +260,7 @@ iframe {
min-height: 100vh;
display: block;
background-color: #f7f7f7;
padding: 173px 55px 55px 55px;
padding: 100px 55px 55px 55px;
}
.login100-form-title {
......
No preview for this file type
/*//////////////////////////////////////////////////////////////////
[ FONT ]*/
@font-face {
font-family: Poppins-Regular;
src: url("../fonts/poppins/Poppins-Regular.731a28a413d6.ttf");
}
@font-face {
font-family: Poppins-Medium;
src: url("../fonts/poppins/Poppins-Medium.a4e11dda4053.ttf");
}
@font-face {
font-family: Poppins-Bold;
src: url("../fonts/poppins/Poppins-Bold.7940efc40d8e.ttf");
}
@font-face {
font-family: Poppins-SemiBold;
src: url("../fonts/poppins/Poppins-SemiBold.e63b93dfac26.ttf");
}
@font-face {
font-family: Montserrat-Bold;
src: url("../fonts/montserrat/Montserrat-Bold.88932dadc42e.ttf");
}
@font-face {
font-family: Montserrat-SemiBold;
src: url("../fonts/montserrat/Montserrat-SemiBold.c88cecbffad6.ttf");
}
@font-face {
font-family: Montserrat-Regular;
src: url("../fonts/montserrat/Montserrat-Regular.9c4609511838.ttf");
}
/*//////////////////////////////////////////////////////////////////
[ RESTYLE TAG ]*/
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body, html {
height: 100%;
font-family: Poppins-Regular, sans-serif;
}
/*---------------------------------------------*/
a {
font-family: Poppins-Regular;
font-size: 14px;
line-height: 1.7;
color: #666666;
margin: 0px;
transition: all 0.4s;
-webkit-transition: all 0.4s;
-o-transition: all 0.4s;
-moz-transition: all 0.4s;
}
a:focus {
outline: none !important;
}
a:hover {
text-decoration: none;
color: #6675df;
}
/*---------------------------------------------*/
h1,h2,h3,h4,h5,h6 {
margin: 0px;
}
p {
font-family: Poppins-Regular;
font-size: 14px;
line-height: 1.7;
color: #666666;
margin: 0px;
}
ul, li {
margin: 0px;
list-style-type: none;
}
/*---------------------------------------------*/
input {
outline: none;
border: none;
}
textarea {
outline: none;
border: none;
}
textarea:focus, input:focus {
border-color: transparent !important;
}
input:focus::-webkit-input-placeholder { color:transparent; }
input:focus:-moz-placeholder { color:transparent; }
input:focus::-moz-placeholder { color:transparent; }
input:focus:-ms-input-placeholder { color:transparent; }
textarea:focus::-webkit-input-placeholder { color:transparent; }
textarea:focus:-moz-placeholder { color:transparent; }
textarea:focus::-moz-placeholder { color:transparent; }
textarea:focus:-ms-input-placeholder { color:transparent; }
input::-webkit-input-placeholder { color: #999999;}
input:-moz-placeholder { color: #999999;}
input::-moz-placeholder { color: #999999;}
input:-ms-input-placeholder { color: #999999;}
textarea::-webkit-input-placeholder { color: #999999;}
textarea:-moz-placeholder { color: #999999;}
textarea::-moz-placeholder { color: #999999;}
textarea:-ms-input-placeholder { color: #999999;}
label {
display: block;
margin: 0;
}
/*---------------------------------------------*/
button {