本文整理汇总了Python中tardis.tardis_portal.models.Dataset.save方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.save方法的具体用法?Python Dataset.save怎么用?Python Dataset.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tardis.tardis_portal.models.Dataset
的用法示例。
在下文中一共展示了Dataset.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MRtaskTestCase
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset 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)
示例2: test_datasetwrapper
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
def test_datasetwrapper(self):
from mecat.models import DatasetWrapper, Sample
sample_desc = "My Description for Sample created in test_datasetwrapper()"
sample = Sample(experiment=self.experiment, description=sample_desc)
sample.save()
self.assertEqual(sample.description, sample_desc)
self.assertEqual(sample.experiment, self.experiment)
from tardis.tardis_portal.models import Dataset
dataset_desc = "My Description for Dataset created in test_datasetwrapper()"
dataset = Dataset(description=dataset_desc, experiment=self.experiment)
dataset.save()
sample_from_db = Sample.objects.get(description=sample_desc)
dataset_from_db = Dataset.objects.get(description=dataset_desc)
datasetwrapper = DatasetWrapper(sample=sample_from_db, dataset=dataset_from_db)
datasetwrapper.save()
self.assertEqual(datasetwrapper.sample, sample_from_db)
self.assertEqual(datasetwrapper.dataset, dataset_from_db)
datasetwrapper_from_db = DatasetWrapper.objects.get(sample__description=sample_desc)
self.assertEqual(datasetwrapper_from_db.dataset.pk, dataset_from_db.pk)
示例3: setUp
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset 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')
]
示例4: _create_test_dataset
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
def _create_test_dataset(nosDatafiles):
ds_ = Dataset(description='happy snaps of plumage')
ds_.save()
for i in range (0, nosDatafiles) :
df_ = Dataset_File(dataset=ds_, url='http://planet-python.org/' + str(_next_id()))
df_.save()
ds_.save()
return ds_
示例5: _make_dataset
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
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()
示例6: _create_test_dataset
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
def _create_test_dataset(nosDatafiles):
ds_ = Dataset(description='happy snaps of plumage')
ds_.save()
for i in range(0, nosDatafiles):
df_ = DataFile(dataset=ds_, filename='file_%d' % i, size='21',
sha512sum='bogus')
df_.save()
ds_.save()
return ds_
示例7: setUp
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
def setUp(self):
raise SkipTest # temporarily disabling this feature, needs coding
from tempfile import mkdtemp, mktemp
from django.conf import settings
import os
# Disconnect post_save signal
from django.db.models.signals import post_save
from tardis.tardis_portal.models import Experiment, \
staging_hook, Dataset, DataFile, DataFileObject, StorageBox
post_save.disconnect(staging_hook, sender=DataFileObject)
from django.contrib.auth.models import User
user = 'tardis_user1'
pwd = 'secret'
email = ''
self.user = User.objects.create_user(user, email, pwd)
try:
os.makedirs(settings.GET_FULL_STAGING_PATH_TEST)
except OSError:
pass
self.temp = mkdtemp(dir=settings.GET_FULL_STAGING_PATH_TEST)
self.filepath = mktemp(dir=self.temp)
content = 'test file'
with open(self.filepath, "w+b") as f:
f.write(content)
# make datafile
exp = Experiment(title='test exp1',
institution_name='monash',
created_by=self.user)
exp.save()
# make dataset
dataset = Dataset(description="dataset description...")
dataset.save()
dataset.experiments.add(exp)
dataset.save()
# create datafile
df = DataFile(dataset=dataset, size=len(content),
filename=path.basename(self.file),
md5sum='f20d9f2072bbeb6691c0f9c5099b01f3')
df.save()
# create replica
base_url = settings.GET_FULL_STAGING_PATH_TEST
s_box = StorageBox.get_default_storage(location=base_url)
dfo = DataFileObject(datafile=df,
uri=self.filepath,
storage_box=s_box)
dfo.save()
self.dfo = dfo
示例8: generate_dataset
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
def generate_dataset(datafiles=[], experiments=[]):
from tardis.tardis_portal.models import Dataset
dataset = Dataset()
dataset.save()
for df in datafiles:
df.dataset_id = dataset.id
df.save()
for exp in experiments:
dataset.experiments.add(exp)
dataset.save()
return dataset
示例9: setUp
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset 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)
# 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()
dataset = Dataset(description='dataset description...')
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
base_path = path.join(path.dirname(__file__), 'fixtures')
s_box = StorageBox.get_default_storage(location=base_path)
def create_datafile(index):
testfile = path.join(base_path, 'middleware_test%d.txt' % index)
size, sha512sum = get_size_and_sha512sum(testfile)
datafile = DataFile(dataset=dataset,
filename=path.basename(testfile),
size=size,
sha512sum=sha512sum)
datafile.save()
dfo = DataFileObject(
datafile=datafile,
storage_box=s_box,
uri=path.basename(testfile))
dfo.save()
if index != 1:
dfo.verified = False
dfo.save(update_fields=['verified'])
return DataFile.objects.get(pk=datafile.pk)
self.dataset = dataset
self.datafiles = [create_datafile(i) for i in (1, 2)]
示例10: _create_test_dataset
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
def _create_test_dataset(nosDatafiles):
ds_ = Dataset(description='happy snaps of plumage')
ds_.save()
for i in range (0, nosDatafiles) :
df_ = Dataset_File(dataset=ds_, size='21', sha512sum='bogus')
df_.save()
rep_ = Replica(datafile=df_,
url='http://planet-python.org/' + str(_next_id()),
location=Location.get_default_location())
rep_.save()
ds_.save()
return ds_
示例11: test_urls_with_some_content
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
def test_urls_with_some_content(self):
# Things that might tend to be in a real live system
user = 'testuser'
pwd = User.objects.make_random_password()
user = User.objects.create(username=user,
email='[email protected]',
first_name="Test", last_name="User")
user.set_password(pwd)
user.save()
experiment = Experiment.objects.create(
title="Test Experiment",
created_by=user,
public_access=Experiment.PUBLIC_ACCESS_FULL)
experiment.save()
acl = ObjectACL(pluginId=django_user,
entityId=str(user.id),
content_object=experiment,
canRead=True,
canWrite=True,
canDelete=True,
isOwner=True)
acl.save()
dataset = Dataset(description="test dataset")
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
# Test everything works
c = Client()
c.login(username=user, password=pwd)
urls = ['/about/', '/stats/']
urls += ['/experiment/list/%s' % part
for part in ('mine', 'shared', 'public')]
# urls += ['/experiment/%s/' % part
# for part in ('search',)]
urls += ['/experiment/view/%d/' % experiment.id]
urls += ['/ajax/experiment/%d/%s' % (experiment.id, tabpane)
for tabpane in ('description', 'datasets', 'rights')]
urls += ['/ajax/datafile_list/%d/' % dataset.id]
urls += ['/ajax/dataset_metadata/%d/' % dataset.id]
for u in urls:
response = c.get(u)
ensure(response.status_code, 200,
"%s should have returned 200 but returned %d"
% (u, response.status_code))
redirect_urls = ['/experiment/list', '/experiment/view/']
for u in redirect_urls:
response = c.get(u)
expect(response.status_code).to_equal(302)
示例12: _create_dataset
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
def _create_dataset(self):
user = User.objects.create_user('testuser', '[email protected]', 'pwd')
user.save()
full_access = Experiment.PUBLIC_ACCESS_FULL
experiment = Experiment.objects.create(title="Background Test",
created_by=user,
public_access=full_access)
experiment.save()
dataset = Dataset()
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
return dataset
示例13: setUp
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset 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()
# 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)]
示例14: test_contextual_view
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
def test_contextual_view(self):
"""
Given schema on dataset, check that image file created
"""
user = _create_test_user()
license = _create_license()
exp = _create_test_experiment(user, license)
ds = Dataset(description='happy snaps of plumage')
ds.save()
ds = _create_test_dataset(ds, exp.id, {
"output.dat": 'test data\n',
"grexp.dat": '1 2\n2 3\n3 7\n',
"grfinal21.dat": '1 2\n 2 4\n4 9\n'})
sch = Schema(namespace=self.HRMCSCHEMA,
name="hrmc_views", type=Schema.DATASET)
sch.save()
param = ParameterName(schema=sch, name="plot",
full_name="scatterplot", units="image",
data_type=ParameterName.FILENAME
)
param.save()
dps = DatasetParameterSet(schema=sch, dataset=ds)
dps.save()
ds.experiments.add(exp)
ds.save()
client = Client()
response = client.get('/dataset/%s' % ds.id)
self.assertEqual(response.status_code, 200)
param_sets = get_param_sets(ds)
self.assertTrue(param_sets)
dp = DatasetParameter.objects.get(parameterset=param_sets[0],
name=param)
self.assertTrue(dp)
self.assertNotEquals(dp.string_value, "") # ie, it has a filename
示例15: _create_datafile
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import save [as 别名]
def _create_datafile():
user = User.objects.create_user("testuser", "[email protected]", "pwd")
user.save()
UserProfile(user=user).save()
Location.force_initialize()
full_access = Experiment.PUBLIC_ACCESS_FULL
experiment = Experiment.objects.create(title="IIIF Test", created_by=user, public_access=full_access)
experiment.save()
ObjectACL(
content_object=experiment,
pluginId="django_user",
entityId=str(user.id),
isOwner=True,
canRead=True,
canWrite=True,
canDelete=True,
aclOwnershipType=ObjectACL.OWNER_OWNED,
).save()
dataset = Dataset()
dataset.save()
dataset.experiments.add(experiment)
dataset.save()
# Create new Datafile
tempfile = TemporaryUploadedFile("iiif_stored_file", None, None, None)
with Image(filename="magick:rose") as img:
img.format = "tiff"
img.save(file=tempfile.file)
tempfile.file.flush()
datafile = Dataset_File(dataset=dataset, size=os.path.getsize(tempfile.file.name), filename="iiif_named_file")
replica = Replica(
datafile=datafile,
url=write_uploaded_file_to_dataset(dataset, tempfile),
location=Location.get_default_location(),
)
replica.verify(allowEmptyChecksums=True)
datafile.save()
replica.datafile = datafile
replica.save()
return datafile