Exemplo n.º 1
0
 def test_project(self):     
     from mecat.models import Project
     desc = "My Description for Project created in test_project()"
     project = Project(experiment=self.experiment)
     forcode1 = "0001"
     forcode2 = "0002"
     forcode3 = "0003 - three"
     funded_by = "NHMRC"
     funding_code = "1001011"
     notes = "A note that is not that long"
     project.forcode1 = forcode1
     project.forcode2 = forcode2
     project.forcode3 = forcode3
     project.funded_by = funded_by
     project.funding_code = funding_code
     project.notes = notes
     project.save()
     self.assertEqual(project.experiment, self.experiment)
     self.assertEqual(project.forcode1, forcode1)
     self.assertEqual(project.forcode2, forcode2)
     self.assertEqual(project.forcode3, forcode3)
     self.assertEqual(project.notes, notes)
     self.assertEqual(project.funded_by, funded_by)
     self.assertEquals(project.funding_code, funding_code)
     
     project_from_db = Project.objects.get(experiment__description=self.desc)
     self.assertEqual(project_from_db.experiment, self.experiment)
Exemplo n.º 2
0
 def add_experiment(self, cleaned_data):
     logger.debug('adding experiment')
     logger.debug(cleaned_data)
     
     experiment_forcode1 = cleaned_data['forcode_1']
     experiment_forcode2 = cleaned_data['forcode_2']
     experiment_forcode3 = cleaned_data['forcode_3']
     experiment_funded_by = cleaned_data['funded_by']
     experiment_funding_code = cleaned_data['funding_code']
     experiment_notes = cleaned_data['notes']
     
     new_exp_wrapper= Project(experiment_id=self.experiment_id,
                         forcode1=experiment_forcode1,
                         forcode2=experiment_forcode2,
                         forcode3=experiment_forcode3,
                         funded_by=experiment_funded_by,
                         funding_code=experiment_funding_code,
                         notes=experiment_notes)
     new_exp_wrapper.save()
Exemplo n.º 3
0
 def setUp(self):
     Schema.objects.get_or_create(namespace="http://www.tardis.edu.au/schemas/related_info/2011/11/10", name='Related Info')
     self.user = User.objects.create_user(username='******',
                                          email='*****@*****.**',
                                          password='******')
     self.e1 = Experiment(title="Experiment 1", created_by=self.user, public=False)
     self.e1.save()
     self.p1 = Project(experiment=self.e1, forcode1="1234 qwe", forcode2="5678 234", funded_by="me", funding_code="0000")
     self.p1.save()
     self.provider = DC2CRifCsProvider()
     self.publish_data = { 
                 self.custom_authors_key: "",
                 self.custom_description_key: "",
                 self.access_type_key: "public"
                }       
Exemplo n.º 4
0
class DC2CRifCsProviderTestCase(TestCase):
    
    custom_description_key = 'custom_description'
    custom_authors_key = 'custom_authors'
    access_type_key = 'access_type'
    random_custom_description = 'a custom description'
    
    def setUp(self):
        Schema.objects.get_or_create(namespace="http://www.tardis.edu.au/schemas/related_info/2011/11/10", name='Related Info')
        self.user = User.objects.create_user(username='******',
                                             email='*****@*****.**',
                                             password='******')
        self.e1 = Experiment(title="Experiment 1", created_by=self.user, public=False)
        self.e1.save()
        self.p1 = Project(experiment=self.e1, forcode1="1234 qwe", forcode2="5678 234", funded_by="me", funding_code="0000")
        self.p1.save()
        self.provider = DC2CRifCsProvider()
        self.publish_data = { 
                    self.custom_authors_key: "",
                    self.custom_description_key: "",
                    self.access_type_key: "public"
                   }       
 
 
    def testInitialisation(self):
        self.assertIsNotNone(self.provider)
        

    def testCanPublishNoProject(self):
        self.e1.public = True
        self.e1.save()
        ph = PublishHandler(self.e1.id, create=True)
        ph.update(self.publish_data)
        self.assertTrue(self.provider.can_publish(self.e1))    
        self.p1.delete()
        self.assertFalse(self.provider.can_publish(self.e1))    

    def testCanPublishNotPublicAndUnpublished(self):
        # (experiment.public : False, access type : Unpublished) -> FALSE
        self.assertFalse(self.provider.can_publish(self.e1))    


    def testCanPublishNotPublicAndMediated(self):     
        # (experiment public: False, access type: mediated) -> True
        self.publish_data[self.access_type_key] = "mediated"
        ph = PublishHandler(self.e1.id, create=True)
        ph.update(self.publish_data)
        self.assertTrue(self.provider.can_publish(self.e1))      

    def testCanPublishNotPublicAndPrivate(self):  
        # (experiment public: False, access type: private) -> True
        self.publish_data[self.access_type_key] = "private"
        ph = PublishHandler(self.e1.id, create=True)
        ph.update(self.publish_data)
        self.assertFalse(self.provider.can_publish(self.e1))            
     
            
    def testCanPublishPublicAndMediated(self):    
        # (experiment public: True, access type: mediated) -> True
        self.e1.public = True
        self.e1.save()
        self.publish_data[self.access_type_key] = "mediated"
        ph = PublishHandler(self.e1.id, create=True)
        ph.update(self.publish_data)
        self.assertTrue(self.provider.can_publish(self.e1))
                
    def testCanPublishNotPublicAndUnpublished(self):
        # (experiment.public : False, access type : Unpublished) -> FALSE
        self.assertFalse(self.provider.can_publish(self.e1))
        
    def testCanPublishNotPublicAndPrivate(self):  
        # (experiment public: False, access type: private) -> True
        self.publish_data[self.access_type_key] = "private"
        ph = PublishHandler(self.e1.id, create=True)
        ph.update(self.publish_data)      
        self.assertFalse(self.provider.can_publish(self.e1))      
          
    def testCanPublishPublicAndPublished(self):
        # (experiment public: True, access type: published) -> True
        self.e1.public = True
        ph = PublishHandler(self.e1.id, create=True)
        ph.update(self.publish_data)
        self.assertTrue(self.provider.can_publish(self.e1))
        
    def testCanPublishPublicAndPrivate(self):
        # (experiment public: True, access type: private) -> True
        self.e1.public = True
        self.publish_data[self.access_type_key] = "private"
        ph = PublishHandler(self.e1.id, create=True)
        ph.update(self.publish_data)
        self.assertTrue(self.provider.can_publish(self.e1))    
        
    def testCanPublishPublicAndUnpublished(self):
        # (experiment public: True, access type: unpublished) -> False
        self.e1.public = True
        self.publish_data[self.access_type_key] = "unpublished"
        ph = PublishHandler(self.e1.id, create=True)
        ph.update(self.publish_data)
        self.assertTrue(self.provider.can_publish(self.e1))       
Exemplo n.º 5
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