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
8f7d2b7f
There was a problem fetching the pipeline metadata.
Commit
8f7d2b7f
authored
7 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
test for subjects api
parent
b8e0d183
No related branches found
No related tags found
1 merge request
!34
Performance of subject list
Pipeline
#
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
smash/web/api_views.py
+34
-31
34 additions, 31 deletions
smash/web/api_views.py
smash/web/tests/functions.py
+9
-2
9 additions, 2 deletions
smash/web/tests/functions.py
smash/web/tests/test_api.py
+39
-1
39 additions, 1 deletion
smash/web/tests/test_api.py
with
82 additions
and
34 deletions
smash/web/api_views.py
+
34
−
31
View file @
8f7d2b7f
...
...
@@ -2,6 +2,7 @@ from django.contrib.auth.decorators import login_required
from
django.http
import
JsonResponse
from
models
import
Subject
,
Worker
,
AppointmentType
,
Location
from
views
import
e500_error
from
views.subject
import
SUBJECT_LIST_GENERIC
,
SUBJECT_LIST_NO_VISIT
,
SUBJECT_LIST_REQUIRE_CONTACT
from
views.notifications
import
get_subjects_with_no_visit
,
get_subjects_with_reminder
...
...
@@ -126,46 +127,48 @@ def get_subjects_filtered(subjects, filters):
@login_required
def
subjects
(
request
,
type
):
# id of the query from dataTable: https://datatables.net/manual/server-side
draw
=
int
(
request
.
GET
.
get
(
"
draw
"
,
"
-1
"
))
try
:
# id of the query from dataTable: https://datatables.net/manual/server-side
draw
=
int
(
request
.
GET
.
get
(
"
draw
"
,
"
-1
"
))
start
=
int
(
request
.
GET
.
get
(
"
start
"
,
"
0
"
))
length
=
int
(
request
.
GET
.
get
(
"
length
"
,
"
10
"
))
order
=
int
(
request
.
GET
.
get
(
"
order[0][column]
"
,
"
0
"
))
order_dir
=
request
.
GET
.
get
(
"
order[0][dir]
"
,
"
asc
"
)
order_column
=
request
.
GET
.
get
(
"
columns[
"
+
str
(
order
)
+
"
][data]
"
,
"
last_name
"
)
start
=
int
(
request
.
GET
.
get
(
"
start
"
,
"
0
"
))
length
=
int
(
request
.
GET
.
get
(
"
length
"
,
"
10
"
))
order
=
int
(
request
.
GET
.
get
(
"
order[0][column]
"
,
"
0
"
))
order_dir
=
request
.
GET
.
get
(
"
order[0][dir]
"
,
"
asc
"
)
order_column
=
request
.
GET
.
get
(
"
columns[
"
+
str
(
order
)
+
"
][data]
"
,
"
last_name
"
)
filters
=
[]
column_id
=
0
while
request
.
GET
.
get
(
"
columns[
"
+
str
(
column_id
)
+
"
][search][value]
"
,
"
unknown
"
)
!=
"
unknown
"
:
val
=
request
.
GET
.
get
(
"
columns[
"
+
str
(
column_id
)
+
"
][search][value]
"
,
"
unknown
"
)
if
val
!=
""
:
filters
.
append
([
request
.
GET
.
get
(
"
columns[
"
+
str
(
column_id
)
+
"
][data]
"
),
val
])
column_id
+=
1
filters
=
[]
column_id
=
0
while
request
.
GET
.
get
(
"
columns[
"
+
str
(
column_id
)
+
"
][search][value]
"
,
"
unknown
"
)
!=
"
unknown
"
:
val
=
request
.
GET
.
get
(
"
columns[
"
+
str
(
column_id
)
+
"
][search][value]
"
,
"
unknown
"
)
if
val
!=
""
:
filters
.
append
([
request
.
GET
.
get
(
"
columns[
"
+
str
(
column_id
)
+
"
][data]
"
),
val
])
column_id
+=
1
all_subjects
=
get_subjects
(
request
,
type
)
all_subjects
=
get_subjects
(
request
,
type
)
count
=
all_subjects
.
count
()
count
=
all_subjects
.
count
()
ordered_subjects
=
get_subjects_order
(
all_subjects
,
order_column
,
order_dir
)
filtered_subjects
=
get_subjects_filtered
(
ordered_subjects
,
filters
)
sliced_subjects
=
filtered_subjects
[
start
:(
start
+
length
)]
ordered_subjects
=
get_subjects_order
(
all_subjects
,
order_column
,
order_dir
)
filtered_subjects
=
get_subjects_filtered
(
ordered_subjects
,
filters
)
sliced_subjects
=
filtered_subjects
[
start
:(
start
+
length
)]
subjects
=
sliced_subjects
subjects
=
sliced_subjects
count_filtered
=
filtered_subjects
.
count
()
count_filtered
=
filtered_subjects
.
count
()
data
=
[]
for
subject
in
subjects
:
data
.
append
(
serialize_subject
(
subject
))
return
JsonResponse
({
"
draw
"
:
draw
,
"
recordsTotal
"
:
count
,
"
recordsFiltered
"
:
count_filtered
,
"
data
"
:
data
,
})
data
=
[]
for
subject
in
subjects
:
data
.
append
(
serialize_subject
(
subject
))
return
JsonResponse
({
"
draw
"
:
draw
,
"
recordsTotal
"
:
count
,
"
recordsFiltered
"
:
count_filtered
,
"
data
"
:
data
,
})
except
:
return
e500_error
(
request
)
def
get_yes_no
(
val
):
if
val
:
...
...
This diff is collapsed.
Click to expand it.
smash/web/tests/functions.py
+
9
−
2
View file @
8f7d2b7f
...
...
@@ -7,6 +7,13 @@ from web.models.constants import SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL
from
web.views.notifications
import
get_today_midnight_date
def
create_get_suffix
(
params
):
result
=
"
?
"
for
key
in
params
:
result
+=
key
+
"
=
"
+
str
(
params
[
key
])
+
"
&
"
return
result
def
create_location
(
name
=
"
test
"
):
return
Location
.
objects
.
create
(
name
=
name
)
...
...
@@ -27,14 +34,14 @@ def create_appointment_type():
)
def
create_subject
():
def
create_subject
(
id
=
1
):
return
Subject
.
objects
.
create
(
first_name
=
"
Piotr
"
,
last_name
=
"
Gawron
"
,
default_location
=
get_test_location
(),
sex
=
SEX_CHOICES_MALE
,
type
=
SUBJECT_TYPE_CHOICES_CONTROL
,
screening_number
=
"
piotr
'
s number
"
,
screening_number
=
"
piotr
'
s number
"
+
str
(
id
)
,
country
=
"
france
"
)
...
...
This diff is collapsed.
Click to expand it.
smash/web/tests/test_api.py
+
39
−
1
View file @
8f7d2b7f
...
...
@@ -6,7 +6,9 @@ from django.test import Client
from
django.test
import
TestCase
from
django.urls
import
reverse
from
web.tests.functions
import
create_subject
,
create_worker
,
create_appointment_type
,
create_location
from
web.tests.functions
import
create_subject
,
create_worker
,
create_appointment_type
,
create_location
,
\
create_get_suffix
from
web.views.subject
import
SUBJECT_LIST_GENERIC
,
SUBJECT_LIST_NO_VISIT
,
SUBJECT_LIST_REQUIRE_CONTACT
__author__
=
'
Piotr Gawron
'
...
...
@@ -149,3 +151,39 @@ class TestApi(TestCase):
found
=
True
self
.
assertTrue
(
found
)
def
test_subjects_general
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'
web.api.subjects
'
,
kwargs
=
{
'
type
'
:
SUBJECT_LIST_GENERIC
}))
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_subjects_no_visit
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'
web.api.subjects
'
,
kwargs
=
{
'
type
'
:
SUBJECT_LIST_NO_VISIT
}))
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_subjects_require_contact
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'
web.api.subjects
'
,
kwargs
=
{
'
type
'
:
SUBJECT_LIST_REQUIRE_CONTACT
}))
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_subjects_invalid
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'
web.api.subjects
'
,
kwargs
=
{
'
type
'
:
"
bla
"
}))
self
.
assertEqual
(
response
.
status_code
,
500
)
def
test_subjects_general_search
(
self
):
name
=
"
Piotrek
"
self
.
subject
.
first_name
=
name
self
.
subject
.
save
()
params
=
{
"
columns[0][search][value]
"
:
"
another_name
"
,
"
columns[0][data]
"
:
"
first_name
"
}
url
=
(
"
%s
"
+
create_get_suffix
(
params
))
%
reverse
(
'
web.api.subjects
'
,
kwargs
=
{
'
type
'
:
SUBJECT_LIST_GENERIC
})
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertFalse
(
name
in
response
.
content
)
params
[
"
columns[0][search][value]
"
]
=
name
url
=
(
"
%s
"
+
create_get_suffix
(
params
))
%
reverse
(
'
web.api.subjects
'
,
kwargs
=
{
'
type
'
:
SUBJECT_LIST_GENERIC
})
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertTrue
(
name
in
response
.
content
)
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