当前位置: 首页>>代码示例>>Python>>正文


Python Deposit.get_record方法代码示例

本文整理汇总了Python中invenio_deposit.api.Deposit.get_record方法的典型用法代码示例。如果您正苦于以下问题:Python Deposit.get_record方法的具体用法?Python Deposit.get_record怎么用?Python Deposit.get_record使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在invenio_deposit.api.Deposit的用法示例。


在下文中一共展示了Deposit.get_record方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_delete

# 需要导入模块: from invenio_deposit.api import Deposit [as 别名]
# 或者: from invenio_deposit.api.Deposit import get_record [as 别名]
def test_delete(app, db, fake_schemas, location):
    """Test simple delete."""
    deposit = Deposit.create({})
    pid = deposit.pid
    assert deposit["_deposit"]["id"]
    assert "draft" == deposit.status
    assert 0 == deposit.revision_id

    deposit.delete()

    with pytest.raises(NoResultFound):
        Deposit.get_record(deposit.id)

    with pytest.raises(PIDInvalidAction):
        deposit.publish(pid=pid)
开发者ID:hachreak,项目名称:invenio-deposit,代码行数:17,代码来源:test_api.py

示例2: test_delete

# 需要导入模块: from invenio_deposit.api import Deposit [as 别名]
# 或者: from invenio_deposit.api.Deposit import get_record [as 别名]
def test_delete(app, db, fake_schemas):
    """Test simple delete."""
    deposit = Deposit.create({})
    pid = deposit.pid
    assert deposit['_deposit']['id']
    assert 'draft' == deposit['_deposit']['status']
    assert 0 == deposit.revision_id

    deposit.delete()

    with pytest.raises(NoResultFound):
        Deposit.get_record(deposit.id)

    with pytest.raises(PIDInvalidAction):
        deposit.publish(pid=pid)
开发者ID:techoutlooks,项目名称:invenio-deposit,代码行数:17,代码来源:test_api.py

示例3: test_file_put_oauth2

# 需要导入模块: from invenio_deposit.api import Deposit [as 别名]
# 或者: from invenio_deposit.api.Deposit import get_record [as 别名]
def test_file_put_oauth2(api, deposit, files, users,
                         write_token_user_1):
    """PUT a deposit file with oauth2."""
    with api.test_request_context():
        with api.test_client() as client:
            old_file_id = files[0].file_id
            old_filename = files[0].key
            new_filename = '{0}-new-name'.format(old_filename)
            # test rename file
            res = client.put(
                url_for('invenio_deposit_rest.depid_file',
                        pid_value=deposit['_deposit']['id'],
                        key=old_filename),
                data=json.dumps({'filename': new_filename}),
                headers=[
                    ('Authorization',
                     'Bearer {0}'.format(write_token_user_1.access_token))
                ]
            )
            deposit_id = deposit.id
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            files = list(deposit.files)
            assert res.status_code == 200
            assert new_filename == files[0].key
            assert old_file_id == files[0].file_id
            data = json.loads(res.data.decode('utf-8'))
            obj = files[0]
            assert data['filename'] == obj.key
            assert data['checksum'] == obj.file.checksum
            assert data['id'] == str(obj.file.id)
开发者ID:tiborsimko,项目名称:invenio-deposit,代码行数:33,代码来源:test_views_rest_files.py

示例4: test_files_put_oauth2

# 需要导入模块: from invenio_deposit.api import Deposit [as 别名]
# 或者: from invenio_deposit.api.Deposit import get_record [as 别名]
def test_files_put_oauth2(app, db, deposit, files, users, write_token_user_1):
    """Test put deposito files with oauth2."""
    with app.test_request_context():
        with app.test_client() as client:
            # fixture
            content = b'### Testing textfile 2 ###'
            stream = BytesIO(content)
            key = 'world.txt'
            deposit.files[key] = stream
            deposit.commit()
            db.session.commit()
            deposit_id = deposit.id
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            key0 = files[0].key
            files = list(deposit.files)
            assert files[0]['key'] == str(key0)
            assert files[1]['key'] == str(key)
            # order files
            res = client.put(
                url_for('invenio_deposit_rest.dep_files',
                        pid_value=deposit['_deposit']['id']),
                data=json.dumps([
                    {'id': key},
                    {'id': key0}
                ]),
                headers=[
                    ('Authorization',
                     'Bearer {0}'.format(write_token_user_1.access_token))
                ]
            )
            assert res.status_code == 200
            data = json.loads(res.data.decode('utf-8'))
            assert data[0]['filename'] == str(key)
            assert data[1]['filename'] == str(key0)
