Fakultas Ilmu Komputer UI

Uas pmpl

parent 204b8ab2
......@@ -40,7 +40,7 @@ class NewVisitorTest(FunctionalTest):
# to check out its homepage
self.login_first()
time.sleep(2)
# She notices the page title and header mention to-do lists
self.assertIn('To-Do list', self.browser.title)
......@@ -59,7 +59,7 @@ class NewVisitorTest(FunctionalTest):
# "1: Buy peacock feathers" as an item in a to-do list table
inputbox.send_keys(Keys.ENTER)
time.sleep(2)
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_elements_by_tag_name('tr')
......@@ -72,7 +72,7 @@ class NewVisitorTest(FunctionalTest):
inputbox.send_keys('Use peacock feathers to make a fly')
inputbox.send_keys(Keys.ENTER)
time.sleep(2)
# The page updates again, and now shows both items on her list
table = self.browser.find_element_by_id('id_list_table')
......@@ -88,7 +88,7 @@ class NewVisitorTest(FunctionalTest):
# Satisfied, she goes back to sleep
time.sleep(2)
@unittest.skip("deprecated : not used anymore since / is list")
def test_go_to_todo_from_homepage(self):
......@@ -122,6 +122,41 @@ class NewVisitorTest(FunctionalTest):
delta=10
)
def test_delete_todo_from_list(self):
self.login_first()
self.assertIn('To-Do list', self.browser.title)
header_text = self.browser.find_element_by_tag_name('h1').text
self.assertIn('To-Do list', header_text)
inputbox = self.browser.find_element_by_id('id_new_item')
inputbox.send_keys('Buy peacock feathers')
inputbox.send_keys(Keys.ENTER)
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_elements_by_tag_name('tr')
self.check_for_row_in_list_table('1: Buy peacock feathers')
inputbox = self.browser.find_element_by_id('id_new_item')
inputbox.send_keys('Use peacock feathers to make a fly')
inputbox.send_keys(Keys.ENTER)
self.browser.find_element_by_id('delete-button').click()
table = self.browser.find_element_by_id('id_list_table')
try:
rows = table.find_elements_by_tag_name('tr')
self.check_for_row_in_list_table('1: Buy peacock feathers')
self.fail("item is not deleted")
except AssertionError:
pass
if __name__ == "__main__":
unittest.main(warnings="ignore")
\ No newline at end of file
......@@ -16,13 +16,14 @@ Including another URLconf
from django.contrib import admin
from django.urls import path, include
from home.views import index
from todo.views import todo
from todo.views import todo, delete_todo
from django.views.generic import RedirectView
urlpatterns = [
#path('admin/', admin.site.urls),
#path("", index, name="index"),
path("", todo, name="index"),
path("delete/", delete_todo, name="delete_todo"),
#path("todo/", todo, name="todo"),
path("accounts/", include('accounts.urls')),
]
from django.db import models
import uuid
# Create your models here.
class Item(models.Model):
text = models.TextField(default="")
\ No newline at end of file
text = models.TextField(default="")
uid = models.CharField(default=uuid.uuid4, max_length=40)
\ No newline at end of file
......@@ -50,8 +50,8 @@
<input name="item_text" id="id_new_item"
class="form-control input-lg"
placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
{% csrf_token %}
</form>
</div>
</div>
<div class="col-md-6 col-md-offset-3">
......
......@@ -9,7 +9,16 @@
{% block form_action %}{% endblock %}
{% block table %}
<table id="id_list_table" class="table">
{% if items %}
<div class="text-center">
<form method="POST" action="delete/" style="margin-top: 10px;">
<input name="delete-button" id="delete-button"
type="submit" value="Delete All"/>
{% csrf_token %}
</form>
</div>
{% endif %}
<table id="id_list_table" class="table">
{% for item in items %}
<tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr>
{% endfor %}
......
......@@ -2,7 +2,7 @@ from django.test import TestCase
from django.urls import reverse
from django.http import HttpRequest
from django.template.loader import render_to_string
from todo.views import todo
from todo.views import todo, delete_todo
from todo.models import Item
# Create your tests here.
......@@ -77,6 +77,16 @@ class TodoPageTests(TestCase):
self.assertEqual(100, Item.objects.count())
#self.assertIn("<p class=\"comment\">oh tidak</p>", response.content.decode())
def test_todo_page_delete_all_list_items(self):
Item.objects.create(text='itemey 1')
Item.objects.create(text='itemey 2')
request = HttpRequest()
request.method = "POST"
response = delete_todo(request)
self.assertEqual(0, Item.objects.count())
class ItemModelTest(TestCase):
def test_saving_and_retrieving_items(self):
first_item = Item()
......
from django.shortcuts import render, redirect
from django.http import HttpResponse
from todo.models import Item
import uuid
# Create your views here.
def todo(request):
if request.method == 'POST':
Item.objects.create(text=request.POST['item_text'])
Item.objects.create(uid=uuid.uuid4 ,text=request.POST.get('item_text'))
return redirect('/')
items = Item.objects.all()
comment = get_custom_comment(items)
return render(request, 'todo.html', {'items': items, 'comment': comment})
def delete_todo(request):
if request.method == "POST":
Item.objects.all().delete()
return redirect('/')
def get_custom_comment(items):
if(items.count() == 0):
return "yey, waktunya berlibur"
......
Markdown is supported
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