本文整理汇总了Python中tardis.tardis_portal.models.ExperimentACL类的典型用法代码示例。如果您正苦于以下问题:Python ExperimentACL类的具体用法?Python ExperimentACL怎么用?Python ExperimentACL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExperimentACL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_test_data
def _create_test_data():
user = User(username='tom',
first_name='Thomas',
last_name='Atkins',
email='[email protected]')
user.save()
user2 = User(username='otheradmin', email='[email protected]')
user2.save()
map(lambda u: UserProfile(user=u).save(), [user, user2])
license_ = License(name='Creative Commons Attribution-NoDerivs 2.5 Australia',
url='http://creativecommons.org/licenses/by-nd/2.5/au/',
internal_description='CC BY 2.5 AU',
allows_distribution=True)
license_.save()
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
experiment.license = license_
experiment.save()
acl = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user2.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return (user, experiment)
示例2: _create_test_data
def _create_test_data():
user = User(username='tom',
first_name='Thomas',
last_name='Atkins',
email='[email protected]')
user.save()
UserProfile(user=user).save()
license_ = License(name='Creative Commons Attribution-NoDerivs 2.5 Australia',
url='http://creativecommons.org/licenses/by-nd/2.5/au/',
internal_description='CC BY 2.5 AU',
allows_distribution=True)
license_.save()
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
experiment.license = license_
experiment.save()
experiment.author_experiment_set.create(order=0,
author="John Cleese",
url="http://nla.gov.au/nla.party-1")
experiment.author_experiment_set.create(order=1,
author="Michael Palin",
url="http://nla.gov.au/nla.party-2")
acl = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return (user, experiment)
示例3: _get_experiment
def _get_experiment(self, entry, user):
experimentId, title, public_access = \
self._get_experiment_details(entry, user)
try:
try:
param_name = ParameterName.objects.\
get(name=self.PARAM_EXPERIMENT_ID, \
schema=AtomImportSchemas.get_schema(Schema.EXPERIMENT))
parameter = ExperimentParameter.objects.\
get(name=param_name, string_value=experimentId)
except ExperimentParameter.DoesNotExist:
raise Experiment.DoesNotExist
return parameter.parameterset.experiment
except Experiment.DoesNotExist:
experiment = Experiment(title=title,
created_by=user,
public_access=public_access)
experiment.save()
self._create_experiment_id_parameter_set(experiment, experimentId)
acl = ExperimentACL(experiment=experiment,
pluginId=django_user,
entityId=user.id,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return experiment
示例4: setUp
def setUp(self):
from django.contrib.auth.models import User
from tardis.tardis_portal.models import Experiment
from tardis.tardis_portal.models import ExperimentACL
from tardis.tardis_portal.models import Dataset
from tardis.apps.mrtardis.mrtask import MRtask
user = 'tardis_user1'
pwd = 'secret'
email = ''
self.user = User.objects.create_user(user, email, pwd)
self.client = Client()
self.client.login(username=user, password=pwd)
self.experiment = Experiment(approved=True,
title="Test Experiment",
institution_name="Test Institution",
created_by=self.user,
public=False)
self.experiment.save()
acl = ExperimentACL(pluginId="django_user",
entityId="1",
experiment=self.experiment,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True)
acl.save()
self.test_dataset = Dataset(experiment=self.experiment,
description="test dataset")
self.test_dataset.save()
self.test_mrtask = MRtask(dataset=self.test_dataset)
示例5: createhpcexperiment
def createhpcexperiment(request, user, dl):
from django.contrib.auth.models import User
from tardis.tardis_portal.views import _registerExperimentDocument
import os
import tempfile
# TODO
temp = tempfile.TemporaryFile()
for chunk in dl.chunks():
temp.write(chunk)
temp.seek(0)
metadata = {}
for line in temp:
key, value = line.split("~")
metadata[key] = value
temp.close()
author = metadata["Name"]
title = metadata["Experiment"]
ds_desc = metadata["Facility"]
desc = metadata["Description"]
fname = metadata["FolderName"]
counter = metadata["Counter"]
package = metadata["Package"]
exp = Experiment(
title=title, institution_name="RMIT University", description=desc, created_by=User.objects.get(id=user.pk)
)
exp.save()
eid = exp.id
# Store the author for the dataset
ae = models.Author_Experiment(experiment=exp, author=author, order="1")
ae.save()
auth_key = settings.DEFAULT_AUTH
try:
e = Experiment.objects.get(pk=eid)
except Experiment.DoesNotExist:
logger.exception("Experiment for eid %i in CreateHPCExperiment does not exist" % eid)
acl = ExperimentACL(
experiment=e,
pluginId=django_user,
entityId=str(user.id),
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
folder_desc = "%s.%s.%s.%s" % (ds_desc.strip(), package.strip(), fname.strip(), counter.strip())
logger.debug("folder_desc = %s" % folder_desc)
return eid, exp, folder_desc
示例6: setUp
def setUp(self):
from os import path, mkdir
from tempfile import mkdtemp
user = 'tardis_user1'
pwd = 'secret'
email = ''
self.user = User.objects.create_user(user, email, pwd)
self.userProfile = UserProfile(user=self.user)
self.test_dir = mkdtemp()
Location.force_initialize()
self.exp = Experiment(title='test exp1',
institution_name='monash', created_by=self.user)
self.exp.save()
acl = ExperimentACL(
pluginId=django_user,
entityId=str(self.user.id),
experiment=self.exp,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
self.dataset = \
Dataset(description='dataset description...')
self.dataset.save()
self.dataset.experiments.add(self.exp)
self.dataset.save()
self.experiment_path = path.join(settings.FILE_STORE_PATH,
str(self.dataset.get_first_experiment().id))
self.dataset_path = path.join(self.experiment_path,
str(self.dataset.id))
if not path.exists(self.experiment_path):
mkdir(self.experiment_path)
if not path.exists(self.dataset_path):
mkdir(self.dataset_path)
# write test file
self.filename = 'testfile.txt'
self.f1 = open(path.join(self.test_dir, self.filename), 'w')
self.f1.write('Test file 1')
self.f1.close()
self.f1_size = path.getsize(path.join(self.test_dir,
self.filename))
self.f1 = open(path.join(self.test_dir, self.filename), 'r')
示例7: setUp
def setUp(self):
# Create test owner without enough details
username, email, password = ('testuser',
'[email protected]',
'password')
user = User.objects.create_user(username, email, password)
profile = UserProfile(user=user, isDjangoAccount=True)
profile.save()
Location.force_initialize()
# Create test experiment and make user the owner of it
experiment = Experiment(title='Text Experiment',
institution_name='Test Uni',
created_by=user)
experiment.save()
acl = ExperimentACL(
pluginId='django_user',
entityId=str(user.id),
experiment=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
dataset = Dataset(description='dataset description...')
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
def create_datafile(index):
testfile = path.join(path.dirname(__file__), 'fixtures',
'middleware_test%d.txt' % index)
size, sha512sum = get_size_and_sha512sum(testfile)
datafile = Dataset_File(dataset=dataset,
filename=path.basename(testfile),
size=size,
sha512sum=sha512sum)
datafile.save()
base_url = 'file://' + path.abspath(path.dirname(testfile))
location = Location.load_location({
'name': 'test-middleware', 'url': base_url, 'type': 'external',
'priority': 10, 'transfer_provider': 'local'})
replica = Replica(datafile=datafile,
url='file://'+path.abspath(testfile),
protocol='file',
location=location)
if index == 1:
replica.verify()
replica.save()
return Dataset_File.objects.get(pk=datafile.pk)
self.dataset = dataset
self.datafiles = [create_datafile(i) for i in (1,2)]
示例8: _get_experiment
def _get_experiment(self, entry, user):
'''
Finds the Experiment corresponding to this entry.
If it doesn't exist, a new Experiment is created and given
an appropriate ACL for the user.
'''
experimentId, title, public_access = self._get_experiment_details(entry, user)
if (experimentId, title) == (None, None):
return None
if experimentId:
try:
# Try and match ExperimentID if we have one.
param_name = ParameterName.objects.\
get(name=IngestOptions.PARAM_EXPERIMENT_ID, \
schema=AtomImportSchemas.get_schema(Schema.EXPERIMENT))
parameter = ExperimentParameter.objects.\
get(name=param_name, string_value=experimentId)
return parameter.parameterset.experiment
except ExperimentParameter.DoesNotExist:
pass
# Failing that, match ExperimentTitle if possible
if title:
try:
experiment = Experiment.objects.get(title=title, created_by=user)
return experiment
except Experiment.DoesNotExist:
pass
# No existing expriment - shall we create a new one?
if not IngestOptions.ALLOW_EXPERIMENT_CREATION:
logging.getLogger(__name__).info("Skipping dataset. ALLOW_EXPERIMENT_CREATION disabled, so ignoring (experimentId: {0}, title: {1}, user: {2})".format(
experimentId, title, user))
return None
experiment = Experiment(title=title, created_by=user, public_access=public_access)
experiment.save()
self._create_experiment_id_parameter_set(experiment, experimentId)
logging.getLogger(__name__).info("Created experiment {0} (title: {1}, user: {2}, experimentId: {3})".format(
experiment.id, experiment.title, experiment.created_by, experimentId))
acl = ExperimentACL(experiment=experiment,
pluginId=django_user,
entityId=user.id,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return experiment
示例9: create_experiment
def create_experiment(i):
experiment = Experiment(title='Text Experiment #%d' % i,
institution_name='Test Uni',
created_by=user)
experiment.save()
acl = ExperimentACL(
pluginId=django_user,
entityId=str(user.id),
experiment=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
return experiment
示例10: setUp
def setUp(self):
# Create test owner without enough details
username, email, password = ('testuser',
'[email protected]',
'password')
user = User.objects.create_user(username, email, password)
profile = UserProfile(user=user, isDjangoAccount=True)
profile.save()
# Create test experiment and make user the owner of it
experiment = Experiment(title='Text Experiment',
institution_name='Test Uni',
created_by=user)
experiment.save()
acl = ExperimentACL(
pluginId='django_user',
entityId=str(user.id),
experiment=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
dataset = Dataset(description='dataset description...')
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
def create_datafile(index):
testfile = path.join(path.dirname(__file__), 'fixtures',
'jeol_sem_test%d.txt' % index)
size, sha512sum = get_size_and_sha512sum(testfile)
datafile = Dataset_File(dataset=dataset,
filename=path.basename(testfile),
url='file://'+path.abspath(testfile),
protocol='file',
size=size,
sha512sum=sha512sum)
datafile.verify()
datafile.save()
return datafile
self.dataset = dataset
self.datafiles = [create_datafile(i) for i in (1,2)]
示例11: test_publish
def test_publish(self):
""" Create an experiment and publish it as RIF-CS using RMITANDSService"""
login = self.client.login(username=self.username,
password=self.pwd)
self.assertTrue(login)
# Create simple experiment
exp = models.Experiment(title='test exp1',
institution_name='rmit',
created_by=self.user,
public=True
)
exp.save()
acl = ExperimentACL(
pluginId=django_user,
entityId=str(self.user.id),
experiment=exp,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
self.assertEqual(exp.title, 'test exp1')
self.assertEqual(exp.url, None)
self.assertEqual(exp.institution_name, 'rmit')
self.assertEqual(exp.approved, False)
self.assertEqual(exp.handle, None)
self.assertEqual(exp.created_by, self.user)
self.assertEqual(exp.public, True)
self.assertEqual(exp.get_or_create_directory(),
path.join(settings.FILE_STORE_PATH, str(exp.id)))
self.experiment_path = path.join(settings.FILE_STORE_PATH, str(exp.id))
# publish
data = {'legal':'on',
'profile':'default.xml'}
response = self.client.post("/apps/hpctardis/publisher/1/", data)
logger.debug("response=%s" % response)
# check resulting rif-cs
response = self.client.post("/apps/hpctardis/rif_cs/")
self.assertTrue(_grep("test exp1",str(response)))
self.assertTrue(_grep("<key>http://www.rmit.edu.au/HPC/1</key>",str(response)))
self.assertTrue(_grep("""<addressPart type="text">rmit</addressPart>""",str(response)))
self.assertFalse(_grep("<key>http://www.rmit.edu.au/HPC/2</key>",str(response)))
logger.debug("response=%s" % response)
示例12: generate_experiment
def generate_experiment(datasets=[], users=[]):
from tardis.tardis_portal.models import Experiment, ExperimentACL
experiment = Experiment(created_by=users[0])
experiment.save()
for ds in datasets:
ds.experiments.add(experiment)
ds.save()
for user in users:
acl = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
return experiment
示例13: setUp
def setUp(self):
user, client = _create_user_and_login()
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
experiment.save()
acl = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=False,
canRead=True,
canWrite=False,
canDelete=False,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
self.client = client
self.experiment = experiment
示例14: setUp
def setUp(self):
self.ns = {'r': 'http://ands.org.au/standards/rif-cs/registryObjects',
'o': 'http://www.openarchives.org/OAI/2.0/'}
user, client = _create_user_and_login()
license_ = License(name='Creative Commons Attribution-NoDerivs 2.5 Australia',
url='http://creativecommons.org/licenses/by-nd/2.5/au/',
internal_description='CC BY 2.5 AU',
allows_distribution=True)
license_.save()
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
experiment.license = license_
experiment.save()
acl = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=False,
canRead=True,
canWrite=True,
canDelete=False,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl.save()
params = {'type': 'website',
'identifier': 'https://www.google.com/',
'title': 'Google',
'notes': 'This is a note.'}
response = client.post(\
reverse('tardis.apps.related_info.views.'\
+'list_or_create_related_info',
args=[experiment.id]),
data=json.dumps(params),
content_type='application/json')
# Check related info was created
expect(response.status_code).to_equal(201)
self.acl = acl
self.client = client
self.experiment = experiment
self.params = params
示例15: testRightsRequireValidOwner
def testRightsRequireValidOwner(self):
# Create test owner without enough details
username, email, password = ('testuser',
'[email protected]',
'password')
user = User.objects.create_user(username, email, password)
profile = UserProfile(user=user, isDjangoAccount=True)
profile.save()
# Create test experiment and make user the owner of it
experiment = Experiment(title='Text Experiment',
institution_name='Test Uni',
created_by=user)
experiment.save()
acl = ExperimentACL(
pluginId=django_user,
entityId=str(user.id),
experiment=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED,
)
acl.save()
# Create client and login as user
client = Client()
login = client.login(username=username, password=password)
self.assertTrue(login)
# Get "Choose Rights" page, and check that we're forbidden
rights_url = reverse('tardis.tardis_portal.views.choose_rights',
args=[str(experiment.id)])
response = client.get(rights_url)
expect(response.status_code).to_equal(403)
# Fill in remaining details
user.first_name = "Voltaire" # Mononymous persons are just fine
user.save()
# Get "Choose Rights" page, and check that we're now allowed access
response = client.get(rights_url)
expect(response.status_code).to_equal(200)