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
1606876052-practice
Commits
fb4be1c0
Commit
fb4be1c0
authored
Sep 25, 2019
by
Rayza Arasj Mahardhika
Browse files
Exercise/personal commentary
parent
cd4c7d2f
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
fb4be1c0
...
...
@@ -11,8 +11,6 @@ Deployment:
-
dpl --provider=heroku --app=$HEROKU_APPNAME --api-key=$HEROKU_APIKEY
-
export HEROKU_API_KEY=$HEROKU_APIKEY
-
heroku run --app $HEROKU_APPNAME migrate
-
heroku run bash
-
./manage.py migrate
environment
:
name
:
production
url
:
$HEROKU_APP_HOST
...
...
lists/templates/home.html
View file @
fb4be1c0
...
...
@@ -14,5 +14,7 @@
<tr><td>
{{ forloop.counter }}: {{ item.text }}
</td></tr>
{% endfor %}
</table>
<p>
{{ commentary }}
</p>
</body>
</html>
lists/tests.py
View file @
fb4be1c0
...
...
@@ -2,7 +2,8 @@ from django.urls import resolve, reverse
from
django.test
import
TestCase
from
django.http
import
HttpRequest
from
lists.views
import
home_page
,
about_page
from
lists.views
import
home_page
,
about_page
,
\
COMMENTARY_ZERO
,
COMMENTARY_LESS_THAN_FIVE
,
COMMENTARY_MORE_THAN_EQUAL_FIVE
from
lists.models
import
Item
class
HomePageTest
(
TestCase
):
...
...
@@ -41,6 +42,19 @@ class HomePageTest(TestCase):
self
.
assertIn
(
'itemey 1'
,
response
.
content
.
decode
())
self
.
assertIn
(
'itemey 2'
,
response
.
content
.
decode
())
def
test_display_correct_personal_commentary
(
self
):
cases
=
[
(
0
,
COMMENTARY_ZERO
),
(
4
,
COMMENTARY_LESS_THAN_FIVE
),
(
5
,
COMMENTARY_MORE_THAN_EQUAL_FIVE
)
]
for
item_count
,
commentary
in
cases
:
for
i
in
range
(
item_count
):
Item
.
objects
.
create
(
text
=
'itemey {}'
.
format
(
i
))
response
=
self
.
client
.
get
(
'/'
)
self
.
assertIn
(
commentary
,
response
.
content
.
decode
())
class
AboutPageTest
(
TestCase
):
def
test_about_url_resolves_to_about_page_view
(
self
):
...
...
lists/views.py
View file @
fb4be1c0
...
...
@@ -3,13 +3,25 @@ from django.shortcuts import redirect, render
from
lists.models
import
Item
COMMENTARY_ZERO
=
'yey, waktunya berlibur'
COMMENTARY_LESS_THAN_FIVE
=
'sibuk tapi santai'
COMMENTARY_MORE_THAN_EQUAL_FIVE
=
'oh tidak'
def
get_commentary
(
item_count
):
if
(
item_count
==
0
):
return
COMMENTARY_ZERO
elif
(
item_count
<
5
):
return
COMMENTARY_LESS_THAN_FIVE
elif
(
item_count
>=
5
):
return
COMMENTARY_MORE_THAN_EQUAL_FIVE
def
home_page
(
request
):
if
request
.
method
==
'POST'
:
Item
.
objects
.
create
(
text
=
request
.
POST
[
'item_text'
])
return
redirect
(
'/'
)
items
=
Item
.
objects
.
all
()
return
render
(
request
,
'home.html'
,
{
'items'
:
items
})
return
render
(
request
,
'home.html'
,
{
'items'
:
items
,
'commentary'
:
get_commentary
(
len
(
items
))
})
def
about_page
(
request
):
return
HttpResponse
(
...
...
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