Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMASCH
scheduling-system
Commits
4d308029
Commit
4d308029
authored
8 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
validation to visit dates added
parent
29187621
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
smash/web/forms.py
+5
-0
5 additions, 0 deletions
smash/web/forms.py
smash/web/tests/test_VisitAddForm.py
+34
-0
34 additions, 0 deletions
smash/web/tests/test_VisitAddForm.py
with
39 additions
and
0 deletions
smash/web/forms.py
+
5
−
0
View file @
4d308029
...
@@ -151,3 +151,8 @@ class VisitAddForm(ModelForm):
...
@@ -151,3 +151,8 @@ class VisitAddForm(ModelForm):
class
Meta
:
class
Meta
:
model
=
Visit
model
=
Visit
exclude
=
[
'
is_finished
'
]
exclude
=
[
'
is_finished
'
]
def
clean
(
self
):
if
(
self
.
cleaned_data
[
'
datetime_begin
'
]
>=
self
.
cleaned_data
[
'
datetime_end
'
]):
self
.
add_error
(
'
datetime_begin
'
,
"
Start date must be before end date
"
)
self
.
add_error
(
'
datetime_end
'
,
"
Start date must be before end date
"
)
This diff is collapsed.
Click to expand it.
smash/web/tests/test_VisitAddForm.py
0 → 100644
+
34
−
0
View file @
4d308029
from
django.test
import
TestCase
from
web.forms
import
SubjectAddForm
from
web.forms
import
VisitAddForm
from
web.models
import
Subject
from
web.models
import
Visit
class
SubjectAddFormTests
(
TestCase
):
def
setUp
(
self
):
subject_data
=
{
'
first_name
'
:
'
name
'
,
'
last_name
'
:
'
name
'
,
'
status
'
:
Subject
.
STATUS_CHOICES_NOT_CONTACTED
,
'
sex
'
:
Subject
.
SEX_CHOICES_MALE
,
'
country
'
:
'
Luxembourg
'
,
}
self
.
subject
=
SubjectAddForm
(
data
=
subject_data
).
save
()
self
.
sample_data
=
{
'
datetime_begin
'
:
"
2017-01-01
"
,
'
datetime_end
'
:
"
2017-02-02
"
,
'
visit_type
'
:
Visit
.
TYPE_CHOICES_OTHER
,
'
subject
'
:
self
.
subject
.
id
}
def
test_validation
(
self
):
form
=
VisitAddForm
(
data
=
self
.
sample_data
)
self
.
assertTrue
(
form
.
is_valid
())
def
test_invalid_validation
(
self
):
self
.
sample_data
[
'
datetime_begin
'
]
=
"
2017-02-02
"
self
.
sample_data
[
'
datetime_end
'
]
=
"
2017-01-01
"
form
=
VisitAddForm
(
data
=
self
.
sample_data
)
validation_status
=
form
.
is_valid
()
self
.
assertFalse
(
validation_status
)
self
.
assertTrue
(
"
datetime_begin
"
in
form
.
errors
)
self
.
assertTrue
(
"
datetime_end
"
in
form
.
errors
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment