本文整理汇总了Python中tardis.tardis_portal.models.Dataset类的典型用法代码示例。如果您正苦于以下问题:Python Dataset类的具体用法?Python Dataset怎么用?Python Dataset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dataset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MRtaskTestCase
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
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
def setUp(self):
# create a test user
self.user = User.objects.create_user(username='DownloadTestUser',
email='',
password='secret')
# create a public experiment
self.experiment1 = Experiment(
title='Experiment 1',
created_by=self.user,
public_access=Experiment.PUBLIC_ACCESS_FULL)
self.experiment1.save()
# create a non-public experiment
self.experiment2 = Experiment(
title='Experiment 2',
created_by=self.user,
public_access=Experiment.PUBLIC_ACCESS_NONE)
self.experiment2.save()
# dataset1 belongs to experiment1
self.dataset1 = Dataset()
self.dataset1.save()
self.dataset1.experiments.add(self.experiment1)
self.dataset1.save()
# dataset2 belongs to experiment2
self.dataset2 = Dataset()
self.dataset2.save()
self.dataset2.experiments.add(self.experiment2)
self.dataset2.save()
# absolute path first
filename1 = 'testfile.txt'
filename2 = 'testfile.tiff'
self.dest1 = abspath(join(settings.FILE_STORE_PATH, '%s/%s/'
% (self.experiment1.id,
self.dataset1.id)))
self.dest2 = abspath(join(settings.FILE_STORE_PATH,
'%s/%s/'
% (self.experiment2.id,
self.dataset2.id)))
if not exists(self.dest1):
makedirs(self.dest1)
if not exists(self.dest2):
makedirs(self.dest2)
testfile1 = abspath(join(self.dest1, filename1))
f = open(testfile1, 'w')
f.write("Hello World!\n")
f.close()
testfile2 = abspath(join(self.dest2, filename2))
_generate_test_image(testfile2)
self.datafile1 = self._build_datafile(testfile1, filename1,
self.dataset1)
self.datafile2 = self._build_datafile(testfile2, filename2,
self.dataset2)
示例4: 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 = 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')
]
示例5: _make_dataset
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
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_
示例7: setUp
def setUp(self):
# create a test user
self.user = User.objects.create_user(username='DownloadTestUser',
email='',
password='secret')
# create a public experiment
self.experiment1 = Experiment(title='Experiment 1',
created_by=self.user,
public=True)
self.experiment1.save()
# create a non-public experiment
self.experiment2 = Experiment(title='Experiment 2',
created_by=self.user,
public=False)
self.experiment2.save()
# dataset1 belongs to experiment1
self.dataset1 = Dataset(experiment=self.experiment1)
self.dataset1.save()
# dataset2 belongs to experiment2
self.dataset2 = Dataset(experiment=self.experiment2)
self.dataset2.save()
# absolute path first
filename = 'testfile.txt'
self.dest1 = abspath(join(settings.FILE_STORE_PATH, '%s'
% self.experiment1.id))
self.dest2 = abspath(join(settings.FILE_STORE_PATH, '%s'
% self.experiment2.id))
if not exists(self.dest1):
mkdir(self.dest1)
if not exists(self.dest2):
mkdir(self.dest2)
testfile1 = abspath(join(self.dest1, filename))
f = open(testfile1, 'w')
f.write("Hello World!\n")
f.close()
testfile2 = abspath(join(self.dest2, filename))
f = open(testfile2, 'w')
f.write("Hello World!\n")
f.close()
self.dataset_file1 = Dataset_File(dataset=self.dataset1,
filename=filename,
protocol='tardis',
url='tardis://%s' % filename)
self.dataset_file1.save()
self.dataset_file2 = Dataset_File(dataset=self.dataset2,
filename=basename(filename),
protocol='tardis',
url='tardis://%s' % filename)
self.dataset_file2.save()
示例8: _create_test_dataset
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_
示例9: setUp
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
示例10: generate_dataset
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
示例11: 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)
# 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)]
示例12: _create_test_dataset
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_
示例13: test_urls_with_some_content
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)
示例14: _create_dataset
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
示例15: __init__
def __init__(self, dataset=None, dataset_id=None,
description="", experiment_id=None):
"""
instantiate new task or existing task
:param dataset: optional parameter to instanciate task from
metadata, will be tested for completeness and copied into
new task if complete
:type dataset: Dataset
"""
if dataset:
self.dataset = dataset
elif dataset_id:
self.dataset = Dataset.objects.get(pk=dataset_id)
else:
if description == "":
raise TypeError("No description given")
if not experiment_id:
raise TypeError("No experiment id given")
self.dataset = Dataset()
self.dataset.experiment_id = experiment_id
self.dataset.description = description
self.dataset.save()
try:
thisparameterset = DatasetParameterSet.objects.get(
schema=self.get_schema(),
dataset=self.dataset)
except ObjectDoesNotExist:
thisparameterset = DatasetParameterSet(
schema=self.get_schema(),
dataset=self.dataset)
thisparameterset.save()
super(Task, self).__init__(parameterset=thisparameterset)