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
1506722720-practice
Commits
73bdbf40
Commit
73bdbf40
authored
Sep 17, 2019
by
Dwi Nanda Susanto
Browse files
Basic view now returns minimal HTML
parent
3aa2244b
Changes
3
Hide whitespace changes
Inline
Side-by-side
functional_tests.py
View file @
73bdbf40
...
...
@@ -10,7 +10,7 @@ class NewVisitorTest(unittest.TestCase):
# to check out its homepage
self
.
browser
.
get
(
'http://localhost:8000'
)
# She notices the page title and header mention to-do lists
self
.
assertIn
(
'To
Do'
,
self
.
browser
.
title
)
self
.
assertIn
(
'To
-
Do'
,
self
.
browser
.
title
)
self
.
fail
(
'Finish the test!'
)
# She is invited to enter a to-do item straight away
# [...rest of comments as before]
...
...
lists/tests.py
View file @
73bdbf40
from
django.urls
import
resolve
from
django.test
import
TestCase
from
django.http
import
HttpRequest
from
lists.views
import
home_page
class
HomePageTest
(
TestCase
):
def
test_root_url_resolves_to_home_page_view
(
self
):
found
=
resolve
(
'/'
)
self
.
assertEqual
(
found
.
func
,
home_page
)
\ No newline at end of file
self
.
assertEqual
(
found
.
func
,
home_page
)
def
test_home_page_returns_correct_html
(
self
):
request
=
HttpRequest
()
response
=
home_page
(
request
)
html
=
response
.
content
.
decode
(
'utf8'
)
self
.
assertTrue
(
html
.
startswith
(
'<html>'
))
self
.
assertIn
(
'<title>To-Do lists</title>'
,
html
)
self
.
assertTrue
(
html
.
endswith
(
'</html>'
))
\ No newline at end of file
lists/views.py
View file @
73bdbf40
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
# Create your views here.
def
home_page
():
pass
\ No newline at end of file
def
home_page
(
req
):
return
HttpResponse
(
'<html><title>To-Do lists</title></html>'
)
\ No newline at end of file
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