Fakultas Ilmu Komputer UI

Commit 2a1a04ec authored by I Gusti Putu Agastya Indrayana's avatar I Gusti Putu Agastya Indrayana
Browse files

[RED] Test detail verification page.

parent 9eb14f24
{% extends 'app/detail_materi.html' %}
{% block title %}
Pratinjau Materi
{% endblock title %}
{% block verification %}
<nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
<!-- Sidebar Toggle (Topbar) -->
<button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
<i class="fa fa-bars"></i>
</button>
<div class="sidebar-brand-text mx-3">Pratinjau Materi</div>
<!-- Topbar Navbar -->
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<button data-toggle="modal" data-target="#myModal" id="checklistButton" class="btn"
style="background-color:#4e73df;color: azure;">
Tampilkan Kriteria
</button>
</li>
</ul>
</nav>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-xl">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Kriteria Verifikasi</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
{% if error %}
<h4>Terjadi Kesalahan, coba lagi.</h4>
{% endif %}
{% for kriteria in kriteria_list %}
<div class="row m-2">
<div class="col-8">
{{kriteria.title}}
</div>
<div class="col-2">
<div class="custom-control custom-radio custom-control-inline">
<input id="kriteria{{ forloop.counter }}Ya" type="radio"
name="kriteria{{ forloop.counter }}" class="custom-control-input kriteria-ok" value=1>
<label class="custom-control-label" for="kriteria{{ forloop.counter }}Ya">Ya</label>
</div>
</div>
<div class="col-2">
<div class="custom-control custom-radio custom-control-inline">
<input checked id="kriteria{{ forloop.counter }}Tidak" type="radio"
name="kriteria{{ forloop.counter }}" class="custom-control-input" value=0>
<label class="custom-control-label" for="kriteria{{ forloop.counter }}Tidak">Tidak</label>
</div>
</div>
</div>
{% endfor %}
<span><small>Kontributor tidak dapat melihat point-point verifikasi, jika materi ditolak tuliskan alasan
penolakan tersebut di kolom tanggapan.</small></span>
<hr>
<form method="POST" id="submitForm">
{% csrf_token %}
<label for="feedbackMateri">Tanggapan terhadap materi untuk Kontributor :</label>
<textarea name="feedback" id="feedbackMateri" class="form-control" rows="6"></textarea>
</form>
</div>
<div class="modal-footer">
<button disabled class="accept-button btn" type="submit" name="action" value="approve" form="submitForm"
style="background-color: #28a745;border-radius: .25rem;color: azure;"
id="approveButton">Terima</button>
<button disabled class="reject-button btn" type="submit" name="action" value="disapprove"
form="submitForm" style="background-color: #dc3545;border-radius: .25rem;color: azure;"
id="disapproveButton">Tolak</button>
<button type="button" class="btn" data-dismiss="modal">Tutup</button>
</div>
</div>
</div>
</div>
{% endblock verification %}
{% block extra_scripts %}
<script>
function cekRadio() {
res = true
x = document.getElementsByClassName("kriteria-ok")
for (index = 0; index < x.length; index++) {
if (x[index].checked == false) {
res = false;
break;
}
}
return res;
}
function cekFeedback() {
if (!$.trim($("#feedbackMateri").val())) {
return false;
} else {
return true;
}
}
$(document).ready(function () {
var approveButton = document.getElementById("approveButton")
var disapproveButton = document.getElementById("disapproveButton")
$(":input").change(function () {
console.log("Running test")
var statusRadio = cekRadio();
var statusFeedback = cekFeedback();
if (statusFeedback) {
disapproveButton.disabled = false;
if (statusRadio) {
approveButton.disabled = false;
} else {
approveButton.disabled = true;
}
} else {
disapproveButton.disabled = true;
approveButton.disabled = true;
}
});
});
</script>
{% endblock extra_scripts %}
\ No newline at end of file
......@@ -161,17 +161,20 @@
</tr>
</tfoot>
<tbody>
{% for materi in materi_list %}
<tr>
{% for materi in materi_list %}
<td>{{ materi.tittle }}</td>
<td>{{ materi.title }}</td>
<td>{{ materi.uploader.name }}</td>
<td>{{ materi.status.1 }}</td>
{% if materi.status.0 == "PENDING" %}
<td class="verif-buttons"><a href="/administration/api/approve/{{materi.id}}/" class="accept-button">Terima</a><a href="/administration/api/disapprove/{{materi.id}}/"
class="reject-button">Tolak</a></td>
<td>{{ materi.status.label }}</td>
{% if materi.status == "PENDING" %}
<td class="verif-buttons">
<a href="/administration/detail-verif/{{materi.id}}/" class="accept-button"
style="background-color:#4e73df">Detail</a>
<a href="/administration/api/approve/{{materi.id}}/" class="accept-button">Terima</a>
<a href="/administration/api/disapprove/{{materi.id}}/" class="reject-button">Tolak</a></td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
......@@ -206,7 +209,6 @@
</a>
<!-- Bootstrap core JavaScript-->
<!-- <script src="{% static 'vendor/jquery/jquery.min.js' %}"></script> -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
......
......@@ -3,129 +3,117 @@ from django.test import Client, TestCase
from django.urls import resolve
from administration import models, views
from app.models import Materi
from app.models import Materi, Category
class VerifikasiMateriTest(TestCase):
def setUp(self):
self.client = Client()
# def test_verifikasi_materi_url_exist(self):
# response = self.client.get('/administration/')
# self.assertEqual(response.status_code, 200)
# def test_verifikasi_materi_using_correct_template(self):
# found = resolve('/administration/')
# self.assertEqual(found.func.__name__, views.verification.__name__)
# found2 = resolve('/admin/')
# self.assertNotEqual(found2.func.__name__, views.verification.__name__)
# def test_verifikasi_materi_title(self):
# response = self.client.get('/administration/')
# self.assertContains(response, 'Dasbor - Verifikasi Materi')
# self.assertNotContains(response, 'Fake Title')
# def test_verifikasi_materi_content(self):
# response = self.client.get('/administration/')
# self.assertContains(response, 'Judul Materi')
# self.assertContains(response, 'Nama Kontributor')
# self.assertContains(response, 'Status')
# self.assertNotContains(response, 'Halaman Katalog')
self.url = "/administration/setting/verification/"
self.model = models.VerificationSetting
self.admin = get_user_model().objects.create_user(
password="admin123", email="admin@admin.com", is_admin=True)
self.contributor = get_user_model().objects.create_user(
password="kontributor123", email="kontributor@kontributor.com", is_contributor=True
)
self.materi = Materi(title="LK 3", author="Agas", uploader=self.contributor,
publisher="Kelas SC", descriptions="COntoh pengerjaan LK 3", status="PENDING").save()
def test_verifikasi_materi_url_exist(self):
response = self.client.get('/administration/detail')
# Login
self.client.login(email="admin@admin.com",
password="admin123")
response = self.client.get('/administration/')
self.assertEqual(response.status_code, 200)
def test_verifikasi_materi_using_correct_template(self):
found = resolve('/administration/detail')
self.assertEqual(found.func.__name__, views.detail.__name__)
found2 = resolve('/admin/')
self.assertNotEqual(found2.func.__name__, views.verification.__name__)
# Login
self.client.login(email="admin@admin.com",
password="admin123")
found = resolve('/administration/')
self.assertEqual(found.func.__name__, views.VerificationView.__name__)
def test_verifikasi_materi_title(self):
response = self.client.get('/administration/detail')
# Login
self.client.login(email="admin@admin.com",
password="admin123")
response = self.client.get('/administration/')
self.assertContains(response, 'Dasbor - Verifikasi Materi')
self.assertNotContains(response, 'Fake Title')
def test_verifikasi_materi_content(self):
response = self.client.get('/administration/detail')
# Login
self.client.login(email="admin@admin.com",
password="admin123")
response = self.client.get('/administration/')
self.assertContains(response, 'Judul Verifikasi')
self.assertContains(response, 'Deskripsi')
self.assertContains(response, 'Tombol')
self.assertContains(response, 'LK 3')
self.assertContains(response, self.contributor.name)
self.assertNotContains(response, 'Halaman Katalog')
class DetailVerifikasiMateriTest(TestCase):
def setUp(self):
self.client = Client()
self.view = views.DetailVerificationView
self.template_name = "detai_verif.html"
self.model = models.VerificationSetting
self.admin = get_user_model().objects.create_user(
password="admin123", email="admin@admin.com", is_admin=True)
self.contributor = get_user_model().objects.create_user(
password="kontributor123", email="kontributor@kontributor.com", is_contributor=True
)
self.materi = Materi(id = 1, title="LK 3", author="Agas", uploader=self.contributor,
publisher="Kelas SC", descriptions="COntoh pengerjaan LK 3", status="PENDING").save()
self.url = f"/administration/detail-verif/1/"
def test_dashboard_kontributor_view(self):
found = resolve(self.url)
self.assertEqual(found.func.__name__, self.view.as_view().__name__)
def test_dashboard_kontributor_template(self):
# Login
self.client.login(email="admin@admin.com",
password="admin123")
# Test
response = self.client.get(self.url)
self.assertTemplateUsed(response, self.template_name)
# Logout
self.client.logout()
def test_dashboard_kontributor_url(self):
# Login
self.client.login(email="admin@admin.com",
password="admin123")
# Test
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
# Logout
self.client.logout()
class SettingVerifikasiTest(TestCase):
def setUp(self):
self.client = Client()
self.url = "/administration/setting/verification/"
self.model = models.VerificationSetting
self.admin = get_user_model().objects.create_user(password="admin123", email="admin@admin.com", is_admin=True)
self.admin = get_user_model().objects.create_user(
password="admin123", email="admin@admin.com", is_admin=True)
self.contributor = get_user_model().objects.create_user(
password="kontributor123", email="kontributor@kontributor.com", is_contributor=True
)
# def test_setting_verifikasi_url_exist(self):
# # Test not authenticated
# response = self.client.get(self.url)
# self.assertEqual(response.status_code, 403)
# # Test Contributor
# self.client.login(email = 'kontributor@kontributor.com', password = 'kontributor123')
# response = self.client.get(self.url)
# self.assertEqual(response.status_code, 403)
# self.client.logout()
# # Test Admin
# self.client.login(email = 'admin@admin.com', password = 'admin123')
# response = self.client.get(self.url)
# self.assertEqual(response.status_code, 200)
# def test_setting_verifikasi_template(self):
# self.client.login(email = 'admin@admin.com', password = 'admin123')
# response = self.client.get(self.url)
# self.assertTemplateUsed(response, 'setting_verifikasi.html')
# def test_setting_verifikasi_func(self):
# found = resolve(self.url)
# self.assertEqual(found.func.__name__, views.VerificationSettingView.as_view().__name__)
# def test_setting_verifikasi_model(self):
# self.assertEqual(self.model.objects.all().count(), 0)
# s1 = self.model(title = "Point 1",description= "Deskripsi Point 1")
# s1.save()
# self.assertEqual(self.model.objects.all().count(), 1)
# def test_setting_verifikasi_table(self):
# # Login
# self.client.login(email = 'admin@admin.com', password = 'admin123')
# # View table
# response = self.client.get(self.url)
# self.assertNotIn(response.content, b'Point 1')
# # Add new setting
# data = {
# "tittle":"Point 1",
# "description":"Deskripsi Point 1"
# }
# response = self.client.post(self.url, data)
# self.assertIn(response.content, b'Point 1')
# self.assertEqual(response.status_code, 200)
# # Add new setting, missing value
# data = {
# "description":"Deskripsi Point 2"
# }
# response = self.client.post(self.url, data)
# self.assertNotIn(response.content, b'Deskripsi Point 2')
# self.assertEqual(response.status_code, 200)
class SettingKategoriTest(TestCase):
def setUp(self):
self.client = Client()
self.url = "/administration/setting/category/"
self.model = Category
self.admin = get_user_model().objects.create_user(
password="admin123", email="admin@admin.com", is_admin=True)
self.contributor = get_user_model().objects.create_user(
password="kontributor123", email="kontributor@kontributor.com", is_contributor=True
)
......@@ -6,8 +6,7 @@ app_name = "administration"
urlpatterns = [
path("", views.VerificationView.as_view()),
path("api/approve/<int:pk>", views.approve),
path("api/disapprove/<int:pk>", views.disapprove),
path("detail-verif/<int:pk>/", views.DetailVerificationView.as_view()),
path("setting/verification/", views.VerificationSettingView.as_view()),
path("setting/category/", views.CategorySettingView.as_view()),
]
......@@ -13,35 +13,67 @@ from .models import VerificationSetting
class VerificationView(TemplateView):
template_name = "verif.html"
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated or not request.user.is_admin:
raise PermissionDenied(request)
return super(VerificationView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(VerificationView, self).get_context_data(**kwargs)
context["materi_list"] = Materi.objects.filter(status='PENDING')
return context
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
def approve(request, pk):
if request.user.is_authenticated == False or request.user.is_admin != True:
raise PermissionDenied(request)
materi = get_object_or_404(Materi, pk=pk)
materi.status = ("APPROVE", "Diterima")
materi.save()
return render(request, "verif.html")
class DetailVerificationView(TemplateView):
template_name = "detail_verif.html"
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated or not request.user.is_admin:
raise PermissionDenied(request)
return super(DetailVerificationView, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(DetailVerificationView,
self).get_context_data(**kwargs)
context["materi_data"] = get_object_or_404(Materi, pk=kwargs["pk"])
context["kriteria_list"] = VerificationSetting.objects.filter(
archived=False)
return context
def post(self, request, *args, **kwargs):
materi = get_object_or_404(Materi, pk=kwargs["pk"])
feedback = request.POST.get("feedback")
if request.POST.get("action") == "approve":
materi.status = "APPROVE"
materi.feedback = feedback
materi.save()
elif request.POST.get("action") == "disapprove":
materi.status = "DISAPPROVE"
materi.feedback = feedback
materi.save()
else:
context = self.get_context_data(**kwargs)
context["error"] = True
return self.render_to_response(context=context)
return HttpResponseRedirect("/administration/")
def disapprove(request, pk):
if request.user.is_authenticated == False or request.user.is_admin != True:
raise PermissionDenied(request)
materi = get_object_or_404(Materi, pk=pk)
materi.status = ("DISAPROVE", "Ditolat")
materi.save()
return render(request, "verif.html")
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
return self.render_to_response(context=context)
class VerificationSettingView(TemplateView):
template_name = "setting_verifikasi.html"
def get_context_data(self, **kwargs):
context = super(VerificationSettingView, self).get_context_data(**kwargs)
context["verification_settings"] = VerificationSetting.objects.filter(archived=False)
context = super(VerificationSettingView,
self).get_context_data(**kwargs)
context["verification_settings"] = VerificationSetting.objects.filter(
archived=False)
return context
def get(self, request, *args, **kwargs):
......
......@@ -50,7 +50,8 @@ class Materi(models.Model):
uploader = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
publisher = models.CharField(max_length=30, default="publiser")
descriptions = models.TextField(default="descriptions")
status = models.CharField(max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0])
status = models.CharField(max_length=30, choices=VERIFICATION_STATUS, default=VERIFICATION_STATUS[0][0])
categories = models.ManyToManyField(Category)
comments = models.ManyToManyField(Comment)
feedback = models.TextField(blank=True, default="")
\ No newline at end of file
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