当前位置: 首页>>代码示例>>Python>>正文


Python models.Experiment类代码示例

本文整理汇总了Python中tardis.tardis_portal.models.Experiment的典型用法代码示例。如果您正苦于以下问题:Python Experiment类的具体用法?Python Experiment怎么用?Python Experiment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Experiment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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)
        # 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)
开发者ID:grischa,项目名称:mytardis,代码行数:34,代码来源:test_views.py

示例2: 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)

        # 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)
开发者ID:grischa,项目名称:mytardis,代码行数:35,代码来源:test_views.py

示例3: _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)
开发者ID:conkiztador,项目名称:mytardis,代码行数:30,代码来源:test_oai.py

示例4: IntegrityCheckTestCase

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)
开发者ID:conkiztador,项目名称:mytardis,代码行数:60,代码来源:test_integrity.py

示例5: setUp

    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'
            ])
开发者ID:JMSS-IT-11-2012,项目名称:mytardis,代码行数:32,代码来源:test_integrity.py

示例6: setUp

 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()
开发者ID:mytardis,项目名称:mytardis,代码行数:33,代码来源:test_migration.py

示例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_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)
开发者ID:jasonrig,项目名称:mytardis,代码行数:60,代码来源:test_download.py

示例8: _create_test_experiment

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
开发者ID:IntersectAustralia,项目名称:mytardis,代码行数:25,代码来源:test_rmexperiment.py

示例9: 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)
开发者ID:aaryani,项目名称:aa-migration-test1,代码行数:33,代码来源:tests.py

示例10: _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 = 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
开发者ID:UQ-CMM-Mirage,项目名称:mytardis-app-atom,代码行数:29,代码来源:atom_ingest.py

示例11: _create_test_data

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
开发者ID:mytardis,项目名称:mytardis,代码行数:33,代码来源:test_oai.py

示例12: 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')
                         ] 
开发者ID:UQ-CMM-Mirage,项目名称:mytardis-app-datagrabber,代码行数:59,代码来源:test_datagrabber.py

示例13: 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
开发者ID:aaryani,项目名称:CoreTardis,代码行数:59,代码来源:views.py

示例14: TarDownloadTestCase

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))
开发者ID:jasonrig,项目名称:mytardis,代码行数:58,代码来源:test_tar_download.py

示例15: _create_test_data

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)
开发者ID:ianedwardthomas,项目名称:mytardis-app-repos-consumer,代码行数:58,代码来源:test_ingest.py


注:本文中的tardis.tardis_portal.models.Experiment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。