def post(self): """Adds new Institution""" data = self.load_data_from_request() record = InstitutionsRecord(data=data).create(data) db.session.commit() return jsonify({"control_number": record["control_number"]}), 201
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_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