本文整理汇总了Python中tardis.tardis_portal.models.Dataset.get_first_experiment方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.get_first_experiment方法的具体用法?Python Dataset.get_first_experiment怎么用?Python Dataset.get_first_experiment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tardis.tardis_portal.models.Dataset
的用法示例。
在下文中一共展示了Dataset.get_first_experiment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UploadTestCase
# 需要导入模块: from tardis.tardis_portal.models import Dataset [as 别名]
# 或者: from tardis.tardis_portal.models.Dataset import get_first_experiment [as 别名]
class UploadTestCase(TestCase):
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).save()
self.test_dir = mkdtemp()
Location.force_initialize()
self.exp = Experiment(title='test exp1',
institution_name='monash', created_by=self.user)
self.exp.save()
acl = ObjectACL(
pluginId=django_user,
entityId=str(self.user.id),
content_object=self.exp,
canRead=True,
isOwner=True,
aclOwnershipType=ObjectACL.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')
def tearDown(self):
from shutil import rmtree
self.f1.close()
rmtree(self.test_dir)
rmtree(self.dataset_path)
rmtree(self.experiment_path)
self.exp.delete()
def testFileUpload(self):
from os import path
c = Client()
c.login(username='tardis_user1', password='secret')
session_id = c.session.session_key
response = c.post('/upload/' + str(self.dataset.id) + '/',
{'Filedata': self.f1, 'session_id': session_id})
test_files_db = \
Dataset_File.objects.filter(dataset__id=self.dataset.id)
self.assertTrue(path.exists(path.join(self.dataset_path,
self.filename)))
self.assertTrue(self.dataset.id == 1)
url = test_files_db[0].get_preferred_replica().url
self.assertTrue(url == '%d/%d/testfile.txt' %
(self.dataset.get_first_experiment().id,
self.dataset.id))
self.assertTrue(test_files_db[0].get_preferred_replica().verified)
def testUploadComplete(self):
from django.http import QueryDict, HttpRequest
from tardis.tardis_portal.views import upload_complete
data = [('filesUploaded', '1'), ('speed', 'really fast!'),
('allBytesLoaded', '2'), ('errorCount', '0')]
post = QueryDict('&'.join(['%s=%s' % (k, v) for (k, v) in
data]))
request = HttpRequest()
#.........这里部分代码省略.........