コード例 #1
0
ファイル: views.py プロジェクト: inspirehep/inspirehep
    def post(self):
        """Adds new experiment record"""

        data = self.load_data_from_request()
        record = ExperimentsRecord(data=data).create(data)
        db.session.commit()
        return (jsonify({"control_number": record["control_number"]}), 201)
コード例 #2
0
ファイル: test_es.py プロジェクト: michamos/inspirehep
def test_experiment_serializer_should_serialize_whole_basic_record():
    schema = ExperimentsElasticSearchSchema()
    expected_result = {
        "$schema": "http://localhost:5000/schemas/records/experiments.json",
        "_collections": ["Experiments"],
        "project_type": ["experiment"],
    }

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

    assert result == expected_result
コード例 #3
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
コード例 #4
0
ファイル: test_es.py プロジェクト: tsgit/inspirehep
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