开发者ID:nharraud,项目名称:invenio-deposit,代码行数:37,代码来源:test_views_rest_files.py

示例5: test_file_delete

# 需要导入模块: from invenio_deposit.api import Deposit [as 别名]
# 或者: from invenio_deposit.api.Deposit import get_record [as 别名]
def test_file_delete(api, deposit, files, users):
    """Test delete file."""
    with api.test_request_context():
        # the user is the owner
        with api.test_client() as client:
            deposit_id = deposit.id
            res = client.delete(url_for(
                'invenio_deposit_rest.depid_file',
                pid_value=deposit['_deposit']['id'],
                key=files[0].key
            ))
            assert res.status_code == 401
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            assert files[0].key in deposit.files
            assert deposit.files[files[0].key] is not None
            # login
            res = client.post(url_for_security('login'), data=dict(
                email=users[0]['email'],
                password="tester"
            ))
            # delete resource
            res = client.delete(url_for(
                'invenio_deposit_rest.depid_file',
                pid_value=deposit['_deposit']['id'],
                key=files[0].key
            ))
            assert res.status_code == 204
            assert res.data == b''
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            assert files[0].key not in deposit.files

        # the user is NOT the owner
        with api.test_client() as client:
            # login
            res = client.post(url_for_security('login'), data=dict(
                email=users[1]['email'],
                password="tester2"
            ))
            # delete resource
            res = client.delete(url_for(
                'invenio_deposit_rest.depid_file',
                pid_value=deposit['_deposit']['id'],
                key=files[0].key
            ))
            assert res.status_code == 403
开发者ID:tiborsimko,项目名称:invenio-deposit,代码行数:49,代码来源:test_views_rest_files.py

示例6: test_file_delete_oauth2

# 需要导入模块: from invenio_deposit.api import Deposit [as 别名]
# 或者: from invenio_deposit.api.Deposit import get_record [as 别名]
def test_file_delete_oauth2(api, deposit, files, users,
                            write_token_user_1):
    """Test delete file with oauth2."""
    with api.test_request_context():
        with api.test_client() as client:
            deposit_id = deposit.id
            # delete resource
            res = client.delete(
                url_for(
                    'invenio_deposit_rest.depid_file',
                    pid_value=deposit['_deposit']['id'],
                    key=files[0].key
                ),
                headers=[
                    ('Authorization',
                     'Bearer {0}'.format(write_token_user_1.access_token))
                ]
            )
            assert res.status_code == 204
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            assert files[0].key not in deposit.files
开发者ID:tiborsimko,项目名称:invenio-deposit,代码行数:24,代码来源:test_views_rest_files.py

示例7: test_file_put

# 需要导入模块: from invenio_deposit.api import Deposit [as 别名]
# 或者: from invenio_deposit.api.Deposit import get_record [as 别名]
def test_file_put(api, deposit, files, users):
    """PUT a deposit file."""
    with api.test_request_context():
        with api.test_client() as client:
            old_file_id = files[0].file_id
            old_filename = files[0].key
            new_filename = '{0}-new-name'.format(old_filename)
            # test rename file (without login)
            res = client.put(
                url_for('invenio_deposit_rest.depid_file',
                        pid_value=deposit['_deposit']['id'],
                        key=old_filename),
                data=json.dumps({'filename': new_filename}))
            assert res.status_code == 401
            # login
            res = client.post(url_for_security('login'), data=dict(
                email=users[0]['email'],
                password="tester"
            ))
            # test rename file
            res = client.put(
                url_for('invenio_deposit_rest.depid_file',
                        pid_value=deposit['_deposit']['id'],
                        key=old_filename),
                data=json.dumps({'filename': new_filename}))
            deposit_id = deposit.id
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            files = list(deposit.files)
            assert res.status_code == 200
            assert new_filename == files[0].key
            assert old_file_id == files[0].file_id
            data = json.loads(res.data.decode('utf-8'))
            obj = files[0]
            assert data['filename'] == obj.key
            assert data['checksum'] == obj.file.checksum
            assert data['id'] == str(obj.file.id)
