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
Class Project
DIGIPUS
Commits
2a519108
Commit
2a519108
authored
Oct 31, 2020
by
Ahmad Fauzan Amirul Isnain
Browse files
[
#132
] QA: Add Tests for PeriodForm Validation
parent
bb5a2dfd
Changes
2
Hide whitespace changes
Inline
Side-by-side
administration/tests.py
View file @
2a519108
...
...
@@ -10,7 +10,9 @@ from app.models import Category, Materi, LaporanMateri
from
authentication.models
import
User
from
bs4
import
BeautifulSoup
from
datetime
import
datetime
from
datetime
import
datetime
,
timedelta
from
.forms
import
PeriodForm
EDIT_ENDPOINT
=
"/edit"
ERROR_403_MESSAGE
=
'Kamu harus login untuk mengakses halaman ini'
...
...
@@ -1659,3 +1661,50 @@ class EditKontributorStatusTests(TestCase):
self
.
assertEqual
(
response
.
status_code
,
403
)
class
PeriodFormTests
(
TestCase
):
def
test_validation_error_when_start_date_is_none
(
self
):
data
=
{
'start_date'
:
None
,
'end_date'
:
datetime
.
now
(),
}
form
=
PeriodForm
(
data
)
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertEqual
(
form
[
"start_date"
].
errors
,
[
'masukan waktu mulai'
]
)
def
test_validation_error_when_end_date_is_none
(
self
):
data
=
{
'start_date'
:
datetime
.
now
(),
'end_date'
:
None
,
}
form
=
PeriodForm
(
data
)
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertEqual
(
form
[
"end_date"
].
errors
,
[
'masukan waktu selesai'
]
)
def
test_validation_error_when_start_date_greater_than_end_date
(
self
):
current_time
=
datetime
.
now
()
data
=
{
'start_date'
:
current_time
+
timedelta
(
days
=
1
),
'end_date'
:
current_time
,
}
form
=
PeriodForm
(
data
)
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertEqual
(
form
[
"end_date"
].
errors
,
[
'waktu selesai sebelum waktu mulai'
]
)
def
test_form_valid_when_data_valid
(
self
):
current_time
=
datetime
.
now
()
data
=
{
'start_date'
:
current_time
-
timedelta
(
days
=
1
),
'end_date'
:
current_time
,
}
form
=
PeriodForm
(
data
)
self
.
assertTrue
(
form
.
is_valid
())
digipus/__pycache__/settings.cpython-36.pyc
View file @
2a519108
No preview for this file type
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