Esempio n. 1
0
def test_get_record_by_bucket(app, db, document_with_file):
    """Test retrieving a record with a given bucket."""
    # OK
    record = SonarRecord.get_record_by_bucket(document_with_file['_bucket'])
    assert record

    # Record bucket not found
    assert not SonarRecord.get_record_by_bucket(
        '9bca9173-2c7b-4e22-bd6d-46e4f972dbf89')

    # Not record class found
    app.config.get('RECORDS_REST_ENDPOINTS',
                   {}).get('doc', {}).pop('record_class', None)
    assert not SonarRecord.get_record_by_bucket(document_with_file['_bucket'])
    app.config['RECORDS_REST_ENDPOINTS']['doc'][
        'record_class'] = DocumentRecord

    # Persistent identifier not found
    pid = PersistentIdentifier.get('doc', document_with_file['pid'])
    db.session.delete(pid)
    db.session.commit()
    pid = PersistentIdentifier.get('oai',
                                   'oai:sonar.ch:' + document_with_file['pid'])
    db.session.delete(pid)
    db.session.commit()
    assert not SonarRecord.get_record_by_bucket(document_with_file['_bucket'])
Esempio n. 2
0
def sync_record_files(file, deleted=False):
    """Sync files in record corresponding to bucket.

    :param file: File object
    :param delete: Wether file is deleted or not.
    """
    record = SonarRecord.get_record_by_bucket(file.bucket_id)

    if not record:
        return

    record.sync_files(file, deleted)