Example #1
0
 def __init__(
     self,
     request,
     separate_replies=False,
     separate_wildcard_uri_keys=True,
     _replies_limit=200,
 ):
     self.es = request.es
     self.separate_replies = separate_replies
     self._replies_limit = _replies_limit
     # Order matters! The KeyValueMatcher must be run last,
     # after all other modifiers have popped off the params.
     self._modifiers = [
         query.Sorter(),
         query.Limiter(),
         query.DeletedFilter(),
         query.AuthFilter(request),
         query.GroupFilter(),
         query.GroupAuthFilter(request),
         query.UserFilter(),
         query.HiddenFilter(request),
         query.AnyMatcher(),
         query.TagsMatcher(),
         query.UriCombinedWildcardFilter(
             request, separate_keys=separate_wildcard_uri_keys
         ),
         query.KeyValueMatcher(),
     ]
     self._aggregations = []
Example #2
0
    def test_limit_set_to_default_when_missing(self, es_dsl_search,
                                               pyramid_request):
        limiter = query.Limiter()

        q = limiter(es_dsl_search, webob.multidict.MultiDict({})).to_dict()

        assert q["size"] == LIMIT_DEFAULT
Example #3
0
File: core.py Project: kael/h
 def __init__(self,
              request,
              separate_replies=False,
              stats=None,
              _replies_limit=200):
     self.es = request.es
     self.separate_replies = separate_replies
     self.stats = stats
     self._replies_limit = _replies_limit
     # Order matters! The KeyValueMatcher must be run last,
     # after all other modifiers have popped off the params.
     self._modifiers = [
         query.Sorter(),
         query.Limiter(),
         query.DeletedFilter(),
         query.AuthFilter(request),
         query.GroupFilter(),
         query.GroupAuthFilter(request),
         query.UserFilter(),
         query.NipsaFilter(request),
         query.AnyMatcher(),
         query.TagsMatcher(),
         query.KeyValueMatcher()
     ]
     self._aggregations = []
Example #4
0
    def test_limit_matches_input(self, es_dsl_search, pyramid_request, lim):
        """Given an integer in the allowed range, it should be passed through."""
        limiter = query.Limiter()

        q = limiter(es_dsl_search, webob.multidict.MultiDict({"limit": str(lim)})).to_dict()

        assert q["size"] == lim
Example #5
0
    def test_limit_output_within_bounds_int_input(self, es_dsl_search, pyramid_request, lim):
        """Given any integer input, output should be in the allowed range."""
        limiter = query.Limiter()

        q = limiter(es_dsl_search, webob.multidict.MultiDict({"limit": str(lim)})).to_dict()

        assert isinstance(q["size"], int)
        assert 0 <= q["size"] <= LIMIT_MAX
Example #6
0
    def test_limit_output_within_bounds(self, es_dsl_search, pyramid_request, limit, expected):
        """Given any string input, output should be in the allowed range."""
        limiter = query.Limiter()

        q = limiter(es_dsl_search, webob.multidict.MultiDict({"limit": limit})).to_dict()

        assert isinstance(q["size"], int)
        assert q["size"] == expected
Example #7
0
    def test_offset(self, es_dsl_search, pyramid_request, offset, from_):
        limiter = query.Limiter()

        params = webob.multidict.MultiDict({"offset": offset})
        if offset is MISSING:
            params = webob.multidict.MultiDict({})

        q = limiter(es_dsl_search, params).to_dict()

        assert q["from"] == from_
Example #8
0
 def search(self, search):
     search.append_modifier(query.Limiter())
     return search