Пример #1
0
def test_package_objects(client, client2, dataset):
    """
    Only super-users are allowed to create/modify package sources/files.
    """
    pkg = DataPackage('Some Video', package_type='Video')
    assert not pkg.exists

    # some files (local for now)
    source = File(name='My Source File',
                  s3_key='s3/source',
                  s3_bucket='my-bucket',
                  file_type="JSON",
                  size=1000)
    file = File(name='My File',
                s3_key='s3/file',
                s3_bucket='my-bucket',
                file_type="CSV",
                size=1000)
    view = File(name='My View File',
                s3_key='s3/view',
                s3_bucket='my-bucket',
                file_type="NIFTI",
                size=1000)

    # get dataset (but as different client)
    dataset2 = client2._api.datasets.get(dataset.id)

    assert dataset2.id == dataset.id
    assert dataset2.exists

    # create package (super-admin user session)
    dataset2.add(pkg)
    assert pkg.exists

    # create package (normal user owns)
    pkg = DataPackage('Some Video', package_type='Video')
    assert not pkg.exists
    dataset.add(pkg)
    assert pkg.exists

    # try doing as normal user - should error
    with pytest.raises(UnauthorizedException):
        pkg.set_sources(source)

    with pytest.raises(UnauthorizedException):
        pkg.set_files(file)

    with pytest.raises(UnauthorizedException):
        pkg.set_view(view)
Пример #2
0
def test_package_objects(client, superuser_client, dataset):
    """
    Only super-users are allowed to create/modify package sources/files.
    """
    pkg = DataPackage('Some Video', package_type='Video')
    assert not pkg.exists

    # some files (local for now)
    source = File(name='My Source File',
                  s3_key='s3/source',
                  s3_bucket='my-bucket',
                  file_type="JSON")
    file = File(name='My File',
                s3_key='s3/file',
                s3_bucket='my-bucket',
                file_type="CSV")
    view = File(name='My View File',
                s3_key='s3/view',
                s3_bucket='my-bucket',
                file_type="NIFTI")

    # get dataset (but as super-user)
    superuser_dataset = superuser_client.get(dataset.id)
    assert superuser_dataset.id == dataset.id
    assert superuser_dataset.exists
    assert superuser_dataset.type == dataset.type

    # create package (super-admin user session)
    superuser_dataset.add(pkg)
    assert pkg.exists

    # add source (super-admin)
    pkg.set_sources(source)

    # get as normal user
    pkg2 = client.get(pkg)
    print "sources =", pkg2.sources
    assert len(pkg2.sources) > 0
    assert pkg2.sources[0].name == 'My Source File'
    del pkg2

    # add files (super-admin)
    pkg.set_files(file)

    # get as normal user
    pkg2 = client.get(pkg)
    print "files =", pkg2.files
    assert len(pkg2.files) > 0
    del pkg2

    # add views (super-admin)
    pkg.set_view(view)

    # get as normal user
    pkg2 = client.get(pkg)
    print "view =", pkg2.view
    assert len(pkg2.view) > 0
    del pkg2
    del pkg

    # create package (normal user owns)
    pkg = DataPackage('Some Video', package_type='Video', parent=dataset)
    assert not pkg.exists
    dataset.add(pkg)
    assert pkg.exists

    # try doing as normal user - should error
    with pytest.raises(UnauthorizedException):
        pkg.set_sources(source)

    with pytest.raises(UnauthorizedException):
        pkg.set_files(file)

    with pytest.raises(UnauthorizedException):
        pkg.set_view(view)