本文整理汇总了Python中tardis.tardis_portal.models.Experiment.save方法的典型用法代码示例。如果您正苦于以下问题:Python Experiment.save方法的具体用法?Python Experiment.save怎么用?Python Experiment.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tardis.tardis_portal.models.Experiment
的用法示例。
在下文中一共展示了Experiment.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
def setUp(self):
# Create test owner without enough details
username, email, password = ("testuser", "[email protected]", "password")
user = User.objects.create_user(username, email, password)
# Need UserAuthentication
UserAuthentication(userProfile=user.userprofile, username=username, authenticationMethod="localdb").save()
# Create staging dir
from os import path, makedirs
staging_dir = path.join(settings.STAGING_PATH, username)
if not path.exists(staging_dir):
makedirs(staging_dir)
# Ensure that staging dir is set up properly
expect(get_full_staging_path(username)).to_be_truthy()
# 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 = ObjectACL(
pluginId=django_user,
entityId=str(user.id),
content_object=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED,
)
acl.save()
self.dataset = Dataset(description="dataset description...")
self.dataset.save()
self.dataset.experiments.add(experiment)
self.dataset.save()
self.username, self.password = (username, password)
示例2: _create_test_experiment
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
def _create_test_experiment(user, license_):
experiment = Experiment(title='Norwegian Blue',
description='Parrot + 40kV',
created_by=user)
experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
experiment.license = license_
experiment.save()
experiment.experimentauthor_set.create(
order=0,
author="John Cleese",
url="http://nla.gov.au/nla.party-1")
experiment.experimentauthor_set.create(
order=1,
author="Michael Palin",
url="http://nla.gov.au/nla.party-2")
acl = ObjectACL(content_object=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ObjectACL.OWNER_OWNED)
acl.save()
return experiment
示例3: _get_experiment
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
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 = ObjectACL(content_object=experiment,
pluginId=django_user,
entityId=user.id,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED)
acl.save()
return experiment
示例4: _create_test_data
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
def _create_test_data():
user = User(username='tom',
first_name='Thomas',
last_name='Atkins',
email='[email protected]')
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.experimentauthor_set.create(order=0,
author="John Cleese",
url="http://nla.gov.au/nla.party-1")
experiment.experimentauthor_set.create(order=1,
author="Michael Palin",
url="http://nla.gov.au/nla.party-2")
acl = ObjectACL(content_object=experiment,
pluginId='django_user',
entityId=str(user.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ObjectACL.OWNER_OWNED)
acl.save()
return user, experiment
示例5: testRightsRequireValidOwner
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
def testRightsRequireValidOwner(self):
# Create test owner without enough details
username, email, password = ("testuser", "[email protected]", "password")
user = User.objects.create_user(username, email, password)
# 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 = ObjectACL(
pluginId=django_user,
entityId=str(user.id),
content_object=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.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)
示例6: IntegrityCheckTestCase
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
class IntegrityCheckTestCase(TestCase):
def _make_dataset(self, exp, filenames):
dataset = Dataset(experiment=exp)
dataset.save()
for filename in filenames:
df = Dataset_File(dataset=dataset, size=41, protocol='file')
df.filename = filename
df.url = 'file://' + path.join(path.dirname(__file__), 'data', df.filename)
df.save()
def setUp(self):
self.user = User(username='user1', password='password', email='[email protected]')
self.user.save()
self.bad_exp = Experiment(
approved = True,
title = 'title1',
institution_name = 'institution1',
description = 'description1',
created_by = self.user,
public_access = Experiment.PUBLIC_ACCESS_FULL
)
self.bad_exp.save()
self.bad_dataset = self._make_dataset(self.bad_exp, [
'file_that_exists',
'file_that_exists_too',
'file_that_exists_but_is_empty',
'file_that_doesnt_exist',
])
self.good_exp = Experiment(
approved = True,
title = 'title1',
institution_name = 'institution1',
description = 'description1',
created_by = self.user,
public_access = Experiment.PUBLIC_ACCESS_FULL
)
self.good_exp.save()
self.good_dataset = self._make_dataset(self.good_exp, [
'file_that_exists',
'file_that_exists_too'
])
def testBadExperimentFails(self):
result = IntegrityCheck(self.bad_exp).get_datafiles_integrity()
self.assertEqual(result['files_ok'], 2)
self.assertEqual(result['files_incomplete'], 1)
self.assertEqual(result['files_missing'], 1)
good_or_bad = IntegrityCheck(self.bad_exp).all_files_complete()
self.assertFalse(good_or_bad)
def testGoodExperimentPasses(self):
result = IntegrityCheck(self.good_exp).get_datafiles_integrity()
self.assertEqual(result['files_ok'], 2)
self.assertEqual(result['files_incomplete'], 0)
self.assertEqual(result['files_missing'], 0)
good_or_bad = IntegrityCheck(self.good_exp).all_files_complete()
self.assertTrue(good_or_bad)
示例7: _create_test_data
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
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)
示例8: MRtaskTestCase
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
class MRtaskTestCase(TestCase):
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.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)
def test_mrtask(self):
self.assertEqual(len(self.test_mrtask.parameters), 0)
示例9: setUp
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
def setUp(self):
self.client = Client()
# old_user
user_old_username = 'tardis_user1'
# new_user
user_new_username = 'tardis_user2'
pwd = 'secret'
email = '[email protected]'
self.user_new = User.objects.create_user(user_new_username, email, pwd)
self.user_old = User.objects.create_user(user_old_username, email, pwd)
# create group
self.group = Group.objects.create(name='test group')
# add old user to group
self.group.user_set.add(self.user_old)
# add user auth
user_auth = UserAuthentication(userProfile=UserProfile.objects.get(user=self.user_old),
username= self.user_old.username,
authenticationMethod='localdb')
user_auth.save()
# add experiments
experiment = Experiment(title='Text Experiment',
institution_name='Test Uni',
created_by=self.user_old)
experiment.save()
acl = ObjectACL(
pluginId='django_user',
entityId=str(self.user_old.id),
content_object=experiment,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED,
)
acl.save()
示例10: setUp
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
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 = ObjectACL(
pluginId='django_user',
entityId=str(user.id),
content_object=experiment,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED)
acl.save()
dataset = Dataset(description='dataset description...')
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
def create_datafile(filename):
testfile = path.join(path.dirname(__file__), 'fixtures',
filename)
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-grabber', 'url': base_url, 'type': 'external',
'priority': 10, 'transfer_provider': 'local'})
replica = Replica(datafile=datafile,
url='file://'+path.abspath(testfile),
protocol='file',
location=location)
replica.verify()
replica.save()
return Dataset_File.objects.get(pk=datafile.pk)
self.dataset = dataset
self.datafiles = [create_datafile('data_grabber_test1.admin'),
create_datafile('testfile.txt')
]
示例11: createhpcexperiment
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
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
示例12: TarDownloadTestCase
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
class TarDownloadTestCase(TestCase):
def setUp(self):
# create user
self.testuser = User(username="testuser")
self.testuser.save()
# create test experiment
self.exp = Experiment(
title="tar download test" * 15, created_by=self.testuser, public_access=Experiment.PUBLIC_ACCESS_FULL
)
self.exp.save()
# create test dataset
self.ds = self.exp.datasets.create(description="testing tar download dataset")
datafile_content = "\n".join(["some data %d" % i for i in range(1000)])
filesize = len(datafile_content)
md5sum = hashlib.md5(datafile_content).hexdigest()
# create test datafiles and datafile objects
self.dfs = []
for i in range(20):
df = self.ds.datafile_set.create(
filename="testfile%d.txt" % i,
mimetype="text/plain",
size=filesize,
md5sum=md5sum,
directory="/".join(["testdir%d" % i for i in range(i, i + 4)]),
)
df.file_object = StringIO(datafile_content)
df.refresh_from_db()
self.dfs.append(df)
# mock client
self.client = Client()
def tearDown(self):
# delete created objects and files
[ds.delete() for ds in self.exp.datasets.all()]
self.exp.delete()
def test_tar_experiment_download(self):
self.assertTrue(all(df.verified for df in self.dfs))
response = self.client.get(
reverse("tardis.tardis_portal.download.streaming_download_experiment", args=(self.exp.id, "tar"))
)
with NamedTemporaryFile("w") as tarfile:
for c in response.streaming_content:
tarfile.write(c)
tarfile.flush()
self.assertEqual(int(response["Content-Length"]), os.stat(tarfile.name).st_size)
tf = TarFile(tarfile.name)
for df in self.dfs:
full_path = os.path.join(
self.exp.title.replace(" ", "_"), self.ds.description, df.directory, df.filename
)
tf.extract(full_path, "/tmp")
self.assertEqual(os.stat(os.path.join("/tmp", full_path)).st_size, int(df.size))
示例13: _create_test_data
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
def _create_test_data():
"""
Create Single experiment with two owners
"""
user1 = User(username='tom',
first_name='Thomas',
last_name='Atkins',
email='[email protected]')
user1.save()
UserProfile(user=user1).save()
user2 = User(username='joe',
first_name='Joe',
last_name='Bloggs',
email='[email protected]')
user2.save()
UserProfile(user=user2).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=user1)
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")
acl1 = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user1.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl1.save()
acl2 = ExperimentACL(experiment=experiment,
pluginId='django_user',
entityId=str(user2.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ExperimentACL.OWNER_OWNED)
acl2.save()
return (user1, user2, experiment)
示例14: testNeverExpire
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
def testNeverExpire(self):
experiment = Experiment(created_by=self.user, end_time=dt.datetime(1999,4,3))
experiment.save()
eh = EmbargoHandler(experiment.id, True)
self.assertFalse(eh.never_expires())
eh.prevent_expiry()
self.assertTrue(eh.never_expires())
self.assertFalse(eh.because_no_end_date())
示例15: create_draft_publication
# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import save [as 别名]
def create_draft_publication(user, publication_title, publication_description):
# Note: Maybe this logic can be taken from the tardis_portal/views.py?
experiment = Experiment(created_by=user,
title=publication_title,
description=publication_description)
experiment.save()
ObjectACL(content_object=experiment,
pluginId=django_user,
entityId=str(user.id),
canRead=True,
canWrite=False,
canDelete=False,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED).save()
ObjectACL(content_object=experiment,
pluginId=django_group,
entityId=str(
Group.objects.get_or_create(
name=getattr(
settings, 'PUBLICATION_OWNER_GROUP',
default_settings.PUBLICATION_OWNER_GROUP))[0].id),
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True,
aclOwnershipType=ObjectACL.OWNER_OWNED).save()
publication_schema = Schema.objects.get(
namespace=getattr(settings, 'PUBLICATION_SCHEMA_ROOT',
default_settings.PUBLICATION_SCHEMA_ROOT))
# Attach draft schema
draft_publication_schema = Schema.objects.get(
namespace=getattr(settings, 'PUBLICATION_DRAFT_SCHEMA',
default_settings.PUBLICATION_DRAFT_SCHEMA))
ExperimentParameterSet(schema=draft_publication_schema,
experiment=experiment).save()
# Attach root schema and blank form_state parameter
publication_root_schema = Schema.objects.get(
namespace=getattr(settings, 'PUBLICATION_SCHEMA_ROOT',
default_settings.PUBLICATION_SCHEMA_ROOT))
publication_root_parameter_set = ExperimentParameterSet(
schema=publication_schema,
experiment=experiment)
publication_root_parameter_set.save()
form_state_param_name = ParameterName.objects.get(
schema=publication_root_schema, name='form_state')
ExperimentParameter(name=form_state_param_name,
parameterset=publication_root_parameter_set).save()
return experiment