Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Collection of Practice
2019
1606836976-practice
Commits
22194bf0
Commit
22194bf0
authored
Oct 09, 2019
by
Yumna Pratista
Browse files
chap 7 starting
parent
e2007f41
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
db.sqlite3
View file @
22194bf0
No preview for this file type
functional_tests/__pycache__/tests.cpython-37.pyc
View file @
22194bf0
No preview for this file type
functional_tests/tests.py
View file @
22194bf0
...
...
@@ -17,13 +17,15 @@ class NewVisitorTest(LiveServerTestCase):
chrome_options
.
add_argument
(
'--headless'
)
chrome_options
.
add_argument
(
'--disable-gpu'
)
self
.
browser
=
webdriver
.
Chrome
(
'./chromedriver'
,
chrome_options
=
chrome_options
)
# self.browser = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)
self
.
browser
=
webdriver
.
Firefox
()
def
tearDown
(
self
):
self
.
browser
.
quit
()
def
check_for_row_in_list_table
(
self
,
row_text
):
table
=
self
.
browser
.
find_element_by_id
(
'id_list_table'
)
time_sleep
(
5
)
rows
=
table
.
find_elements_by_tag_name
(
'tr'
)
self
.
assertIn
(
row_text
,
[
row_text
for
row
in
rows
])
...
...
@@ -42,7 +44,7 @@ class NewVisitorTest(LiveServerTestCase):
inputbox
.
send_keys
(
Keys
.
ENTER
)
time
.
sleep
(
5
)
# The page updates again, and now shows both items on her list
self
.
wait_for_row_in
t
_list_table
(
'1: Buy peacock feathers'
)
self
.
wait_for_row_in_list_table
(
'1: Buy peacock feathers'
)
# She is invited to enter a to-do item straight away
# There is still a text box inviting her to add another item. She
...
...
@@ -54,15 +56,15 @@ class NewVisitorTest(LiveServerTestCase):
time
.
sleep
(
5
)
# The page updates again, and now shows both items on her list
self
.
wait_for_row_in
t
_list_table
(
'1: Buy peacock feathers'
)
self
.
wait_for_row_in
t
_list_table
(
'2: Use peacock feathers to make a fly'
)
self
.
wait_for_row_in_list_table
(
'1: Buy peacock feathers'
)
self
.
wait_for_row_in_list_table
(
'2: Use peacock feathers to make a fly'
)
# Edith wonders whether the site will remember her list. Then she sees
# that the site has generated a unique URL for her -- there is some
# explanatory text to that effect.
# self.fail('Finish the test!')
def
wait_for_row_in
t
_list_table
(
self
,
row_text
):
def
wait_for_row_in_list_table
(
self
,
row_text
):
start_time
=
time
.
time
()
while
True
:
try
:
...
...
@@ -75,6 +77,59 @@ class NewVisitorTest(LiveServerTestCase):
raise
e
time
.
sleep
(
0.5
)
def
test_can_start_a_list_for_one_user
(
self
):
# Edith has heard about a cool new online to-do app. She goes
# The page updates again, and now shows both items on her list
self
.
wait_for_row_in_list_table
(
'2: Use peacock feathers to make a fly'
)
self
.
wait_for_row_in_list_table
(
'1: Buy peacock feathers'
)
# Satisfied, she goes back to sleep
def
test_multiple_users_can_start_lists_at_different_urls
(
self
):
# Edith starts a new to-do list
self
.
browser
.
get
(
self
.
live_server_url
)
inputbox
=
self
.
browser
.
find_element_by_id
(
'id_new_item'
)
inputbox
.
send_keys
(
'Buy peacock feathers'
)
inputbox
.
send_keys
(
Keys
.
ENTER
)
self
.
wait_for_row_in_list_table
(
'1: Buy peacock feathers'
)
# She notices that her list has a unique URL
edith_list_url
=
self
.
browser
.
current_url
self
.
assertRegex
(
edith_list_url
,
'/lists/.+'
)
# Now a new user, Francis, comes along to the site.
# We use a new browser session to make sure that no information
# of Edith's is coming through from cookies etc
self
.
browser
.
quit
()
self
.
browser
=
webdriver
.
Firefox
()
# Francis visits the home page. There is no sign of Edith's
# list
self
.
browser
.
get
(
self
.
live_server_url
)
page_text
=
self
.
browser
.
find_element_by_tag_name
(
'body'
).
text
self
.
assertNotIn
(
'Buy peacock feathers'
,
page_text
)
self
.
assertNotIn
(
'make a fly'
,
page_text
)
# Francis starts a new list by entering a new item. He
# is less interesting than Edith...
inputbox
=
self
.
browser
.
find_element_by_id
(
'id_new_item'
)
inputbox
.
send_keys
(
'Buy milk'
)
inputbox
.
send_keys
(
Keys
.
ENTER
)
self
.
wait_for_row_in_list_table
(
'1: Buy milk'
)
# Francis gets his own unique URL
francis_list_url
=
self
.
browser
.
current_url
self
.
assertRegex
(
francis_list_url
,
'/lists/.+'
)
self
.
assertNotEqual
(
francis_list_url
,
edith_list_url
)
# Again, there is no trace of Edith's list
page_text
=
self
.
browser
.
find_element_by_tag_name
(
'body'
).
text
self
.
assertNotIn
(
'Buy peacock feathers'
,
page_text
)
self
.
assertIn
(
'Buy milk'
,
page_text
)
# if __name__ == '__main__': #
...
...
geckodriver.log
View file @
22194bf0
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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