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
724e90b5
There was a problem fetching the pipeline metadata.
Commit
724e90b5
authored
7 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
unit tests for expire voucher cron job
parent
41af46a4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!120
Resolve "auto-expire of vouchers"
Pipeline
#
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
smash/web/tests/functions.py
+13
-2
13 additions, 2 deletions
smash/web/tests/functions.py
smash/web/tests/view/test_voucher.py
+26
-1
26 additions, 1 deletion
smash/web/tests/view/test_voucher.py
smash/web/views/voucher.py
+2
-2
2 additions, 2 deletions
smash/web/views/voucher.py
with
41 additions
and
5 deletions
smash/web/tests/functions.py
+
13
−
2
View file @
724e90b5
...
...
@@ -4,13 +4,13 @@ import os
from
django.contrib.auth.models
import
User
from
web.models.worker_study_role
import
ROLE_CHOICES_DOCTOR
from
web.models
import
Location
,
AppointmentType
,
StudySubject
,
Worker
,
Visit
,
Appointment
,
ConfigurationItem
,
\
Language
,
ContactAttempt
,
FlyingTeam
,
Availability
,
Subject
,
Study
,
StudyColumns
,
StudyNotificationParameters
,
\
VoucherType
,
VoucherTypePrice
,
Voucher
,
WorkerStudyRole
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
,
VOUCHER_STATUS_NEW
,
GLOBAL_STUDY_ID
from
web.models.worker_study_role
import
ROLE_CHOICES_DOCTOR
from
web.redcap_connector
import
RedcapSubject
from
web.views.notifications
import
get_today_midnight_date
...
...
@@ -68,10 +68,21 @@ def create_study(name="test"):
return
Study
.
objects
.
create
(
name
=
name
,
columns
=
study_columns
,
notification_parameters
=
notification_parameters
)
TEST_ID_COUNTER
=
0
def
get_test_id
():
global
TEST_ID_COUNTER
result
=
str
(
TEST_ID_COUNTER
)
TEST_ID_COUNTER
+=
1
return
result
def
create_voucher
(
study_subject
=
None
):
if
study_subject
is
None
:
study_subject
=
create_study_subject
()
return
Voucher
.
objects
.
create
(
number
=
"
123456
"
,
number
=
str
(
get_test_id
())
return
Voucher
.
objects
.
create
(
number
=
number
,
study_subject
=
study_subject
,
issue_date
=
get_today_midnight_date
(),
expiry_date
=
get_today_midnight_date
(),
...
...
This diff is collapsed.
Click to expand it.
smash/web/tests/view/test_voucher.py
+
26
−
1
View file @
724e90b5
import
logging
import
datetime
from
django.urls
import
reverse
from
web.views.notifications
import
get_today_midnight_date
from
web.views.voucher
import
ExpireVouchersJob
from
web.forms
import
VoucherForm
from
web.models
import
Voucher
from
web.models.constants
import
VOUCHER_STATUS_NEW
from
web.models.constants
import
VOUCHER_STATUS_NEW
,
VOUCHER_STATUS_USED
,
VOUCHER_STATUS_EXPIRED
from
web.tests.functions
import
create_voucher
,
create_study_subject
,
format_form_field
,
create_voucher_type
from
..
import
LoggedInTestCase
...
...
@@ -56,3 +59,25 @@ class VoucherTypeViewTests(LoggedInTestCase):
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
1
,
Voucher
.
objects
.
all
().
count
())
def
test_expire_voucher_cron_job
(
self
):
voucher
=
create_voucher
()
voucher
.
status
=
VOUCHER_STATUS_NEW
voucher
.
expiry_date
=
"
2011-01-01
"
voucher
.
save
()
status
=
ExpireVouchersJob
().
do
()
self
.
assertTrue
(
"
1
"
in
status
)
updated_voucher
=
Voucher
.
objects
.
get
(
id
=
voucher
.
id
)
self
.
assertEqual
(
VOUCHER_STATUS_EXPIRED
,
updated_voucher
.
status
)
def
test_expire_voucher_cron_job_with_no_vouchers_to_update
(
self
):
voucher
=
create_voucher
()
voucher
.
status
=
VOUCHER_STATUS_USED
voucher
.
expiry_date
=
"
2011-01-01
"
voucher
.
save
()
voucher
=
create_voucher
()
voucher
.
status
=
VOUCHER_STATUS_NEW
voucher
.
expiry_date
=
get_today_midnight_date
()
+
datetime
.
timedelta
(
days
=
2
)
voucher
.
save
()
status
=
ExpireVouchersJob
().
do
()
self
.
assertTrue
(
"
0
"
in
status
)
This diff is collapsed.
Click to expand it.
smash/web/views/voucher.py
+
2
−
2
View file @
724e90b5
...
...
@@ -8,7 +8,7 @@ from django.views.generic import ListView
from
django.views.generic
import
UpdateView
from
django_cron
import
CronJobBase
,
Schedule
from
views.notifications
import
get_today_midnight_date
from
web.
views.notifications
import
get_today_midnight_date
from
web.forms
import
VoucherForm
from
web.models
import
Voucher
,
StudySubject
from
web.models.constants
import
GLOBAL_STUDY_ID
,
VOUCHER_STATUS_NEW
,
VOUCHER_STATUS_EXPIRED
...
...
@@ -80,4 +80,4 @@ class ExpireVouchersJob(CronJobBase):
count
=
vouchers
.
count
()
if
count
>
0
:
vouchers
.
update
(
status
=
VOUCHER_STATUS_EXPIRED
)
return
count
+
"
vouchers expired
"
return
str
(
count
)
+
"
vouchers expired
"
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