def test_facet_configuration_with_existing_facet_dict(isolated_app): config = { 'RECORDS_REST_FACETS': { 'defenders': { 'aggs': { 'jessica-jones': { 'terms': { 'field': 'defenders', 'size': 20, }, }, }, }, }, } expected = { 'aggs': { 'jessica-jones': { 'terms': { 'field': 'defenders', 'size': 20 } } } } with isolated_app.test_request_context('?facet_name=defenders'): with patch.dict(isolated_app.config, config): result = get_facet_configuration('records-hep') assert expected == result
def test_facet_configuration_with_existing_facet_callable(isolated_app): facet_mock = Mock() facet_mock.return_value = { 'aggs': { 'jessica-jones': { 'terms': { 'field': 'defenders', 'size': 20, }, }, }, } config = { 'RECORDS_REST_FACETS': { 'defenders': facet_mock }, } expected = { 'aggs': { 'jessica-jones': { 'terms': { 'field': 'defenders', 'size': 20 } } } } with isolated_app.test_request_context('?facet_name=defenders'): with patch.dict(isolated_app.config, config): result = get_facet_configuration('records-hep') facet_mock.assert_called_once() assert expected == result
def default_inspire_facets_factory(search, index): urlkwargs = MultiDict() facets = get_facet_configuration(index) if facets: search = _aggregations(search, facets.get("aggs", {})) search, urlkwargs = _query_filter(search, urlkwargs, facets.get("filters", {})) search, urlkwargs = _post_filter(search, urlkwargs, facets.get("post_filters", {})) return search, urlkwargs
def default_inspire_facets_factory(search, index): urlkwargs = MultiDict() facets = get_facet_configuration(index) if facets: search = _aggregations(search, facets.get("aggs", {})) search, urlkwargs = _query_filter( search, urlkwargs, facets.get("filters", {})) search, urlkwargs = _post_filter( search, urlkwargs, facets.get("post_filters", {})) return search, urlkwargs
def inspire_filter_factory(search, urlkwargs, search_index): """Copies behaviour of default facets factory but without the aggregations, As facets factory is also responsible for filtering the year and author (invenio mess) Args: search: Elastic search DSL search instance. urlkwargs: search_index: index name Returns: tuple with search and urlarguments """ facets = get_facet_configuration(search_index) # Query filter search, urlkwargs = _query_filter(search, urlkwargs, facets.get("filters", {})) # Post filter search, urlkwargs = _post_filter(search, urlkwargs, facets.get("post_filters", {})) return search, urlkwargs
def inspire_filter_factory(search, urlkwargs, search_index): """Copies behaviour of default facets factory but without the aggregations, As facets factory is also responsible for filtering the year and author (invenio mess) Args: search: Elastic search DSL search instance. urlkwargs: search_index: index name Returns: tuple with search and urlarguments """ facets = get_facet_configuration(search_index) # Query filter search, urlkwargs = _query_filter( search, urlkwargs, facets.get("filters", {})) # Post filter search, urlkwargs = _post_filter( search, urlkwargs, facets.get("post_filters", {})) return search, urlkwargs