Пример #1
0
def new_project(app,
                es,
                cds_jsonresolver,
                users,
                location,
                db,
                deposit_metadata,
                project_data=None,
                wait=None):
    """New project with videos."""
    project_data = project_data or {
        'title': {
            'title': 'my project',
        },
        'description': 'in tempor reprehenderit enim eiusmod',
    }
    project_data.update(deposit_metadata)
    project_video_1 = {
        'title': {
            'title': 'video 1',
        },
        'description': 'in tempor reprehenderit enim eiusmod',
        'featured': True,
        'vr': True,
        'language': 'en',
        'date': '2017-09-25',
    }
    project_video_1.update(deposit_metadata)
    project_video_2 = {
        'title': {
            'title': 'video 2',
        },
        'description': 'in tempor reprehenderit enim eiusmod',
        'featured': False,
        'vr': False,
        'language': 'en',
        'date': '2017-09-25',
    }
    project_video_2.update(deposit_metadata)
    with app.test_request_context():
        login_user(User.query.get(users[0]))

        # create empty project
        project = Project.create(project_data).commit()

        # create videos
        project_video_1['_project_id'] = project['_deposit']['id']
        project_video_2['_project_id'] = project['_deposit']['id']
        video_1 = Video.create(project_video_1)
        video_2 = Video.create(project_video_2)

        # save project and video
        project.commit()
        video_1.commit()
        video_2.commit()

    db.session.commit()
    if wait is not False:
        sleep(2)
    return project, video_1, video_2
Пример #2
0
def test_add_video(app, es, cds_jsonresolver, users, location):
    """Test add video."""
    project_data = {
        'title': {
            'title': 'my project',
        },
        'videos': [],
    }

    login_user(User.query.get(users[0]))

    # create empty project
    project = Project.create(project_data).commit()

    # check project <--/--> video
    assert project['videos'] == []

    # create video
    project_video_1 = {
        'title': {
            'title': 'video 1',
        },
        '_project_id': project['_deposit']['id'],
    }
    video_1 = Video.create(project_video_1)

    # check project <----> video
    assert project._find_refs([video_1.ref])
    assert video_1.project.id == project.id
Пример #3
0
def test_sync_records_with_deposits(app, db, location, users,
                                    project_deposit_metadata,
                                    video_deposit_metadata):
    """Test sync records with deposits task."""
    # create a project
    project = Project.create(project_deposit_metadata)
    project_deposit_metadata['report_number'] = ['123']
    # create new video
    video_deposit_metadata['_project_id'] = project['_deposit']['id']
    deposit = Video.create(video_deposit_metadata)
    depid = deposit['_deposit']['id']

    # insert objects inside the deposit
    ObjectVersion.create(deposit.files.bucket,
                         "obj_1").set_location("mylocation1", 1, "mychecksum1")
    ObjectVersion.create(deposit.files.bucket,
                         "obj_2").set_location("mylocation2", 1, "mychecksum2")
    ObjectVersion.create(deposit.files.bucket,
                         "obj_3").set_location("mylocation3", 1, "mychecksum3")
    obj_4 = ObjectVersion.create(deposit.files.bucket,
                                 "obj_4").set_location("mylocation4", 1,
                                                       "mychecksum4")

    # publish
    login_user(User.query.get(users[0]))
    prepare_videos_for_publish([deposit])
    deposit = deposit.publish()
    _, record = deposit.fetch_published()
    assert deposit.is_published() is True

    # add a new object
    ObjectVersion.create(deposit.files.bucket,
                         "obj_new").set_location("mylocation_new", 1,
                                                 "mychecksum")
    # modify obj_1
    ObjectVersion.create(deposit.files.bucket,
                         "obj_new").set_location("mylocation2.1", 1,
                                                 "mychecksum2.1")
    # delete obj_3
    ObjectVersion.delete(deposit.files.bucket, "obj_3")
    # remove obj_4
    obj_4.remove()

    # check video and record
    files = ['obj_1', 'obj_2', 'obj_3', 'obj_4']
    edited_files = ['obj_1', 'obj_2', 'obj_3', 'obj_new']
    check_deposit_record_files(deposit, edited_files, record, files)

    # try to sync deposit and record
    sync_records_with_deposit_files.s(deposit_id=depid).apply_async()

    # get deposit and record
    deposit = deposit_video_resolver(depid)
    _, record = deposit.fetch_published()
    assert deposit.is_published() is True

    # check that record and deposit are sync
    re_edited_files = edited_files + ['obj_4']
    check_deposit_record_files(deposit, edited_files, record, re_edited_files)
