Exemplo n.º 1
0
def test_experiment_serializer_should_serialize_whole_basic_record(
    mock_experiment_literature_table, ):
    schema = ExperimentsElasticSearchSchema()
    expected_result = {
        "$schema": "http://localhost:5000/schemas/records/experiments.json",
        "_collections": ["Experiments"],
        "project_type": ["experiment"],
    }

    experiment = faker.record("exp", data={"experiment": {}})
    result = schema.dump(experiment).data

    assert result == expected_result
Exemplo n.º 2
0
def test_experiment_serializer_populates_normalized_names_and_subgroups(
    mock_experiment_literature_table, ):
    schema = ExperimentsElasticSearchSchema()
    data = {
        "accelerator": {
            "value": "ACC"
        },
        "collaboration": {
            "curated_relation": False,
            "value": "COLLABORATION",
            "subgroup_names": ["subgroup 1", "subgroup 2"],
        },
        "experiment": {
            "short_name": "EXP SHORT NAME",
            "value": "Experiment value"
        },
        "institutions": [{
            "record": {
                "$ref": "http://labs.inspirehep.net/api/institutions/902725"
            },
            "value": "INST_VALUE",
            "curated_relation": True,
        }],
        "legacy_name":
        "LEGACY-NAME",
        "name_variants": ["NAME_V1", "NAME_V2", "NAME_V3"],
    }

    expected_normalized_name_variants = [
        "COLLABORATION",
        "NAME_V1",
        "NAME_V2",
        "NAME_V3",
    ]
    expected_normalized_subgroups = ["subgroup 1", "subgroup 2"]

    experiment = ExperimentsRecord(faker.record("exp", data))
    result = schema.dump(experiment).data

    assert result[
        "normalized_name_variants"] == expected_normalized_name_variants
    assert result["normalized_subgroups"] == expected_normalized_subgroups
Exemplo n.º 3
0
def test_experiment_serializer_populates_experiment_suggest(
    mock_experiment_literature_table,
):
    schema = ExperimentsElasticSearchSchema()
    data = {
        "accelerator": {"value": "ACC"},
        "collaboration": {"curated_relation": False, "value": "COLLABORATION"},
        "experiment": {"short_name": "EXP SHORT NAME", "value": "Experiment value"},
        "institutions": [
            {
                "record": {
                    "$ref": "http://labs.inspirehep.net/api/institutions/902725"
                },
                "value": "INST_VALUE",
                "curated_relation": True,
            }
        ],
        "legacy_name": "LEGACY-NAME",
        "long_name": "{Long Name}",
        "name_variants": ["NAME_V1", "NAME_V2", "NAME_V3"],
    }

    expected_experiment_suggest = [
        {"input": "ACC", "weight": 1},
        {"input": "COLLABORATION", "weight": 1},
        {"input": "EXP SHORT NAME", "weight": 1},
        {"input": "Experiment value", "weight": 1},
        {"input": "INST_VALUE", "weight": 1},
        {"input": "{Long Name}", "weight": 1},
        {"input": "NAME_V1", "weight": 1},
        {"input": "NAME_V2", "weight": 1},
        {"input": "NAME_V3", "weight": 1},
        {"input": "LEGACY-NAME", "weight": 5},
    ]
    experiment = ExperimentsRecord(faker.record("exp", data))
    result = schema.dump(experiment).data["experiment_suggest"]

    assert result == expected_experiment_suggest