Fakultas Ilmu Komputer UI

Commit 0c58db8e authored by Izzatul Muttaqin's avatar Izzatul Muttaqin
Browse files

Merge branch 'take-home-exam' into 'master'

Take home exam

See merge request !7
parents 58af4df2 5b41f4cc
Pipeline #28529 passed with stages
in 8 minutes and 10 seconds
from selenium.webdriver.common.keys import Keys
from .tests import FunctionalTest
class FooterHeaderTest(FunctionalTest):
def test_home_page_whether_satisfies_user_needs(self):
self.browser.get(self.live_server_url)
owner_full_name = "Izzatul Muttaqin"
header = self.browser.find_element_by_class_name("header")
footer = self.browser.find_element_by_class_name("footer")
self.assertIn(owner_full_name, header.text)
self.assertIn(owner_full_name, footer.text)
......@@ -18,9 +18,9 @@ class ItemValidationTest(FunctionalTest):
))
self.get_item_input_box().send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('2: Buy milk')
self.wait_for_row_in_list_table('2: Buy milk Delete')
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 Delete')
\ No newline at end of file
......@@ -67,13 +67,8 @@ 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(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
<html>
<title>To-Do lists {{ name }}</title>
<body>
<h1 id="intro">Hello, this is {{ name }}.</h1>
<h1>Your To-Do list</h1>
<form method="POST">
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
<title>To-Do lists {{ name }}</title>
<style>
/* Style the body */
body {
font-family: Arial;
margin: 0;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
text-align: center;
}
/* Header/Logo Title */
.header {
padding: 60px;
text-align: center;
background: #1abc9c;
color: white;
font-size: 30px;
}
</style>
<body>
<div class="header">
<h1>Website PMPL practice</h1>
<p>This owned by Izzatul Muttaqin</p>
</div>
<h1 id="intro">Hello, this is {{ name }}.</h1>
<h1>Your To-Do list</h1>
<form method="POST">
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
<h1 id="comment">{{ comment }}</h1>
<table id="id_list_table">
{% for item in items %}
<tr>
<td> {{ forloop.counter }}: {{ item.text }} <a id={{item.id}} href="/delete-item/?id={{ item.id }}"> Delete
</a></td>
</tr>
{% endfor %}
</table>
<div class="footer">
<p>Owned by Izzatul Muttaqin</p>
</div>
</body>
<h1 id="comment">{{ comment }}</h1>
<table id="id_list_table">
{% for item in items %}
<tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr>
{% endfor %}
</table>
</body>
</html>
\ No newline at end of file
......@@ -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('/')
astmonkey==0.3.6
astroid==1.5.3
colorama==0.3.9
coverage==4.4.1
dj-database-url==0.4.2
dj-database-url==0.5.0
Django==2.2.5
django-appconf==1.0.3
django-compressor==2.3
django-environ==0.4.4
gunicorn==19.7.1
isort==4.2.15
lazy-object-proxy==1.3.1
mccabe==0.6.1
psycopg2==2.7.3.1
pylint==1.7.2
pytz==2017.2
requests==2.18.4
selenium==3.5.0
six==1.10.0
whitenoise==3.3.0
wrapt==1.10.11
\ No newline at end of file
django-mutpy==0.1.2
django-sass-processor==0.7.3
gunicorn==19.9.0
Jinja2==2.10.3
libsass==0.19.3
MarkupSafe==1.1.1
MutPy==0.6.0
psycopg2-binary==2.8.3
pydot==1.4.1
pyparsing==2.4.2
pytz==2019.2
PyYAML==5.1.2
rcssmin==1.0.6
rjsmin==1.1.0
selenium==3.141.0
six==1.12.0
sqlparse==0.3.0
termcolor==1.1.0
urllib3==1.25.3
whitenoise==4.1.3
\ 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