Exemple #1
0
def test_data_create_with_invalid_data(base_app, db, create_pidstore):
    data = faker.record("dat", with_control_number=True)
    data["invalid_key"] = "should throw an error"
    record_control_number = str(data["control_number"])

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

    record_pid = PersistentIdentifier.query.filter_by(
        pid_value=record_control_number).one_or_none()
    assert record_pid is None
Exemple #2
0
def test_data_create_with_existing_control_number(inspire_app):
    data = faker.record("dat", with_control_number=True)
    existing_object_uuid = uuid.uuid4()

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

    with pytest.raises(PIDAlreadyExists):
        DataRecord.create(data)
Exemple #3
0
def test_cn_redirection_works_for_data(inspire_app):
    redirected_record = create_record("dat")
    record = create_record(
        "dat", data={"deleted_records": [redirected_record["self"]]})

    original_record = DataRecord.get_uuid_from_pid_value(
        redirected_record["control_number"], original_record=True)
    new_record = DataRecord.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
Exemple #4
0
def test_create_record_from_db_depending_on_its_pid_type(base_app, db, es):
    data = faker.record("dat")
    record = InspireRecord.create(data)
    assert type(record) == DataRecord
    assert record.pid_type == "dat"

    record = DataRecord.create(data)
    assert type(record) == DataRecord
    assert record.pid_type == "dat"
Exemple #5
0
def test_create_record_from_db_depending_on_its_pid_type(inspire_app):
    data = faker.record("dat")
    record = InspireRecord.create(data)
    assert isinstance(record, DataRecord)
    assert record.pid_type == "dat"

    record = DataRecord.create(data)
    assert isinstance(record, DataRecord)
    assert record.pid_type == "dat"
Exemple #6
0
def test_create_record_update_citation_table_for_literature_citation(inspire_app):
    data = faker.record("dat")
    record = DataRecord.create(data)

    data2 = faker.record("lit", data_citations=[record["control_number"]])
    record2 = InspireRecord.create(data2)

    assert len(record.model.citations) == 1
    assert len(record.model.references) == 0
    assert len(record2.model.citations) == 0
    assert len(record2.model.references) == 1
    assert len(RecordCitations.query.all()) == 1
Exemple #7
0
def test_data_create_or_update_with_new_record(base_app, db, es):
    data = faker.record("dat")
    record = DataRecord.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="dat", pid_value=str(control_number)).one()

    assert record.model.id == record_pid.object_uuid
    assert control_number == record_pid.pid_value
Exemple #8
0
def test_indexer_deletes_record_from_es(inspire_app):
    def assert_record_is_deleted_from_es():
        current_search.flush_and_refresh("records-data")
        expected_records_count = 0
        record_lit_es = DataSearch().get_record(str(record.id)).execute().hits
        assert expected_records_count == len(record_lit_es)

    record = DataRecord.create(faker.record("dat"))
    db.session.commit()

    record.delete()
    db.session.commit()

    retry_until_pass(assert_record_is_deleted_from_es)
Exemple #9
0
def test_data_create_or_update_with_existing_record(base_app, db, es):
    data = faker.record("dat", with_control_number=True)
    record = DataRecord.create(data)

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

    data_update = {"dois": [{"value": "10.1000/UPDATED"}]}
    data.update(data_update)

    record_updated = DataRecord.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="dat", pid_value=str(control_number)).one()

    assert record_updated.model.id == record_updated_pid.object_uuid
    assert control_number == record_updated_pid.pid_value
Exemple #10
0
def test_subclasses_for_data():
    expected = {"dat": DataRecord}
    assert expected == DataRecord.get_subclasses()