Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
library-app-django
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ilham Maulana
library-app-django
Commits
40b62c33
Commit
40b62c33
authored
Jul 17, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: unit test book
parent
1dc1a740
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
1 deletion
+62
-1
tests.py
book/tests.py
+62
-1
No files found.
book/tests.py
View file @
40b62c33
from
django.test
import
TestCase
from
django.utils
import
timezone
from
django.core.exceptions
import
ValidationError
# Create your tests here.
from
.models
import
Category
,
Book
class
CategoryModelTest
(
TestCase
):
def
setUp
(
self
):
self
.
category
=
Category
.
objects
.
create
(
name
=
"Test Category"
)
def
test_category_creation
(
self
):
self
.
assertEqual
(
self
.
category
.
name
,
"Test Category"
)
def
test_category_update
(
self
):
self
.
category
.
name
=
"Test Category Update"
self
.
category
.
save
()
self
.
assertEqual
(
self
.
category
.
name
,
"Test Category Update"
)
def
test_delete_category
(
self
):
category
=
Category
.
objects
.
create
(
name
=
"Test Delete Category"
)
category
.
delete
()
with
self
.
assertRaises
(
Category
.
DoesNotExist
):
Category
.
objects
.
get
(
id
=
category
.
id
)
class
BookModelTest
(
TestCase
):
def
setUp
(
self
):
self
.
category
=
Category
.
objects
.
create
(
name
=
"Test Category"
)
self
.
book
=
Book
.
objects
.
create
(
title
=
"Test Book"
,
author
=
"Test Author"
,
publish_date
=
timezone
.
now
(),
rating
=
3
,
isbn
=
"1234567890123"
,
category
=
self
.
category
,
)
def
test_book_creation
(
self
):
self
.
assertEqual
(
self
.
book
.
title
,
"Test Book"
)
self
.
assertEqual
(
self
.
book
.
author
,
"Test Author"
)
self
.
assertEqual
(
self
.
book
.
rating
,
3
)
self
.
assertEqual
(
self
.
book
.
isbn
,
"1234567890123"
)
self
.
assertEqual
(
self
.
book
.
category
,
self
.
category
)
def
test_book_update
(
self
):
self
.
book
.
title
=
"Test Book Update"
self
.
book
.
save
()
self
.
assertEqual
(
self
.
book
.
title
,
"Test Book Update"
)
def
test_delete_book
(
self
):
book
=
Book
.
objects
.
create
(
title
=
"Test Book 2"
,
author
=
"Test Author 2"
,
publish_date
=
timezone
.
now
(),
rating
=
3
,
isbn
=
"2234567890123"
,
)
book
.
delete
()
with
self
.
assertRaises
(
Book
.
DoesNotExist
):
Book
.
objects
.
get
(
id
=
book
.
id
)
Write
Preview
Markdown
is supported
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