Fakultas Ilmu Komputer UI

Commit e6410346 authored by Agas Yanpratama's avatar Agas Yanpratama 💬
Browse files

Merge branch 'takehome-UAS' into 'master'

Takehome uas

See merge request !16
parents 91ebf75b 3995b41d
Pipeline #28504 passed with stages
in 38 minutes and 44 seconds
......@@ -18,7 +18,8 @@ Unit_Test:
- python manage.py migrate
when: on_success
script:
- python manage.py test lists
- coverage run --omit='manage.py,functional_tests/*,superlists/*,env/*' manage.py test lists accounts
- coverage report -m
Deploy:
......
1. URL Gitlab:
https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1606918396-practice
2. Branch yang digunakan:
takehome-UAS
https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1606918396-practice/tree/takehome-UAS
Fitur: Delete Todo List one by one
\ No newline at end of file
......@@ -4,6 +4,16 @@ Agas Yanpratama - 1606918396 - PMPL A
heroku link: [http://pmpl-agas.herokuapp.com/](http://pmpl-agas.herokuapp.com/)
Pipeline:
[![pipeline status](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1606918396-practice/badges/master/pipeline.svg)](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1606918396-practice/commits/master)
Coverage:
[![coverage report](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1606918396-practice/badges/master/coverage.svg)](https://gitlab.cs.ui.ac.id/pmpl/practice-collection/2019/1606918396-practice/commits/master)
***
## Cerita Exercise 3
......
......@@ -26,7 +26,7 @@ class FunctionalTest(StaticLiveServerTestCase):
try:
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_elements_by_tag_name('tr')
self.assertIn(row_text, [row.text for row in rows])
self.assertIn(row_text, [row.find_element_by_css_selector('.item-content').text for row in rows])
return
except (AssertionError, WebDriverException) as e:
if time.time() - start_time > MAX_WAIT:
......
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from .base import FunctionalTest
class DeleteListItemTest(FunctionalTest):
def test_can_delete_todo_list_item(self):
self.browser.get(self.live_server_url)
# User mengisi item pertama
self.browser.find_element_by_id('id_new_item').send_keys('Beli kfc')
self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('1: Beli kfc')
# User mengisi item kedua
self.browser.find_element_by_id('id_new_item').send_keys('Minum aqua')
self.browser.find_element_by_id('id_new_item').send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('2: Minum aqua')
# Karena user sudah beli mcd maka user tidak jadi beli kfc dan ingin dihapus
self.browser.execute_script("document.getElementById('del-button-1').click();")
# Mengecek kfc sudah tidak ada di to do list
page_text = self.browser.find_element_by_tag_name('body').text
self.assertNotIn('Beli kfc', page_text)
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from .base import FunctionalTest
class HeaderFooterTest(FunctionalTest):
def test_can_see_header_contain_name(self):
self.browser.get(self.live_server_url)
self.assertIn('Agas Yanpratama', self.browser.find_element_by_id('header').text)
def test_can_see_footer_contain_name(self):
self.browser.get(self.live_server_url)
self.assertIn('Agas Yanpratama', self.browser.find_element_by_id('footer').text)
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
......@@ -8,14 +8,38 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>To-Do lists</title>
<title>To-Do lists</title>
<link href="{% static 'bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'base.css' %}" rel="stylesheet">
<style>
.footer-div {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: black;
color: white;
text-align: center;
}
.header-div {
position: fixed;
left: 0;
top: 0;
margin-bottom: 20px;
width: 100%;
background-color: black;
color: white;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<div class="header-div">
<p id="header">Agas Yanpratama</p>
</div>
<div class="container" style="margin-top: 10px;">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<a class="navbar-brand" href="/">Superlists</a>
......@@ -60,6 +84,16 @@
</div>
</div>
</body>
<div class="footer-div">
<p id="footer">Agas Yanpratama</p>
</div>
<!-- Use jquery 3.7.1 and bootsrap 3.3.7-->
<script src="{% static 'jquery.min.js' %}"></script>
<script type="application/javascript" src="{% static 'bootstrap.min.js' %}"></script>
{% block custom_script %}
​{% endblock %}
</body>
</html>
\ No newline at end of file
......@@ -22,8 +22,18 @@
<table id="id_list_table" class="table">
{% for item in list.item_set.all %}
<tr>
<td>{{ forloop.counter }}: {{ item.text }}</td>
<td><div class ="item-content">{{ forloop.counter }}: {{ item.text }}</div> <button class="delete-todo btn btn-danger" id="del-button-{{forloop.counter}}" data-id="{{item.id}}">Delete</button></td>
</tr>
{% endfor %}
</table>
{% endblock %}
{% block custom_script %}
<script type="application/javascript">
$(".delete-todo").on("click", function (e) {
var todo_id = $(this).data('id');
location.href = "delete_item/" + todo_id;
});
</script>
{% endblock %}
\ No newline at end of file
......@@ -4,7 +4,7 @@ from django.http import HttpRequest
from django.template.loader import render_to_string
from lists.views import home_page
from lists.views import home_page, delete_item
from lists.models import Item, List
class ListAndItemModelsTest(TestCase):
......@@ -36,3 +36,23 @@ class ListAndItemModelsTest(TestCase):
self.assertEqual(second_saved_item.text, 'Item the second')
self.assertEqual(second_saved_item.list, list_)
def test_saving_and_deleting_items(self):
list_ = List()
list_.save()
first_item = Item()
first_item.text = 'The first (ever) list item'
first_item.list = list_
first_item.save()
saved_items = Item.objects.all()
self.assertEqual(saved_items.count(), 1)
saved_list = List.objects.first()
saved_obj = saved_items[0]
saved_obj.delete()
saved_items_after_del = Item.objects.all()
self.assertEqual(saved_items_after_del.count(), 0)
......@@ -131,4 +131,30 @@ class NewItemTest(TestCase):
)
self.assertIn('task amount: 5', response.content.decode('utf-8'))
self.assertIn('oh tidak, harus dikerjakan secepatnya', response.content.decode('utf-8'))
\ No newline at end of file
self.assertIn('oh tidak, harus dikerjakan secepatnya', response.content.decode('utf-8'))
class DeleteItemTest(TestCase):
def test_delete_todo(self):
new_list = List.objects.create()
# Create Todo
newTodoItem = Item.objects.create(text='item 1', list=new_list)
self.client.get(
f'/lists/{new_list.id}/delete_item/{newTodoItem.id}/'
)
self.assertEqual(Item.objects.all().count(), 0)
def test_delete_redirects_to_list_view(self):
new_list = List.objects.create()
# Create Todo
newTodoItem = Item.objects.create(text='item 1', list=new_list)
response = self.client.get(
f'/lists/{new_list.id}/delete_item/{newTodoItem.id}/'
)
self.assertRedirects(response, f'/lists/{new_list.id}/')
\ No newline at end of file
......@@ -5,4 +5,5 @@ urlpatterns = [
url(r'^new$', views.new_list, name='new_list'),
url(r'^(\d+)/$', views.view_list, name='view_list'),
url(r'^(\d+)/add_item$', views.add_item, name='add_item'),
url(r'^(?P<list_id>\d+)/delete_item/(?P<todo_id>\d+)/$', views.delete_item, name='delete_item'),
]
\ No newline at end of file
......@@ -16,4 +16,10 @@ def new_list(request):
def add_item(request, list_id):
list_ = List.objects.get(id=list_id)
Item.objects.create(text=request.POST['item_text'], list=list_)
return redirect(f'/lists/{list_.id}/')
def delete_item(request, list_id, todo_id):
list_ = List.objects.get(id=list_id)
todo = Item.objects.get(id=todo_id)
todo.delete()
return redirect(f'/lists/{list_.id}/')
\ No newline at end of file
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