コード例 #1
0
def test_project_deposit(es, location, deposit_metadata):
    """Test CDS deposit creation."""
    deposit = Project.create(deposit_metadata)
    id_ = deposit.id
    db.session.expire_all()
    deposit = Project.get_record(id_)
    assert deposit['_cds']['state'] == {}
    assert deposit_project_resolver(deposit['_deposit']['id']) is not None
    assert '_buckets' in deposit
コード例 #2
0
def test_project_partial_validation(api_app, db, api_cds_jsonresolver,
                                    deposit_metadata, location,
                                    video_deposit_metadata, users):
    """Test project create/publish with partial validation/validation."""
    video_1 = deepcopy(video_deposit_metadata)
    # create a deposit without a required field
    if 'category' in deposit_metadata:
        del deposit_metadata['category']
    with api_app.test_request_context():
        login_user(User.query.get(users[0]))
        project = Project.create(deposit_metadata)
        video_1['_project_id'] = project['_deposit']['id']
        video_1 = Video.create(video_1)
        prepare_videos_for_publish([video_1])
        video_1.commit()
        id_ = project.id
        db.session.expire_all()
        project = Project.get_record(id_)
        assert project is not None
        # if publish, then generate an validation error
        with pytest.raises(ValidationError):
            project.publish()
        # patch project
        patch = [{
            'op': 'add',
            'path': '/category',
            'value': 'bar',
        }]
        id_ = project.id
        db.session.expire_all()
        project = Project.get_record(id_)
        project.patch(patch).commit()
        # update project
        copy = deepcopy(project)
        copy['category'] = 'qwerty'
        id_ = project.id
        db.session.expire_all()
        project = Project.get_record(id_)
        project.update(copy)
        # assert not raise a validation exception
        project.commit()