开发者ID:tiborsimko,项目名称:invenio-deposit,代码行数:39,代码来源:test_views_rest_files.py

示例8: test_files_put

# 需要导入模块: from invenio_deposit.api import Deposit [as 别名]
# 或者: from invenio_deposit.api.Deposit import get_record [as 别名]
def test_files_put(api, deposit, files, users):
    """Test put deposit files."""
    with api.test_request_context():
        # the user is the owner
        with api.test_client() as client:
            # fixture
            content = b'### Testing textfile 2 ###'
            stream = BytesIO(content)
            key = 'world.txt'
            deposit.files[key] = stream
            deposit.commit()
            db.session.commit()
            deposit_id = deposit.id
            file_ids = [f.file_id for f in deposit.files]
            assert deposit['_files'][0]['key'] == files[0].key
            assert deposit['_files'][1]['key'] == key
            assert len(deposit.files) == 2
            assert len(deposit['_files']) == 2
            # add new file (without login)
            res = client.put(
                url_for('invenio_deposit_rest.depid_files',
                        pid_value=deposit['_deposit']['id']),
                data=json.dumps([
                    {'id': str(file_ids[1])},
                    {'id': str(file_ids[0])}
                ])
            )
            assert res.status_code == 401
            # login
            res = client.post(url_for_security('login'), data=dict(
                email=users[0]['email'],
                password="tester"
            ))
            # order files
            res = client.put(
                url_for('invenio_deposit_rest.depid_files',
                        pid_value=deposit['_deposit']['id']),
                data=json.dumps([
                    {'id': str(file_ids[1])},
                    {'id': str(file_ids[0])}
                ])
            )
            data = json.loads(res.data.decode('utf-8'))
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            assert deposit['_files'][0]['key'] == data[0]['filename']
            assert deposit['_files'][1]['key'] == data[1]['filename']
            assert data[0]['id'] == str(file_ids[1])
            assert data[1]['id'] == str(file_ids[0])
            assert len(deposit.files) == 2
            assert len(deposit['_files']) == 2
            assert len(data) == 2

        # the user is NOT the owner
        with api.test_client() as client:
            # login
            res = client.post(url_for_security('login'), data=dict(
                email=users[1]['email'],
                password="tester2"
            ))
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            order = [f.key for f in deposit.files]
            # test files post
            res = client.put(
                url_for('invenio_deposit_rest.depid_files',
                        pid_value=deposit['_deposit']['id']),
                data=json.dumps([
                    {'id': str(file_ids[1])},
                    {'id': str(file_ids[0])}
                ])
            )
            assert res.status_code == 403
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            assert deposit['_files'][0]['key'] == order[0]
            assert deposit['_files'][1]['key'] == order[1]
开发者ID:tiborsimko,项目名称:invenio-deposit,代码行数:79,代码来源:test_views_rest_files.py

示例9: test_files_post

