Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Collection of Practice
2019
1606835595-practice
Commits
e98e66bd
Commit
e98e66bd
authored
Sep 24, 2019
by
Kevin Albert Simanjuntak
Browse files
refactor
parent
429fb6fb
Pipeline
#20538
passed with stage
in 1 minute and 2 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
functional_tests.py
View file @
e98e66bd
...
...
@@ -35,18 +35,21 @@ class NewVisitorTest(unittest.TestCase):
# When she hits enter, the page updates, and now the page lists
# "1: Buy peacock feathers" as an item in a to-do list table
inputbox
.
send_keys
(
Keys
.
ENTER
)
time
.
sleep
(
1
)
inputbox
.
send_keys
(
Keys
.
ENTER
)
time
.
sleep
(
1
)
table
=
self
.
browser
.
find_element_by_id
(
'id_list_table'
)
rows
=
table
.
find_elements_by_tag_name
(
'tr'
)
self
.
assertTrue
(
any
(
row
.
text
==
'1: Buy peacock feathers'
for
row
in
rows
),
"New to-do item did not appear in table"
)
# There is still a text box inviting her to add another item. She
# enters "Use peacock feathers to make a fly" (Edith is very
# methodical)
self
.
fail
(
'Finish the test!'
)
# The page updates again, and now shows both items on her list
#self.assertTrue(any(row.text == '1: Buy peacock feathers' for row in rows),f"New to-do item did not appear in table")
self
.
assertIn
(
'1: Buy peacock feathers'
,
[
row
.
text
for
row
in
rows
])
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
)
time
.
sleep
(
1
)
table
=
self
.
browser
.
find_element_by_id
(
'id_list_table'
)
rows
=
table
.
find_elements_by_tag_name
(
'tr'
)
self
.
assertIn
(
'1: Buy peacock feathers'
,
[
row
.
text
for
row
in
rows
])
self
.
assertIn
(
'2: Use peacock feathers to make a fly'
,[
row
.
text
for
row
in
rows
])
if
__name__
==
'__main__'
:
unittest
.
main
(
warnings
=
'ignore'
)
\ No newline at end of file
lists/__pycache__/tests.cpython-37.pyc
View file @
e98e66bd
No preview for this file type
lists/__pycache__/views.cpython-37.pyc
View file @
e98e66bd
No preview for this file type
lists/templates/home.html
View file @
e98e66bd
...
...
@@ -4,8 +4,12 @@
</head>
<body>
<h1>
Your To-Do list
</h1>
<input
id=
"id_new_item"
placeholder=
"Enter a to-do item"
/>
<table
id=
"id_list_table"
>
</table>
</body>
<form
method=
"POST"
>
<input
name=
"item_text"
id=
"id_new_item"
placeholder=
"Enter a to-do item"
/>
{% csrf_token %}
</form>
<table
id=
"id_list_table"
>
<tr><td>
1: {{ new_item_text }}
</td></tr>
</table>
</body>
</html>
\ No newline at end of file
lists/tests.py
View file @
e98e66bd
...
...
@@ -20,4 +20,9 @@ class HomePageTest(TestCase):
def
test_uses_home_template
(
self
):
response
=
self
.
client
.
get
(
'/homepage/'
)
self
.
assertTemplateUsed
(
response
,
'home.html'
)
def
test_can_save_a_POST_request
(
self
):
response
=
self
.
client
.
post
(
'/homepage/'
,
data
=
{
'item_text'
:
'A new list item'
})
self
.
assertIn
(
'A new list item'
,
response
.
content
.
decode
())
self
.
assertTemplateUsed
(
response
,
'home.html'
)
\ No newline at end of file
lists/views.py
View file @
e98e66bd
from
django.http
import
HttpResponse
from
django.shortcuts
import
render
def
home_page
(
request
):
return
render
(
request
,
'home.html'
)
\ No newline at end of file
return
render
(
request
,
'home.html'
,
{
'new_item_text'
:
request
.
POST
.
get
(
'item_text'
,
''
),
})
\ No newline at end of file
s
0 → 100644
View file @
e98e66bd
[1mdiff --git a/functional_tests.py b/functional_tests.py[m
[1mindex c9ac63e..a438209 100644[m
[1m--- a/functional_tests.py[m
[1m+++ b/functional_tests.py[m
[36m@@ -35,18 +35,21 @@[m [mclass NewVisitorTest(unittest.TestCase):[m
[m
# When she hits enter, the page updates, and now the page lists[m
# "1: Buy peacock feathers" as an item in a to-do list table[m
[31m- inputbox.send_keys(Keys.ENTER) [m
[31m- time.sleep(1) [m
[m
[32m+[m[32m inputbox.send_keys(Keys.ENTER)[m
[32m+[m[32m time.sleep(1)[m
table = self.browser.find_element_by_id('id_list_table')[m
rows = table.find_elements_by_tag_name('tr') [m
[31m- self.assertTrue(any(row.text == '1: Buy peacock feathers' for row in rows),"New to-do item did not appear in table")[m
[31m-[m
[31m- # There is still a text box inviting her to add another item. She[m
[31m- # enters "Use peacock feathers to make a fly" (Edith is very[m
[31m- # methodical)[m
[31m- self.fail('Finish the test!')[m
[31m-[m
[31m- # The page updates again, and now shows both items on her list [m
[32m+[m[32m #self.assertTrue(any(row.text == '1: Buy peacock feathers' for row in rows),f"New to-do item did not appear in table")[m
[32m+[m[32m self.assertIn('1: Buy peacock feathers', [row.text for row in rows])[m
[32m+[m[32m inputbox = self.browser.find_element_by_id('id_new_item')[m
[32m+[m[32m inputbox.send_keys('Use peacock feathers to make a fly')[m
[32m+[m[32m inputbox.send_keys(Keys.ENTER)[m
[32m+[m[32m time.sleep(1)[m
[32m+[m[32m table = self.browser.find_element_by_id('id_list_table')[m
[32m+[m[32m rows = table.find_elements_by_tag_name('tr')[m
[32m+[m[32m self.assertIn('1: Buy peacock feathers', [row.text for row in rows])[m
[32m+[m[32m self.assertIn('2: Use peacock feathers to make a fly',[row.text for row in rows])[m
[32m+[m[41m [m
if __name__ == '__main__': [m
unittest.main(warnings='ignore')[m
\ No newline at end of file[m
[1mdiff --git a/lists/__pycache__/tests.cpython-37.pyc b/lists/__pycache__/tests.cpython-37.pyc[m
[1mindex f371935..4b6e9b9 100644[m
Binary files a/lists/__pycache__/tests.cpython-37.pyc and b/lists/__pycache__/tests.cpython-37.pyc differ
[1mdiff --git a/lists/__pycache__/views.cpython-37.pyc b/lists/__pycache__/views.cpython-37.pyc[m
[1mindex 8a440d0..2bd5393 100644[m
Binary files a/lists/__pycache__/views.cpython-37.pyc and b/lists/__pycache__/views.cpython-37.pyc differ
[1mdiff --git a/lists/templates/home.html b/lists/templates/home.html[m
[1mindex 9a2a093..dd544fc 100644[m
[1m--- a/lists/templates/home.html[m
[1m+++ b/lists/templates/home.html[m
[36m@@ -4,8 +4,12 @@[m
</head>[m
<body>[m
<h1>Your To-Do list</h1>[m
[31m- <input id="id_new_item" placeholder="Enter a to-do item" />[m
[31m- <table id="id_list_table">[m
[31m- </table>[m
[31m- </body>[m
[32m+[m [32m<form method="POST">[m
[32m+[m[41m [m [32m<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />[m
[32m+[m[41m [m [32m{% csrf_token %}[m
[32m+[m [32m</form>[m
[32m+[m [32m<table id="id_list_table">[m
[32m+[m[41m [m [32m<tr><td>1: {{ new_item_text }}</td></tr>[m
[32m+[m[41m [m [32m</table>[m
[32m+[m [32m</body>[m
</html>[m
\ No newline at end of file[m
[1mdiff --git a/lists/tests.py b/lists/tests.py[m
[1mindex 4e973ff..44473b0 100644[m
[1m--- a/lists/tests.py[m
[1m+++ b/lists/tests.py[m
[36m@@ -20,4 +20,9 @@[m [mclass HomePageTest(TestCase):[m
[m
def test_uses_home_template(self):[m
response = self.client.get('/homepage/')[m
[32m+[m[32m self.assertTemplateUsed(response, 'home.html')[m
[32m+[m
[32m+[m[32m def test_can_save_a_POST_request(self):[m
[32m+[m[32m response = self.client.post('/homepage/', data={'item_t
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment