Exemplo n.º 1
0
def test_institutions_create_with_invalid_data(inspire_app):
    data = faker.record("ins", with_control_number=True)
    data["invalid_key"] = "should throw an error"
    record_control_number = str(data["control_number"])

    with pytest.raises(ValidationError):
        InstitutionsRecord.create(data)

    record_pid = PersistentIdentifier.query.filter_by(
        pid_value=record_control_number).one_or_none()
    assert record_pid is None
Exemplo n.º 2
0
def test_institutions_create_with_existing_control_number(inspire_app):
    data = faker.record("ins", with_control_number=True)
    existing_object_uuid = uuid.uuid4()

    create_pidstore(
        object_uuid=existing_object_uuid,
        pid_type="ins",
        pid_value=data["control_number"],
    )

    with pytest.raises(PIDAlreadyExists):
        InstitutionsRecord.create(data)
def test_cn_redirection_works_for_institutions(inspire_app):
    redirected_record = create_record("ins")
    record = create_record(
        "ins", data={"deleted_records": [redirected_record["self"]]})

    original_record = InstitutionsRecord.get_uuid_from_pid_value(
        redirected_record["control_number"], original_record=True)
    new_record = InstitutionsRecord.get_uuid_from_pid_value(
        redirected_record["control_number"])

    assert original_record != new_record
    assert original_record == redirected_record.id
    assert new_record == record.id
Exemplo n.º 4
0
def test_aut_citation_count_property_blows_up_on_wrong_pid_type(
        base_app, db, es):
    data = faker.record("ins")
    record = InstitutionsRecord.create(data)

    with pytest.raises(AttributeError):
        record.citation_count
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
def test_create_record_from_db_depending_on_its_pid_type(inspire_app):
    data = faker.record("ins")
    record = InspireRecord.create(data)
    assert type(record) == InstitutionsRecord
    assert record.pid_type == "ins"

    record = InstitutionsRecord.create(data)
    assert type(record) == InstitutionsRecord
    assert record.pid_type == "ins"
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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
Exemplo n.º 9
0
def test_institutions_create_or_update_with_new_record(inspire_app):
    data = faker.record("ins")
    record = InstitutionsRecord.create_or_update(data)

    control_number = str(record["control_number"])
    record_db = RecordMetadata.query.filter_by(id=record.id).one()

    assert record == record_db.json

    record_pid = PersistentIdentifier.query.filter_by(
        pid_type="ins", pid_value=str(control_number)).one()

    assert record.model.id == record_pid.object_uuid
    assert control_number == record_pid.pid_value
Exemplo n.º 10
0
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
Exemplo n.º 11
0
def test_institutions_create_or_update_with_existing_record(inspire_app):
    data = faker.record("ins", with_control_number=True)
    record = InstitutionsRecord.create(data)

    assert data["control_number"] == record["control_number"]

    data_update = {"public_notes": [{"value": "UPDATED"}]}
    data.update(data_update)

    record_updated = InstitutionsRecord.create_or_update(data)
    control_number = str(record_updated["control_number"])

    assert record["control_number"] == record_updated["control_number"]

    record_updated_db = RecordMetadata.query.filter_by(id=record_updated.id).one()

    assert data == record_updated_db.json

    record_updated_pid = PersistentIdentifier.query.filter_by(
        pid_type="ins", pid_value=str(control_number)
    ).one()

    assert record_updated.model.id == record_updated_pid.object_uuid
    assert control_number == record_updated_pid.pid_value
Exemplo n.º 12
0
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
Exemplo n.º 13
0
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
Exemplo n.º 14
0
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
Exemplo n.º 15
0
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
Exemplo n.º 16
0
def test_subclasses_for_institutions():
    expected = {"ins": InstitutionsRecord}
    assert expected == InstitutionsRecord.get_subclasses()