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
531324ce
There was a problem fetching the pipeline metadata.
Commit
531324ce
authored
7 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
unit tests for voucher_type_price views
parent
f6f913ec
No related branches found
No related tags found
1 merge request
!112
Resolve "voucher types"
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
smash/web/tests/functions.py
+11
-2
11 additions, 2 deletions
smash/web/tests/functions.py
smash/web/tests/view/test_voucher_type_price.py
+58
-0
58 additions, 0 deletions
smash/web/tests/view/test_voucher_type_price.py
with
69 additions
and
2 deletions
smash/web/tests/functions.py
+
11
−
2
View file @
531324ce
...
@@ -6,7 +6,7 @@ from django.contrib.auth.models import User
...
@@ -6,7 +6,7 @@ from django.contrib.auth.models import User
from
web.models
import
Location
,
AppointmentType
,
StudySubject
,
Worker
,
Visit
,
Appointment
,
ConfigurationItem
,
\
from
web.models
import
Location
,
AppointmentType
,
StudySubject
,
Worker
,
Visit
,
Appointment
,
ConfigurationItem
,
\
Language
,
ContactAttempt
,
FlyingTeam
,
Availability
,
Subject
,
Study
,
StudyColumns
,
StudyNotificationParameters
,
\
Language
,
ContactAttempt
,
FlyingTeam
,
Availability
,
Subject
,
Study
,
StudyColumns
,
StudyNotificationParameters
,
\
VoucherType
VoucherType
,
VoucherTypePrice
from
web.models.constants
import
REDCAP_TOKEN_CONFIGURATION_TYPE
,
REDCAP_BASE_URL_CONFIGURATION_TYPE
,
\
from
web.models.constants
import
REDCAP_TOKEN_CONFIGURATION_TYPE
,
REDCAP_BASE_URL_CONFIGURATION_TYPE
,
\
SEX_CHOICES_MALE
,
SUBJECT_TYPE_CHOICES_CONTROL
,
CONTACT_TYPES_PHONE
,
\
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
...
@@ -31,6 +31,13 @@ def create_voucher_type():
...
@@ -31,6 +31,13 @@ def create_voucher_type():
return
VoucherType
.
objects
.
create
(
code
=
"
X
"
,
study
=
get_test_study
())
return
VoucherType
.
objects
.
create
(
code
=
"
X
"
,
study
=
get_test_study
())
def
create_voucher_type_price
():
return
VoucherTypePrice
.
objects
.
create
(
voucher_type
=
create_voucher_type
(),
price
=
12.34
,
start_date
=
get_today_midnight_date
(),
end_date
=
get_today_midnight_date
())
def
create_empty_study_columns
():
def
create_empty_study_columns
():
study_columns
=
StudyColumns
.
objects
.
create
(
study_columns
=
StudyColumns
.
objects
.
create
(
postponed
=
False
,
postponed
=
False
,
...
@@ -238,7 +245,9 @@ def get_resource_path(filename):
...
@@ -238,7 +245,9 @@ def get_resource_path(filename):
def
format_form_field
(
value
):
def
format_form_field
(
value
):
if
isinstance
(
value
,
datetime
.
datetime
):
if
isinstance
(
value
,
datetime
.
date
):
return
value
.
strftime
(
'
%Y-%m-%d
'
)
elif
isinstance
(
value
,
datetime
.
datetime
):
return
value
.
strftime
(
'
%Y-%m-%d %H:%M
'
)
return
value
.
strftime
(
'
%Y-%m-%d %H:%M
'
)
else
:
else
:
return
value
return
value
...
...
This diff is collapsed.
Click to expand it.
smash/web/tests/view/test_voucher_type_price.py
0 → 100644
+
58
−
0
View file @
531324ce
import
logging
from
django.urls
import
reverse
from
web.forms.forms
import
VoucherTypePriceForm
from
web.models
import
VoucherType
,
VoucherTypePrice
from
web.tests.functions
import
create_voucher_type
,
create_voucher_type_price
,
format_form_field
from
..
import
LoggedInTestCase
logger
=
logging
.
getLogger
(
__name__
)
class
VoucherTypePriceViewTests
(
LoggedInTestCase
):
def
setUp
(
self
):
super
(
VoucherTypePriceViewTests
,
self
).
setUp
()
self
.
voucher_type
=
create_voucher_type
()
def
test_render_add_voucher_type_price_request
(
self
):
url
=
reverse
(
'
web.views.voucher_type_price_add
'
,
kwargs
=
{
'
voucher_type_id
'
:
self
.
voucher_type
.
id
})
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_render_edit_voucher_type_price_request
(
self
):
voucher_type_price
=
create_voucher_type_price
()
url
=
reverse
(
'
web.views.voucher_type_price_edit
'
,
kwargs
=
{
'
pk
'
:
voucher_type_price
.
id
,
'
voucher_type_id
'
:
self
.
voucher_type
.
id
})
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_add_voucher_type_price
(
self
):
form_data
=
{
'
price
'
:
"
11.0
"
,
'
start_date
'
:
"
2017-01-01
"
,
'
end_date
'
:
"
2018-01-01
"
}
url
=
reverse
(
'
web.views.voucher_type_price_add
'
,
kwargs
=
{
'
voucher_type_id
'
:
self
.
voucher_type
.
id
})
response
=
self
.
client
.
post
(
url
,
data
=
form_data
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
1
,
VoucherType
.
objects
.
all
().
count
())
def
test_edit_voucher_type_price
(
self
):
voucher_type_price
=
create_voucher_type_price
()
form
=
VoucherTypePriceForm
(
instance
=
voucher_type_price
)
form_data
=
{}
for
key
,
value
in
form
.
initial
.
items
():
if
value
is
not
None
:
form_data
[
'
{}
'
.
format
(
key
)]
=
format_form_field
(
value
)
form_data
[
'
price
'
]
=
90.50
url
=
reverse
(
'
web.views.voucher_type_price_edit
'
,
kwargs
=
{
'
pk
'
:
voucher_type_price
.
id
,
'
voucher_type_id
'
:
voucher_type_price
.
voucher_type
.
id
})
response
=
self
.
client
.
post
(
url
,
data
=
form_data
)
self
.
assertEqual
(
90.50
,
VoucherTypePrice
.
objects
.
get
(
id
=
voucher_type_price
.
id
).
price
)
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