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
bb264c09
Commit
bb264c09
authored
4 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
test visibility of field from different study on the subject
parent
4c5e57c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!265
Resolve "configurable study fields"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
smash/web/tests/functions.py
+12
-10
12 additions, 10 deletions
smash/web/tests/functions.py
smash/web/tests/models/test_study_subject.py
+23
-1
23 additions, 1 deletion
smash/web/tests/models/test_study_subject.py
with
35 additions
and
11 deletions
smash/web/tests/functions.py
+
12
−
10
View file @
bb264c09
...
...
@@ -2,6 +2,7 @@ import datetime
import
logging
import
os
from
django.contrib.auth.models
import
Permission
from
django.contrib.auth.models
import
User
from
django.utils.timezone
import
make_aware
,
is_aware
...
...
@@ -14,7 +15,6 @@ from web.models.constants import REDCAP_TOKEN_CONFIGURATION_TYPE, REDCAP_BASE_UR
from
web.models.worker_study_role
import
ROLE_CHOICES_DOCTOR
,
WORKER_VOUCHER_PARTNER
from
web.redcap_connector
import
RedcapSubject
from
web.views.notifications
import
get_today_midnight_date
from
django.contrib.auth.models
import
Permission
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -70,7 +70,8 @@ def create_study(name="test"):
study_columns
=
StudyColumns
.
objects
.
create
()
notification_parameters
=
StudyNotificationParameters
.
objects
.
create
()
redcap_columns
=
StudyRedCapColumns
.
objects
.
create
()
return
Study
.
objects
.
create
(
name
=
name
,
columns
=
study_columns
,
notification_parameters
=
notification_parameters
,
redcap_columns
=
redcap_columns
)
return
Study
.
objects
.
create
(
name
=
name
,
columns
=
study_columns
,
notification_parameters
=
notification_parameters
,
redcap_columns
=
redcap_columns
)
TEST_ID_COUNTER
=
0
...
...
@@ -191,7 +192,7 @@ def create_subject():
)
def
create_study_subject
(
subject_id
=
1
,
subject
=
None
,
nd_number
=
'
ND0001
'
):
def
create_study_subject
(
subject_id
=
1
,
subject
=
None
,
nd_number
=
'
ND0001
'
)
->
StudySubject
:
if
subject
is
None
:
subject
=
create_subject
()
study_subject
=
StudySubject
.
objects
.
create
(
...
...
@@ -201,7 +202,7 @@ def create_study_subject(subject_id=1, subject=None, nd_number='ND0001'):
study
=
get_test_study
(),
subject
=
subject
)
if
nd_number
is
not
None
:
#
null value in column "nd_number" violates not-null constraint
if
nd_number
is
not
None
:
#
null value in column "nd_number" violates not-null constraint
study_subject
.
nd_number
=
nd_number
study_subject
.
save
()
...
...
@@ -242,12 +243,14 @@ def create_user(username=None, password=None):
create_worker
(
user
)
return
user
def
add_permissions_to_worker
(
worker
,
codenames
):
roles
=
WorkerStudyRole
.
objects
.
filter
(
worker
=
worker
,
study_id
=
GLOBAL_STUDY_ID
)
perms
=
Permission
.
objects
.
filter
(
codename__in
=
codenames
).
all
()
roles
=
WorkerStudyRole
.
objects
.
filter
(
worker
=
worker
,
study_id
=
GLOBAL_STUDY_ID
)
perms
=
Permission
.
objects
.
filter
(
codename__in
=
codenames
).
all
()
roles
[
0
].
permissions
.
set
(
perms
)
roles
[
0
].
save
()
def
create_worker
(
user
=
None
,
with_test_location
=
False
):
worker
=
Worker
.
objects
.
create
(
first_name
=
'
piotr
'
,
...
...
@@ -321,7 +324,7 @@ def create_appointment(visit=None, when=None, length=30):
make_aware
(
when_datetime
)
else
:
when_datetime
=
when
return
Appointment
.
objects
.
create
(
visit
=
visit
,
length
=
length
,
...
...
@@ -427,6 +430,5 @@ def datetimeify_date(date, timezone=datetime.timezone.utc):
"""
actual_type
=
str
(
type
(
date
))
raise
TypeError
(
"
Date should be either a subclass of
'
datetime.date
'
, string or bytes! But is: {} instead
"
.
format
(
actual_type
))
raise
TypeError
(
"
Date should be either a subclass of
'
datetime.date
'
, string or bytes! But is: {} instead
"
.
format
(
actual_type
))
This diff is collapsed.
Click to expand it.
smash/web/tests/models/test_study_subject.py
+
23
−
1
View file @
bb264c09
...
...
@@ -3,7 +3,7 @@ from django.test import TestCase
from
web.models
import
Appointment
,
Visit
,
StudySubject
,
Study
from
web.models.constants
import
CUSTOM_FIELD_TYPE_TEXT
from
web.models.custom_data
import
CustomStudySubjectField
from
web.tests.functions
import
create_visit
from
web.tests.functions
import
create_visit
,
create_study
from
web.tests.functions
import
get_test_study
,
create_study_subject
,
create_appointment
,
\
create_study_subject_with_multiple_screening_numbers
...
...
@@ -191,3 +191,25 @@ class SubjectModelTests(TestCase):
field
.
delete
()
self
.
assertEqual
(
0
,
len
(
subject
.
custom_data_values
))
def
test_subject_with_field_from_different_study
(
self
):
field
=
CustomStudySubjectField
.
objects
.
create
(
study
=
create_study
(
'
bla
'
),
type
=
CUSTOM_FIELD_TYPE_TEXT
)
subject
=
create_study_subject
()
self
.
assertIsNone
(
subject
.
get_custom_data_value
(
field
))
def
test_status
(
self
):
subject
=
create_study_subject
()
# noinspection PySetFunctionToLiteral
statuses
=
set
([
subject
.
status
,
])
subject
.
endpoint_reached
=
True
statuses
.
add
(
subject
.
status
)
subject
.
excluded
=
True
statuses
.
add
(
subject
.
status
)
subject
.
resigned
=
True
statuses
.
add
(
subject
.
status
)
subject
.
subject
.
dead
=
True
statuses
.
add
(
subject
.
status
)
print
(
statuses
)
self
.
assertEqual
(
5
,
len
(
statuses
))
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