Esempio n. 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
Esempio n. 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)
Esempio n. 3
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"
Esempio n. 4
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"
Esempio n. 5
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
Esempio n. 6
0
def test_data_create(base_app, db, es):
    data = faker.record("dat")
    record = DataRecord.create(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
Esempio n. 7
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)
Esempio n. 8
0
def test_data_update(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.update(data)
    control_number = str(record["control_number"])
    record_updated_db = RecordMetadata.query.filter_by(id=record.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.model.id == record_updated_pid.object_uuid
    assert control_number == record_updated_pid.pid_value