# 需要导入模块: from invenio_deposit.api import Deposit [as 别名]
# 或者: from invenio_deposit.api.Deposit import get_record [as 别名]
def test_files_post(api, deposit, users):
    """Post a deposit file."""
    real_filename = 'real_test.json'
    content = b'### Testing textfile ###'
    digest = 'md5:{0}'.format(hashlib.md5(content).hexdigest())
    filename = 'test.json'
    with api.test_request_context():
        # the user is the owner
        with api.test_client() as client:
            # test post without login
            file_to_upload = (BytesIO(content), filename)
            res = client.post(
                url_for('invenio_deposit_rest.depid_files',
                        pid_value=deposit['_deposit']['id']),
                data={'file': file_to_upload, 'name': real_filename},
                content_type='multipart/form-data'
            )
            assert res.status_code == 401
            # login
            res = client.post(url_for_security('login'), data=dict(
                email=users[0]['email'],
                password="tester"
            ))
            # test empty post
            res = client.post(
                url_for('invenio_deposit_rest.depid_files',
                        pid_value=deposit['_deposit']['id']),
                data={'name': real_filename},
                content_type='multipart/form-data'
            )
            assert res.status_code == 400
            # test post
            file_to_upload = (BytesIO(content), filename)
            res = client.post(
                url_for('invenio_deposit_rest.depid_files',
                        pid_value=deposit['_deposit']['id']),
                data={'file': file_to_upload, 'name': real_filename},
                content_type='multipart/form-data'
            )
            deposit_id = deposit.id
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            files = list(deposit.files)
            assert res.status_code == 201
            assert real_filename == files[0].key
            assert digest == files[0].file.checksum
            data = json.loads(res.data.decode('utf-8'))
            obj = files[0]
            assert data['filename'] == obj.key
            assert data['checksum'] == obj.file.checksum
            assert data['id'] == str(obj.file.id)

        # the user is NOT the owner
        with api.test_client() as client:
            # login
            res = client.post(url_for_security('login'), data=dict(
                email=users[1]['email'],
                password="tester2"
            ))
            # test post
            file_to_upload = (BytesIO(content), filename)
            res = client.post(
                url_for('invenio_deposit_rest.depid_files',
                        pid_value=deposit['_deposit']['id']),
                data={'file': file_to_upload, 'name': real_filename},
                content_type='multipart/form-data'
            )
            assert res.status_code == 403
开发者ID:tiborsimko,项目名称:invenio-deposit,代码行数:70,代码来源:test_views_rest_files.py

示例10: test_files_put

# 需要导入模块: from invenio_deposit.api import Deposit [as 别名]
# 或者: from invenio_deposit.api.Deposit import get_record [as 别名]
def test_files_put(app, db, deposit, files, users):
    """Test put deposit files."""
    with app.test_request_context():
        # the user is the owner
        with app.test_client() as client:
            # fixture
            content = b'### Testing textfile 2 ###'
            stream = BytesIO(content)
            key = 'world.txt'
            deposit.files[key] = stream
            deposit.commit()
            db.session.commit()
            deposit_id = deposit.id
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            key0 = files[0].key
            files = list(deposit.files)
            assert files[0]['key'] == str(key0)
            assert files[1]['key'] == str(key)
            # add new file (without login)
            res = client.put(
                url_for('invenio_deposit_rest.dep_files',
                        pid_value=deposit['_deposit']['id']),
                data=json.dumps([
                    {'id': key},
                    {'id': key0}
                ])
            )
            assert res.status_code == 401
            # login
            res = client.post(url_for_security('login'), data=dict(
                email=users[0].email,
                password="tester"
            ))
            # order files
            res = client.put(
                url_for('invenio_deposit_rest.dep_files',
                        pid_value=deposit['_deposit']['id']),
                data=json.dumps([
                    {'id': key},
                    {'id': key0}
                ])
            )
            db.session.expunge(deposit.model)
            deposit = Deposit.get_record(deposit_id)
            files = list(deposit.files)
            assert len(deposit.files) == 2
            assert files[0]['key'] == str(key)
            assert files[1]['key'] == str(key0)
            data = json.loads(res.data.decode('utf-8'))
            assert data[0]['filename'] == str(key)
            assert data[1]['filename'] == str(key0)

        # the user is NOT the owner
        with app.test_client() as client:
            # login
            res = client.post(url_for_security('login'), data=dict(
                email=users[1].email,
                password="tester2"
            ))
            # test files post
            res = client.put(
                url_for('invenio_deposit_rest.dep_files',
                        pid_value=deposit['_deposit']['id']),
                data=json.dumps([
                    {'id': key},
                    {'id': key0}
                ])
            )
            assert res.status_code == 403
开发者ID:nharraud,项目名称:invenio-deposit,代码行数:72,代码来源:test_views_rest_files.py


注:本文中的invenio_deposit.api.Deposit.get_record方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。