Пример #4
0
def test_project_permissions(es, location, deposit_metadata, users):
    """Test deposit permissions."""
    deposit = Project.create(deposit_metadata)
    deposit.commit()
    user = User.query.get(users[0])
    login_user(user)
    assert not has_update_permission(user, deposit)
    deposit['_access'] = {'update': [user.id]}
    assert has_update_permission(user, deposit)
Пример #5
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
Пример #6
0
def cds_depid(api_app, users, db, bucket, deposit_metadata):
    """New deposit with files."""
    record = {'title': {'title': 'fuu'}}
    record.update(deposit_metadata)
    with api_app.test_request_context():
        login_user(User.query.get(users[0]))
        deposit = Project.create(record)
        deposit['_access'] = {'update': ['*****@*****.**']}
        deposit.commit()
        db.session.commit()
    return deposit['_deposit']['id']
Пример #7
0
def test_add_video(api_app, es, cds_jsonresolver, users, location,
                   project_deposit_metadata, video_deposit_metadata):
    """Test add video."""
    project_data = deepcopy(project_deposit_metadata)

    login_user(User.query.get(users[0]))

    # create empty project
    project = Project.create(project_data).commit()

    # check default project license
    assert project['license'] == [{
        'license': 'CERN',
        'material': '',
        'url': 'http://copyright.web.cern.ch',
    }]

    # check default copyright
    assert 'copyright' not in project

    # check project <--/--> video
    assert project['videos'] == []

    # create video
    project_video_1 = deepcopy(video_deposit_metadata)
    if 'license' in project_video_1:
        del project_video_1['license']
    if 'copyright' in project_video_1:
        del project_video_1['copyright']
    project_video_1['title']['title'] = 'video 1'
    project_video_1['_project_id'] = project['_deposit']['id']
    video_1 = Video.create(project_video_1)

    # check default video license
    assert video_1['license'] == [{
        'license': 'CERN',
        'material': '',
        'url': 'http://copyright.web.cern.ch',
    }]

    # check default video copyright
    year = str(datetime.date.today().year)
    assert video_1['copyright'] == {
        'holder': 'CERN',
        'year': year,
        'url': 'http://copyright.web.cern.ch',
    }

    # check project <----> video
    assert project._find_refs([video_1.ref])
    assert video_1.project.id == project.id
Пример #8
0
def project(app, deposit_rest, es, cds_jsonresolver, users, location, db):
    """New project with videos."""
    project_data = {
        'title': {
            'title': 'my project',
        },
        'description': {
            'value': 'in tempor reprehenderit enim eiusmod',
        },
    }
    project_video_1 = {
        'title': {
            'title': 'video 1',
        },
        'description': {
            'value': 'in tempor reprehenderit enim eiusmod',
        },
    }
    project_video_2 = {
        'title': {
            'title': 'video 2',
        },
        'description': {
            'value': 'in tempor reprehenderit enim eiusmod',
        },
    }
    with app.test_request_context():
        login_user(User.query.get(users[0]))

        # create empty project
        project = Project.create(project_data).commit()

        # create videos
        project_video_1['_project_id'] = project['_deposit']['id']
        project_video_2['_project_id'] = project['_deposit']['id']
        video_1 = Video.create(project_video_1)
        video_2 = Video.create(project_video_2)

        # save project and video
        project.commit()
        video_1.commit()
        video_2.commit()

    db.session.commit()
    sleep(2)
    return (project, video_1, video_2)
Пример #9
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()
def test_links_filter(app, es, location, deposit_metadata):
    """Test Jinja to_links_js filter."""
    assert to_links_js(None) == []
    deposit = Project.create(deposit_metadata)
    links = to_links_js(deposit.pid, deposit)
    assert all([key in links for key in ['self', 'edit', 'publish', 'bucket',
               'files', 'html', 'discard']])
    self_url = links['self']
    assert links['discard'] == self_url + '/actions/discard'
    assert links['edit'] == self_url + '/actions/edit'
    assert links['publish'] == self_url + '/actions/publish'
    assert links['files'] == self_url + '/files'
    links_type = to_links_js(deposit.pid, deposit, 'project')
    self_url_type = links_type['self']
    assert links_type['discard'] == self_url_type + '/actions/discard'
    assert links_type['edit'] == self_url_type + '/actions/edit'
    assert links_type['publish'] == self_url_type + '/actions/publish'
    assert links_type['files'] == self_url_type + '/files'
    with app.test_client() as client:
        data = client.get(links_type['html']).get_data().decode('utf-8')
        for key in links_type:
            assert links_type[key] in data