Fakultas Ilmu Komputer UI

Commit 82c04b0e authored by ilestin.il's avatar ilestin.il
Browse files

[GREEN] make test for unggah materi page

parent 9c5f622e
import json
from django.core import serializers
from django.test import Client, TestCase
from django.test import Client, TestCase, RequestFactory
from django.urls import resolve
from .models import Category, Comment, Materi
from .views import DaftarKatalog, DetailMateri
from app.views import UploadMateriHTML
class DaftarKatalogTest(TestCase):
def test_daftar_katalog_url_exist(self):
......@@ -18,32 +20,6 @@ class DaftarKatalogTest(TestCase):
response = Client().get("/")
self.assertTemplateUsed(response, "app/katalog_materi.html")
# def test_daftar_kategori(self):
# kategori = Category()
# kategori.name = "baru"
# kategori.description = "kategori baru saya"
# kategori.save()
# kategori2 = Category()
# kategori2.name = "baru2"
# kategori2.save()
# materi1 = Materi()
# materi1.title = "baru lah"
# materi1.save()
# materi1.categories.add(kategori.id)
# materi1.save()
# materi2 = Materi()
# materi2.save()
# materi2.categories.add(kategori2)
# materi2.save()
# cl = Client()
# res = cl.get('/?kategori='+str(kategori.pk))
# self.assertIn(materi1, res.context['materi_list'])
# self.assertNotIn(materi2,res.context['materi_list'])
def test_daftar_katalog_using_daftar_katalog_func(self):
found = resolve("/")
self.assertEqual(found.func.__name__, DaftarKatalog.as_view().__name__)
......@@ -60,28 +36,6 @@ class DaftarKatalogTest(TestCase):
class DetailMateriTest(TestCase):
# def test_detail_materi_url_exist(self):
# materi = Materi.objects.create(title="wahyu",
# cover='https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg',
# author='Saul Andre Lumban Gaol',
# 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):
# materi = Materi.objects.create(title="wahyu",
# cover='https://cache.umusic.com/_sites/billieeilish/v2/images/pic-red.jpg',
# author='Saul Andre Lumban Gaol',
# 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/1/")
......@@ -132,39 +86,38 @@ class TemplateLoaderTest(TestCase):
class UploadPageTest(TestCase):
def test_upload_page_using_login_func(self):
found = resolve("")
self.assertEqual(found.func.__name__, )
found = resolve("/unggah/")
self.assertEqual(found.func.__name__, UploadMateriHTML.as_view().__name__)
def test_upload_page_url_is_exist(self):
# Positive tests
response = Client().get("")
self.assertEqual(response.status_code, 200)
def test_uplaod_page_url_is_exist(self):
#Positive test
response = Client().get("/unggah/")
self.assertEqual(response.status_code,200)
# Negative tests
response = Client().get("")
response = Client().get("/fake/")
self.assertEqual(response.status_code, 404)
def test_upload_page_template(self):
url = ""
url = "/unggah/"
response = Client().get(url)
expected_template_name = ""
expected_template_name = "unggah.html"
self.assertTemplateUsed(response, expected_template_name)
def test_upload_page_title(self):
response = Client().get("")
response = Client().get("/unggah/")
# Positive tests
self.assertContains(response, "")
self.assertContains(response, "Unggah Materi")
# Negative tests
self.assertNotContains(response, "")
self.assertNotContains(response, "Anything")
def test_upload_page_form_field(self):
response = Client().get("")
response = Client().get("/unggah/")
# Positive tests
self.assertContains(response, "")
self.assertContains(response, "")
self.assertContains(response, "title")
# Negative tests
self.assertNotContains(response, "")
self.assertNotContains(response, "anything")
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