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
29736e9f
Commit
29736e9f
authored
Sep 24, 2019
by
Kevin Albert Simanjuntak
Browse files
Model for list Items and associated migration
parent
43acb640
Pipeline
#20586
passed with stage
in 1 minute and 7 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
db.sqlite3
View file @
29736e9f
No preview for this file type
lists/__pycache__/models.cpython-37.pyc
View file @
29736e9f
No preview for this file type
lists/__pycache__/tests.cpython-37.pyc
View file @
29736e9f
No preview for this file type
lists/migrations/0001_initial.py
0 → 100644
View file @
29736e9f
# Generated by Django 2.0 on 2019-09-24 15:43
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
initial
=
True
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Item'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
],
),
]
lists/migrations/0002_item_text.py
0 → 100644
View file @
29736e9f
# Generated by Django 2.0 on 2019-09-24 15:46
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'lists'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'item'
,
name
=
'text'
,
field
=
models
.
TextField
(
default
=
''
),
),
]
lists/models.py
View file @
29736e9f
from
django.db
import
models
# Create your models here.
class
Item
(
models
.
Model
):
text
=
models
.
TextField
(
default
=
''
)
\ No newline at end of file
lists/tests.py
View file @
29736e9f
...
...
@@ -4,6 +4,7 @@ from django.http import HttpRequest
from
django.test
import
Client
from
lists.views
import
home_page
from
django.template.loader
import
render_to_string
from
lists.models
import
Item
class
HomePageTest
(
TestCase
):
def
test_home_page_returns_correct_html
(
self
):
...
...
@@ -25,4 +26,23 @@ class HomePageTest(TestCase):
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
self
.
assertTemplateUsed
(
response
,
'home.html'
)
class
ItemModelTest
(
TestCase
):
def
test_saving_and_retrieving_items
(
self
):
first_item
=
Item
()
first_item
.
text
=
'The first (ever) list item'
first_item
.
save
()
second_item
=
Item
()
second_item
.
text
=
'Item the second'
second_item
.
save
()
saved_items
=
Item
.
objects
.
all
()
self
.
assertEqual
(
saved_items
.
count
(),
2
)
first_saved_item
=
saved_items
[
0
]
second_saved_item
=
saved_items
[
1
]
self
.
assertEqual
(
first_saved_item
.
text
,
'The first (ever) list item'
)
self
.
assertEqual
(
second_saved_item
.
text
,
'Item the second'
)
\ 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