Exemplo n.º 1
0
def test_hard_delete_record(base_app, db, create_record, create_pidstore):
    record_factory = create_record("lit")
    create_pidstore(record_factory.id, "pid1", faker.control_number())
    create_pidstore(record_factory.id, "pid2", faker.control_number())
    create_pidstore(record_factory.id, "pid3", faker.control_number())

    pid_value_rec = record_factory.json["control_number"]
    record_uuid = record_factory.id
    record = InspireRecord.get_record(record_uuid)
    record_pids = PersistentIdentifier.query.filter_by(
        object_uuid=record.id).all()

    assert 4 == len(record_pids)
    assert record_factory.json == record

    record.hard_delete()
    record = RecordMetadata.query.filter_by(id=record_uuid).one_or_none()
    record_pids = PersistentIdentifier.query.filter_by(
        object_uuid=record_uuid).one_or_none()
    record_identifier = RecordIdentifier.query.filter_by(
        recid=pid_value_rec).one_or_none()

    assert record is None
    assert record_pids is None
    assert record_identifier is None
Exemplo n.º 2
0
def test_base_get_records(base_app, db, create_record):
    records = [create_record("lit")]
    record_uuids = [record.id for record in records]

    expected_records = InspireRecord.get_records(record_uuids)

    for record in records:
        assert record.json in expected_records
Exemplo n.º 3
0
def test_redirect_records(base_app, db, create_record):
    current_factory = create_record("lit")
    other_factory = create_record("lit")

    current = InspireRecord.get_record(current_factory.id)
    other = InspireRecord.get_record(other_factory.id)

    current.redirect(other)

    current_pids = PersistentIdentifier.query.filter(
        PersistentIdentifier.object_uuid == current_factory.id).all()
    other_pid = PersistentIdentifier.query.filter(
        PersistentIdentifier.object_uuid == other_factory.id).one()

    assert current['deleted'] is True
    for current_pid in current_pids:
        assert current_pid.get_redirect() == other_pid
Exemplo n.º 4
0
def test_base_get_records(base_app, db):
    records = RecordMetadataFactory.create_batch(20)
    record_uuids = [record.id for record in records]

    expected_records = InspireRecord.get_records(record_uuids)

    for record in records:
        assert record.json in expected_records
Exemplo n.º 5
0
def test_strip_empty_values():
    empty_fields = {"empty_string": "", "empty_array": [], "empty_dict": {}}
    data = faker.record()
    data.update(empty_fields)
    data_stripped = InspireRecord.strip_empty_values(data)

    assert "empty_string" not in data_stripped
    assert "empty_array" not in data_stripped
    assert "empty_dict" not in data_stripped
Exemplo n.º 6
0
def test_soft_delete_record(base_app, db, create_record):
    record_factory = create_record("lit")
    record_uuid = record_factory.id
    record = InspireRecord.get_record(record_uuid)
    record.delete()
    record_pid = PersistentIdentifier.query.filter_by(
        object_uuid=record.id).one_or_none()

    assert "deleted" in record
    assert record_pid is None
Exemplo n.º 7
0
def test_get_uuid_from_pid_value(base_app, db, create_record):
    record = create_record("lit")
    record_uuid = record.id
    record_pid_type = record._persistent_identifier.pid_type
    record_pid_value = record._persistent_identifier.pid_value

    expected_record_uuid = InspireRecord.get_uuid_from_pid_value(
        record_pid_value, pid_type=record_pid_type)

    assert expected_record_uuid == record_uuid
Exemplo n.º 8
0
def test_base_get_record(base_app, db, create_record):
    record = create_record("lit")

    expected_record = InspireRecord.get_record(record.id)

    assert expected_record == record.json
Exemplo n.º 9
0
def test_base_get_record(base_app, db):
    record = RecordMetadataFactory()

    expected_record = InspireRecord.get_record(record.id)

    assert expected_record == record.json