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
1dc1a740
Commit
1dc1a740
authored
Jul 17, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: unit test book loans
parent
91591bbd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
tests.py
loans/tests.py
+49
-0
No files found.
loans/tests.py
View file @
1dc1a740
from
django.test
import
TestCase
from
django.utils
import
timezone
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
from
.models
import
BookLoan
,
Book
,
Member
class
BookLoanModelTest
(
TestCase
):
def
setUp
(
self
):
self
.
book
=
Book
.
objects
.
create
(
title
=
"Test Book"
,
author
=
"Test Author"
,
publish_date
=
timezone
.
now
(),
rating
=
5
,
)
self
.
user
=
User
.
objects
.
create_user
(
username
=
"Test User"
,
password
=
"secret"
,
is_staff
=
False
)
self
.
member
=
Member
.
objects
.
create
(
user
=
self
.
user
)
self
.
loan_date
=
timezone
.
now
()
self
.
due_date
=
self
.
loan_date
+
timezone
.
timedelta
(
days
=
14
)
def
test_book_loan_creation
(
self
):
book_loan
=
BookLoan
.
objects
.
create
(
book
=
self
.
book
,
member
=
self
.
member
,
loan_date
=
self
.
loan_date
,
due_date
=
self
.
due_date
,
)
self
.
assertEqual
(
book_loan
.
book
,
self
.
book
)
self
.
assertEqual
(
book_loan
.
member
,
self
.
member
)
self
.
assertEqual
(
book_loan
.
due_date
,
self
.
due_date
)
def
test_cascading_delete
(
self
):
book_loan
=
BookLoan
.
objects
.
create
(
book
=
self
.
book
,
member
=
self
.
member
,
loan_date
=
self
.
loan_date
,
due_date
=
self
.
due_date
,
)
book_loan_id
=
book_loan
.
id
self
.
book
.
delete
()
with
self
.
assertRaises
(
BookLoan
.
DoesNotExist
):
BookLoan
.
objects
.
get
(
id
=
book_loan_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