Exemplo n.º 1
0
 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)
     
     
     
Exemplo n.º 2
0
 def test_sample(self):
     from mecat.models import Sample
     desc = "My Description for Sample created in test_sample()"
     sample = Sample(experiment=self.experiment, description=desc)
     name = "Sample 1"
     forcode1 = "0001"
     forcode2 = "0002"
     forcode3 = "0003 - three"
     notes = "A note that is not that long"
     sample.name = name
     sample.forcode1 = forcode1
     sample.forcode2 = forcode2
     sample.forcode3 = forcode3
     sample.notes = notes
     sample.save()
     self.assertEqual(sample.description, desc)
     self.assertEqual(sample.experiment, self.experiment)
     self.assertEqual(sample.name, name)
     self.assertEqual(sample.forcode1, forcode1)
     self.assertEqual(sample.forcode2, forcode2)
     self.assertEqual(sample.forcode3, forcode3)
     self.assertEqual(sample.notes, notes)
     
     sample_from_db = Sample.objects.get(description=desc)
     self.assertEqual(sample_from_db.experiment, self.experiment)
Exemplo n.º 3
0
 def add_sample(self, cleaned_data):
     logger.debug('adding sample')
     logger.debug(cleaned_data)
     
     sample_name = cleaned_data['name']
     sample_description = cleaned_data['description']
     sample_forcode1 = cleaned_data['forcode_1']
     sample_forcode2 = cleaned_data['forcode_2']
     sample_forcode3 = cleaned_data['forcode_3']
     sample_notes = cleaned_data['notes']
     
     new_sample = Sample(experiment_id=self.experiment_id,
                         name=sample_name,
                         description=sample_description,
                         forcode1=sample_forcode1,
                         forcode2=sample_forcode2,
                         forcode3=sample_forcode3,
                         notes=sample_notes)
     new_sample.save()
Exemplo n.º 4
0
    def test_existing_datasetwrappers(self):
        s1 = Sample(name="s1", description="s1 description", experiment=self._create_experiment())
        s2 = Sample(name="s2", description="s2 description", experiment=self._create_experiment())
        s1.save()
        s2.save()

        d1 = DatasetWrapper(name="dw1", description="dw1 description", sample=s1)
        d2 = DatasetWrapper(name="dw2", description="dw2 description", sample=s1)
        d3 = DatasetWrapper(name="dw1", description="dw1 description", sample=s2)
        d4 = DatasetWrapper(name="dw2", description="dw2 description", sample=s1)
        d5 = DatasetWrapper(name="", description="", sample=s1)
        d1.save()
        d2.save()
        from mecat.forms import existing

        self.assertTrue(existing(d1))
        self.assertTrue(existing(d2))
        self.assertFalse(existing(d3))
        self.assertTrue(existing(d4))  # d4 is identical to d2 so it's considered existing
        self.assertFalse(existing(d5))
        d5.save()
        self.assertTrue(existing(d5))
Exemplo n.º 5
0
 def _create_samples(self, exp):
     sample_desc = {"s1 name": "s1 desc", "s2 name": "s2 desc"}
     for name, desc in sample_desc.items():
         sample = Sample(name=name, description=desc, experiment=exp)
         sample.save()
Exemplo n.º 6
0
def _registerExperimentDocument(filename, created_by, expid=None,
                                owners=[], username=None):
    '''
    Register the experiment document and return the experiment id.

    :param filename: path of the document to parse (METS or notMETS)
    :type filename: string
    :param created_by: a User instance
    :type created_by: :py:class:`django.contrib.auth.models.User`
    :param expid: the experiment ID to use
    :type expid: int
    :param owners: a list of owners
    :type owner: list
    :param username: **UNUSED**
    :rtype: int

    '''

    f = open(filename)
    firstline = f.readline()
    f.close()

    if firstline.startswith('<experiment'):
        logger.debug('processing simple xml')
        processExperiment = ProcessExperiment()
        eid = processExperiment.process_simple(filename, created_by, expid)

    else:
        logger.debug('processing METS')
        eid = parseMets(filename, created_by, expid)
 
    # Create a DatasetWrapper for each Dataset
    experiment = Experiment.objects.get(pk=eid)
    sample = Sample(experiment=experiment, name="Default Sample", 
                    description="A default sample for %s" % experiment.title)
    sample.save()
    _create_wrappers_for_datasets(sample, experiment)  
    
    # Create a Project to wraps the experiment, then create a Sample that
    # points to the experiment  
    project = Project(experiment=experiment)
    project.save()
    
    auth_key = ''
    try:
        auth_key = settings.DEFAULT_AUTH
    except AttributeError:
        logger.error('no default authentication for experiment ownership set (settings.DEFAULT_AUTH)')

    force_user_create = False
    try:
        force_user_create = settings.DEFAULT_AUTH_FORCE_USER_CREATE
    except AttributeError:
        pass

    if auth_key:
        for owner in owners:
            logger.debug('** Owner : %s' %owner)
            # for each PI
            if not owner:
                continue

            owner_username = None
            if '@' in owner:
                logger.debug('** Email as username **')
                owner_username = auth_service.getUsernameByEmail(auth_key,
                                    owner)
            if not owner_username:
                logger.debug('** No existing user!! **')
                owner_username = owner

            owner_user = auth_service.getUser(auth_key, owner_username,
                      force_user_create=force_user_create)
            if owner_user:
                # if exist, create ACL
                logger.debug('registering owner: ' + owner)
                e = Experiment.objects.get(pk=eid)

                acl = ExperimentACL(experiment=e,
                                    pluginId=django_user,
                                    entityId=str(owner_user.id),
                                    canRead=True,
                                    canWrite=True,
                                    canDelete=True,
                                    isOwner=True,
                                    aclOwnershipType=ExperimentACL.OWNER_OWNED)
                acl.save()
                # Also update email
                if '@' in owner:
                    owner_user.email = owner
                    owner_user.save()

    return eid