Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-notes-api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-notes-api
Commits
e7254a67
Commit
e7254a67
authored
Nov 28, 2014
by
Oleg Marshev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add default and max size settings.
parent
fdb3abe3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
13 deletions
+27
-13
notesapi/v1/tests/test_views.py
+10
-10
notesapi/v1/views.py
+8
-1
notesserver/settings/test.py
+9
-2
No files found.
notesapi/v1/tests/test_views.py
View file @
e7254a67
...
@@ -305,18 +305,18 @@ class AnnotationViewTests(APITestCase):
...
@@ -305,18 +305,18 @@ class AnnotationViewTests(APITestCase):
"""
"""
Tests for limit query parameter for paging through results.
Tests for limit query parameter for paging through results.
"""
"""
for
i
in
xrange
(
25
0
):
for
i
in
xrange
(
30
0
):
self
.
_create_annotation
(
refresh
=
False
)
self
.
_create_annotation
(
refresh
=
False
)
es
.
conn
.
indices
.
refresh
(
es
.
index
)
es
.
conn
.
indices
.
refresh
(
es
.
index
)
# By default return 2
0. See RESULTS_DEFAULT_SIZE in annotator
.
# By default return 2
5. See RESULTS_DEFAULT_SIZE in settings
.
result
=
self
.
_get_search_results
()
result
=
self
.
_get_search_results
()
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
0
)
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
5
)
# Return maximum 2
00. See RESULTS_MAX_SIZE in annotator
.
# Return maximum 2
50. See RESULTS_MAX_SIZE in settings
.
result
=
self
.
_get_search_results
(
'limit=
25
0'
)
result
=
self
.
_get_search_results
(
'limit=
30
0'
)
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
0
0
)
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
5
0
)
# Return minimum 0.
# Return minimum 0.
result
=
self
.
_get_search_results
(
'limit=-10'
)
result
=
self
.
_get_search_results
(
'limit=-10'
)
...
@@ -324,7 +324,7 @@ class AnnotationViewTests(APITestCase):
...
@@ -324,7 +324,7 @@ class AnnotationViewTests(APITestCase):
# Ignore bogus values.
# Ignore bogus values.
result
=
self
.
_get_search_results
(
'limit=foobar'
)
result
=
self
.
_get_search_results
(
'limit=foobar'
)
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
0
)
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
5
)
def
test_search_offset
(
self
):
def
test_search_offset
(
self
):
"""
"""
...
@@ -336,7 +336,7 @@ class AnnotationViewTests(APITestCase):
...
@@ -336,7 +336,7 @@ class AnnotationViewTests(APITestCase):
es
.
conn
.
indices
.
refresh
(
es
.
index
)
es
.
conn
.
indices
.
refresh
(
es
.
index
)
result
=
self
.
_get_search_results
()
result
=
self
.
_get_search_results
()
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
0
)
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
5
)
first
=
result
[
'rows'
][
0
]
first
=
result
[
'rows'
][
0
]
result
=
self
.
_get_search_results
(
'offset=240'
)
result
=
self
.
_get_search_results
(
'offset=240'
)
...
@@ -344,12 +344,12 @@ class AnnotationViewTests(APITestCase):
...
@@ -344,12 +344,12 @@ class AnnotationViewTests(APITestCase):
# ignore negative values
# ignore negative values
result
=
self
.
_get_search_results
(
'offset=-10'
)
result
=
self
.
_get_search_results
(
'offset=-10'
)
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
0
)
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
5
)
self
.
assertEqual
(
result
[
'rows'
][
0
],
first
)
self
.
assertEqual
(
result
[
'rows'
][
0
],
first
)
# ignore bogus values
# ignore bogus values
result
=
self
.
_get_search_results
(
'offset=foobar'
)
result
=
self
.
_get_search_results
(
'offset=foobar'
)
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
0
)
self
.
assertEqual
(
len
(
result
[
'rows'
]),
2
5
)
self
.
assertEqual
(
result
[
'rows'
][
0
],
first
)
self
.
assertEqual
(
result
[
'rows'
][
0
],
first
)
def
test_read_all_no_annotations
(
self
):
def
test_read_all_no_annotations
(
self
):
...
...
notesapi/v1/views.py
View file @
e7254a67
...
@@ -31,8 +31,15 @@ class AnnotationSearchView(APIView):
...
@@ -31,8 +31,15 @@ class AnnotationSearchView(APIView):
if
'offset'
in
params
:
if
'offset'
in
params
:
kwargs
[
'offset'
]
=
_convert_to_int
(
params
.
pop
(
'offset'
))
kwargs
[
'offset'
]
=
_convert_to_int
(
params
.
pop
(
'offset'
))
if
'limit'
in
params
:
if
'limit'
in
params
and
_convert_to_int
(
params
[
'limit'
])
is
not
None
:
kwargs
[
'limit'
]
=
_convert_to_int
(
params
.
pop
(
'limit'
))
kwargs
[
'limit'
]
=
_convert_to_int
(
params
.
pop
(
'limit'
))
elif
'limit'
in
params
and
_convert_to_int
(
params
[
'limit'
])
is
None
:
# bad value
params
.
pop
(
'limit'
)
kwargs
[
'limit'
]
=
settings
.
RESULTS_DEFAULT_SIZE
else
:
# default
kwargs
[
'limit'
]
=
settings
.
RESULTS_DEFAULT_SIZE
# All remaining parameters are considered searched fields.
# All remaining parameters are considered searched fields.
kwargs
[
'query'
]
=
params
kwargs
[
'query'
]
=
params
...
...
notesserver/settings/test.py
View file @
e7254a67
from
annotator
import
es
from
annotator
import
es
import
annotator
from
.common
import
*
from
.common
import
*
DATABASES
=
{
DATABASES
=
{
...
@@ -14,7 +15,13 @@ INSTALLED_APPS += ('django_nose',)
...
@@ -14,7 +15,13 @@ INSTALLED_APPS += ('django_nose',)
ELASTICSEARCH_URL
=
'http://127.0.0.1:9200'
ELASTICSEARCH_URL
=
'http://127.0.0.1:9200'
ELASTICSEARCH_INDEX
=
'edx-notes-test'
ELASTICSEARCH_INDEX
=
'edx-notes-test'
# Overwrite default annotator-store elasticsearch settings.
# Number of rows to return by default in result.
RESULTS_DEFAULT_SIZE
=
25
# Max number of rows to return in result.
RESULTS_MAX_SIZE
=
250
# Override default annotator-store elasticsearch settings.
es
.
host
=
ELASTICSEARCH_URL
es
.
host
=
ELASTICSEARCH_URL
es
.
index
=
ELASTICSEARCH_INDEX
es
.
index
=
ELASTICSEARCH_INDEX
annotator
.
elasticsearch
.
RESULTS_MAX_SIZE
=
RESULTS_MAX_SIZE
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment