Commit e7254a67 by Oleg Marshev

Add default and max size settings.

parent fdb3abe3
...@@ -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(250): for i in xrange(300):
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 20. See RESULTS_DEFAULT_SIZE in annotator. # By default return 25. See RESULTS_DEFAULT_SIZE in settings.
result = self._get_search_results() result = self._get_search_results()
self.assertEqual(len(result['rows']), 20) self.assertEqual(len(result['rows']), 25)
# Return maximum 200. See RESULTS_MAX_SIZE in annotator. # Return maximum 250. See RESULTS_MAX_SIZE in settings.
result = self._get_search_results('limit=250') result = self._get_search_results('limit=300')
self.assertEqual(len(result['rows']), 200) self.assertEqual(len(result['rows']), 250)
# 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']), 20) self.assertEqual(len(result['rows']), 25)
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']), 20) self.assertEqual(len(result['rows']), 25)
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']), 20) self.assertEqual(len(result['rows']), 25)
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']), 20) self.assertEqual(len(result['rows']), 25)
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):
......
...@@ -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
......
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment