Fakultas Ilmu Komputer UI

Commit 572b264d authored by Izzatul Muttaqin's avatar Izzatul Muttaqin
Browse files

Adding delete feature and header/footer

parent 9e790112
Pipeline #28410 failed with stages
in 38 minutes and 12 seconds
......@@ -23,4 +23,16 @@ class ItemValidationTest(FunctionalTest):
self.get_item_input_box().send_keys('Buy cheese')
self.get_item_input_box().send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('3: Buy cheese')
\ No newline at end of file
self.wait_for_row_in_list_table('3: Buy cheese')
def test_item_delete(self):
self.browser.get(self.live_server_url)
self.get_item_input_box().send_keys(Keys.ENTER)
self.get_item_input_box().send_keys('Buy milk')
self.get_item_input_box().send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('1: Buy milk')
self.browser.find_element_by_id('1').click()
self.wait_for_row_not_in_list_table('1: Buy Milk')
\ No newline at end of file
......@@ -53,9 +53,6 @@ class FunctionalTest(StaticLiveServerTestCase):
rows = table.find_elements_by_tag_name('tr')
self.assertIn(row_text, [row.text for row in rows])
def get_item_input_box(self):
return self.browser.find_element_by_id('id_new_item')
@wait
def wait_for(self, fn):
return fn()
......@@ -67,13 +64,7 @@ class FunctionalTest(StaticLiveServerTestCase):
self.assertIn(row_text, [row.text for row in rows])
@wait
def wait_to_be_logged_in(self, email):
self.browser.find_element_by_link_text('Log out')
navbar = self.browser.find_element_by_css_selector('.navbar')
self.assertIn(email, navbar.text)
@wait
def wait_to_be_logged_out(self, email):
self.browser.find_element_by_name('email')
navbar = self.browser.find_element_by_css_selector('.navbar')
self.assertNotIn(email, navbar.text)
\ No newline at end of file
def wait_for_row_not_in_list_table_to(self, row_text):
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_elements_by_tag_name('tr')
self.assertNotIn(row_text, [row.text for row in rows])
\ No newline at end of file
from django.db import models
class Item(models.Model):
text = models.TextField(default='')
date = models.DateTimeField(auto_now_add=True, blank=True)
\ No newline at end of file
text = models.TextField(default='')
\ No newline at end of file
......@@ -42,8 +42,8 @@
<table id="id_list_table">
{% for item in items %}
<tr>
<td> {{ forloop.counter }}: {{ item.text }} </td>
<td> {{ item.date }}</td>
<td> {{ forloop.counter }}: {{ item.text }} <a id={{item.id}} href="/delete-item/?id={{ item.id }}"> Delete
</a></td>
</tr>
{% endfor %}
</table>
......
......@@ -70,6 +70,22 @@ class HomePageTest(TestCase):
self.assertIn('itemey 1', response.content.decode())
self.assertIn('itemey 2', response.content.decode())
def test_delete_item(self):
item = Item.objects.create(text='itemey 1')
request = HttpRequest()
response = home_page(request)
self.assertIn('sibuk tapi santai', response.content.decode())
response = Client().get('/delete-item/?id=' + str(item.id))
request = HttpRequest()
response = home_page(request)
self.assertIn('yey, waktunya libur', response.content.decode())
self.assertNotIn(item, Item.objects.all())
def test_all_comment(self):
request = HttpRequest()
response = home_page(request)
......
from django.conf.urls import url
from .views import home_page
from .views import home_page, delete_item
#url for app
urlpatterns = [
url(r'^$', home_page, name='home_page')
url(r'^$', home_page, name='home_page'),
url(r'delete-item/$', delete_item, name='delete_item')
]
......@@ -6,7 +6,15 @@ def home_page(request):
if request.method == 'POST':
Item.objects.create(text=request.POST['item_text'])
return redirect('/')
items = Item.objects.all()
comment = counter_comment(Item.objects.count())
return render(request, 'homepage/home.html', {'items': items, 'comment' : comment, 'name': 'Izzatul Muttaqin'})
def delete_item(request):
if request.method=='GET':
id = request.GET.get('id')
if id is not None:
Item.objects.filter(id=id).delete()
return redirect('/')
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