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
f793badf
Commit
f793badf
authored
7 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
unit tests for voucher views
parent
7c27133b
No related branches found
No related tags found
1 merge request
!113
Resolve "voucher functionality"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
smash/web/forms/forms.py
+1
-1
1 addition, 1 deletion
smash/web/forms/forms.py
smash/web/tests/functions.py
+3
-2
3 additions, 2 deletions
smash/web/tests/functions.py
smash/web/tests/view/test_voucher.py
+54
-0
54 additions, 0 deletions
smash/web/tests/view/test_voucher.py
with
58 additions
and
3 deletions
smash/web/forms/forms.py
+
1
−
1
View file @
f793badf
...
...
@@ -443,7 +443,7 @@ class VoucherForm(ModelForm):
instance
.
issue_date
=
timezone
.
now
()
instance
.
expiry_date
=
instance
.
issue_date
+
datetime
.
timedelta
(
days
=
92
)
max_id
=
str
(
0
).
zfill
(
5
)
if
Voucher
.
objects
.
latest
(
'
id
'
)
:
if
Voucher
.
objects
.
all
().
count
()
>
0
:
max_id
=
str
(
Voucher
.
objects
.
latest
(
'
id
'
).
id
).
zfill
(
5
)
instance
.
number
=
max_id
+
VerhoeffAlgorithm
.
calculate_verhoeff_check_sum
(
max_id
)
if
instance
.
status
==
VOUCHER_STATUS_USED
and
not
instance
.
use_date
:
...
...
This diff is collapsed.
Click to expand it.
smash/web/tests/functions.py
+
3
−
2
View file @
f793badf
...
...
@@ -9,7 +9,7 @@ from web.models import Location, AppointmentType, StudySubject, Worker, Visit, A
VoucherType
,
VoucherTypePrice
,
Voucher
from
web.models.constants
import
REDCAP_TOKEN_CONFIGURATION_TYPE
,
REDCAP_BASE_URL_CONFIGURATION_TYPE
,
\
SEX_CHOICES_MALE
,
SUBJECT_TYPE_CHOICES_CONTROL
,
CONTACT_TYPES_PHONE
,
\
MONDAY_AS_DAY_OF_WEEK
,
COUNTRY_AFGHANISTAN_ID
MONDAY_AS_DAY_OF_WEEK
,
COUNTRY_AFGHANISTAN_ID
,
VOUCHER_STATUS_NEW
from
web.redcap_connector
import
RedcapSubject
from
web.views.notifications
import
get_today_midnight_date
...
...
@@ -74,7 +74,8 @@ def create_voucher(study_subject=None):
study_subject
=
study_subject
,
issue_date
=
get_today_midnight_date
(),
expiry_date
=
get_today_midnight_date
(),
voucher_type
=
create_voucher_type
())
voucher_type
=
create_voucher_type
(),
status
=
VOUCHER_STATUS_NEW
)
def
create_empty_notification_parameters
():
...
...
This diff is collapsed.
Click to expand it.
smash/web/tests/view/test_voucher.py
0 → 100644
+
54
−
0
View file @
f793badf
import
logging
from
django.urls
import
reverse
from
web.forms.forms
import
VoucherForm
from
web.models
import
Voucher
from
web.models.constants
import
VOUCHER_STATUS_NEW
from
web.tests.functions
import
create_voucher
,
create_study_subject
,
format_form_field
,
create_voucher_type
from
..
import
LoggedInTestCase
logger
=
logging
.
getLogger
(
__name__
)
class
VoucherTypeViewTests
(
LoggedInTestCase
):
def
test_render_add_voucher_request
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'
web.views.voucher_add
'
))
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_render_edit_voucher_request
(
self
):
voucher
=
create_voucher
()
response
=
self
.
client
.
get
(
reverse
(
'
web.views.voucher_edit
'
,
kwargs
=
{
'
pk
'
:
voucher
.
id
}))
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_add_voucher
(
self
):
study_subject
=
create_study_subject
()
visit_detail_form
=
VoucherForm
()
form_data
=
{
"
status
"
:
VOUCHER_STATUS_NEW
,
"
voucher_type
"
:
create_voucher_type
().
id
}
for
key
,
value
in
visit_detail_form
.
initial
.
items
():
form_data
[
key
]
=
format_form_field
(
value
)
url
=
reverse
(
'
web.views.voucher_add
'
)
+
'
?study_subject_id=
'
+
str
(
study_subject
.
id
)
response
=
self
.
client
.
post
(
url
,
data
=
form_data
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
1
,
Voucher
.
objects
.
all
().
count
())
def
test_edit_voucher
(
self
):
voucher
=
create_voucher
()
voucher_form
=
VoucherForm
(
instance
=
voucher
)
form_data
=
{}
for
key
,
value
in
voucher_form
.
initial
.
items
():
form_data
[
key
]
=
format_form_field
(
value
)
form_data
[
"
usage_partner
"
]
=
""
form_data
[
"
use_date
"
]
=
""
url
=
reverse
(
'
web.views.voucher_edit
'
,
kwargs
=
{
'
pk
'
:
voucher
.
id
})
response
=
self
.
client
.
post
(
url
,
data
=
form_data
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
1
,
Voucher
.
objects
.
all
().
count
())
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