def test_institutions_serializer_should_serialize_whole_basic_record(): schema = InstitutionsElasticSearchSchema() expected_result = { "$schema": "http://localhost:5000/schemas/records/institutions.json", "_collections": ["Institutions"], } conference = InstitutionsRecord(faker.record("ins")) result = schema.dump(conference).data assert result == expected_result
def test_populate_affiliation_suggest_from_legacy_icn(): data = { "$schema": "http://localhost:5000/schemas/records/institutions.json", "legacy_ICN": "CERN", } record = InstitutionsRecord(faker.record("ins", data)) schema = InstitutionsElasticSearchSchema() result = schema.dump(record).data["affiliation_suggest"] expected = {"input": ["CERN"]} assert expected == result
def test_populate_affiliation_search_as_you_type_from_legacy_icn( mock_institution_literature_table, ): data = { "$schema": "http://localhost:5000/schemas/records/institutions.json", "legacy_ICN": "CERN", } record = InstitutionsRecord(faker.record("ins", data)) schema = InstitutionsElasticSearchSchema() result = schema.dump(record).data["affiliation_search_as_you_type"] expected = ["CERN"] assert expected == result
def test_populate_affiliation_suggest_from_name_variants(): data = { "$schema": "http://localhost:5000/schemas/records/institutions.json", "legacy_ICN": "CERN", "name_variants": [{ "value": "Centre Européen de Recherches Nucléaires" }], } record = InstitutionsRecord(faker.record("ins", data)) schema = InstitutionsElasticSearchSchema() result = schema.dump(record).data["affiliation_suggest"] expected = {"input": ["CERN", "Centre Européen de Recherches Nucléaires"]} assert expected == result
def test_index_institutions_record(inspire_app, datadir): data = orjson.loads((datadir / "902725.json").read_text()) record = create_record("ins", data=data) expected_count = 1 expected_metadata = InstitutionsElasticSearchSchema().dump(record).data expected_metadata["affiliation_suggest"] = { "input": [ "CERN, Geneva", "CERN", "European Organization for Nuclear Research", "CERN", "Centre Européen de Recherches Nucléaires", "01631", "1211", ] } expected_metadata["number_of_papers"] = 0 expected_metadata["_created"] = utils.isoformat(record.created) expected_metadata["_updated"] = utils.isoformat(record.updated) response = es_search("records-institutions") assert response["hits"]["total"]["value"] == expected_count assert response["hits"]["hits"][0]["_source"] == expected_metadata
def test_populate_affiliation_search_as_you_type_from_institution_hierarchy_name( mock_institution_literature_table, ): data = { "$schema": "http://localhost:5000/schemas/records/institutions.json", "institution_hierarchy": [{ "name": "European Organization for Nuclear Research" }], "legacy_ICN": "CERN", } record = InstitutionsRecord(faker.record("ins", data)) schema = InstitutionsElasticSearchSchema() result = schema.dump(record).data["affiliation_search_as_you_type"] expected = ["European Organization for Nuclear Research", "CERN"] assert expected == result
def test_populate_affiliation_search_as_you_type_from_name_variants_with_umr( mock_institution_literature_table, ): data = { "$schema": "http://localhost:5000/schemas/records/institutions.json", "legacy_ICN": "CERN", "name_variants": [ { "value": "Centre Européen de Recherches Nucléaires" }, { "value": "UMR 2454" }, { "value": "umr 1234" }, { "value": "umr" }, ], } record = InstitutionsRecord(faker.record("ins", data)) schema = InstitutionsElasticSearchSchema() result = schema.dump(record).data["affiliation_search_as_you_type"] expected = [ "CERN", "Centre Européen de Recherches Nucléaires", "UMR 2454", "umr 1234", "umr", "2454", "1234", ] assert expected == result
def test_institutions_serializer_populates_affiliation_suggest(): schema = InstitutionsElasticSearchSchema() data = { "ICN": ["ICN_VALUE"], "legacy_ICN": "Legacy icn value", "institution_hierarchy": [{ "acronym": "ACR1", "name": "Name1" }], "name_variants": [{ "value": "name1" }, { "value": "name2" }], "addresses": [{ "postal_code": "12345" }, { "postal_code": "65432" }], } expected_result = { "input": [ "ICN_VALUE", "ACR1", "Name1", "Legacy icn value", "name1", "name2", "12345", "65432", ] } institution = InstitutionsRecord(faker.record("ins", data)) result = schema.dump(institution).data["affiliation_suggest"] assert result == expected_result