コード例 #1
0
def test_facet_configuration_with_existing_facet_dict(inspire_app):
    config = {
        "RECORDS_REST_FACETS": {
            "defenders": {
                "aggs": {
                    "jessica-jones": {
                        "terms": {
                            "field": "defenders",
                            "size": 20
                        }
                    }
                }
            }
        }
    }
    expected = {
        "aggs": {
            "jessica-jones": {
                "terms": {
                    "field": "defenders",
                    "size": 20
                }
            }
        }
    }
    with current_app.test_request_context("?facet_name=defenders"):
        with override_config(**config):
            result = get_facet_configuration("records-hep")
            assert expected == result
コード例 #2
0
ファイル: test_utils.py プロジェクト: michamos/inspirehep
def test_facet_configuration_with_fallback_to_default_facet(base_app):
    config = {
        "RECORDS_REST_FACETS": {
            "records-hep": {
                "aggs": {
                    "jessica-jones": {
                        "terms": {
                            "field": "defenders",
                            "size": 20
                        }
                    }
                }
            }
        }
    }
    expected = {
        "aggs": {
            "jessica-jones": {
                "terms": {
                    "field": "defenders",
                    "size": 20
                }
            }
        }
    }
    with base_app.test_request_context("?facet_name=defenders"):
        with patch.dict(base_app.config, config):
            result = get_facet_configuration("records-hep")
            assert expected == result
コード例 #3
0
def test_facet_configuration_with_existing_facet_callable(inspire_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 current_app.test_request_context("?facet_name=defenders"):
        with override_config(**config):
            result = get_facet_configuration("records-hep")
            facet_mock.assert_called_once()
            assert expected == result
コード例 #4
0
ファイル: test_utils.py プロジェクト: michamos/inspirehep
def test_facet_configuration_with_existing_facet_import_string(
        facet_mock, base_app):
    facet_mock.return_value = {
        "aggs": {
            "jessica-jones": {
                "terms": {
                    "field": "defenders",
                    "size": 20
                }
            }
        }
    }
    config = {
        "RECORDS_REST_FACETS": {
            "defenders": "inspirehep.records.config.RECORDS_REST_ENDPOINTS"
        }
    }
    expected = {
        "aggs": {
            "jessica-jones": {
                "terms": {
                    "field": "defenders",
                    "size": 20
                }
            }
        }
    }
    with base_app.test_request_context("?facet_name=defenders"):
        with patch.dict(base_app.config, config):
            result = get_facet_configuration("records-hep")
            facet_mock.assert_called_once()
            assert expected == result