Ejemplo n.º 1
0
    def setUp(self):

        self.user = User(username='******',
                         password='******',
                         email='*****@*****.**')
        self.user.save()
        self.exp = Experiment(approved=True,
                              title='title1',
                              institution_name='institution1',
                              description='description1',
                              created_by=self.user,
                              public_access=Experiment.PUBLIC_ACCESS_FULL)
        self.uid = 0
        self.url = 'http://remotetardis:8080'

        self.mock_ts = flexmock()
        flexmock(TransferClient).new_instances(self.mock_ts)

        self.mock_integrity = flexmock()
        flexmock(IntegrityCheck).new_instances(self.mock_integrity)

        self.status = {
            'human_status': 'this is a readable status',
            'message': 'this is a message'
        }
Ejemplo n.º 2
0
    def setUp(self):
        # create a test user
        self.user = User.objects.create_user(username='******',
                                             email='',
                                             password='******')

        # 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/%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, 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()
Ejemplo n.º 3
0
    def setUp(self):
        # Create test owner without enough details
        username, email, password = ("testuser", "*****@*****.**", "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)
Ejemplo n.º 4
0
    def setUp(self):
        self.user = User(username='******',
                         password='******',
                         email='*****@*****.**')
        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'])
Ejemplo n.º 5
0
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 = '******'
        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)
Ejemplo n.º 6
0
    def testRightsRequireValidOwner(self):
        # Create test owner without enough details
        username, email, password = ("testuser", "*****@*****.**", "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)
Ejemplo n.º 7
0
    def setUp(self):
        # create a test user
        self.user = User.objects.create_user(username='******',
                                             email='',
                                             password='******')

        # 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)
Ejemplo n.º 8
0
    def setUp(self):
        """
        setting up essential objects, copied from tests above
        """

        user = '******'
        pwd = 'secret'
        email = ''
        self.user = User.objects.create_user(user, email, pwd)
        self.userProfile = self.user.userprofile
        self.exp = Experiment(title='test exp1',
                              institution_name='monash',
                              created_by=self.user)
        self.exp.save()
        self.acl = ObjectACL(
            pluginId=django_user,
            entityId=str(self.user.id),
            content_object=self.exp,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ObjectACL.OWNER_OWNED,
        )
        self.acl.save()
        self.dataset = Dataset(description='dataset description...')
        self.dataset.save()
        self.dataset.experiments.add(self.exp)
        self.dataset.save()

        self.datafile = DataFile(dataset=self.dataset,
                                 size=42,
                                 filename="foo",
                                 md5sum="junk")
        self.datafile.save()
Ejemplo n.º 9
0
 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 = ExperimentACL(experiment=experiment,
                             pluginId=django_user,
                             entityId=user.id,
                             canRead=True,
                             canWrite=True,
                             canDelete=True,
                             isOwner=True,
                             aclOwnershipType=ExperimentACL.OWNER_OWNED)
         acl.save()
         return experiment
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
def _create_experiment(user, bad):
    experiment = Experiment(title='Norwegian Blue',
                            description='Parrot + 40kV',
                            created_by=user)
    experiment.public_access = Experiment.PUBLIC_ACCESS_METADATA
    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")
    psm = ParameterSetManager(parentObject=experiment, schema=SCHEMA_URI)
    if bad:
        params = {
            'type': 'website',
            'identifier': 'https://www.badexample.com/'
        }
    else:
        params = {
            'type': 'website',
            'identifier': 'https://www.example.com/',
            'title': 'Google',
            'notes': 'This is a note.'
        }
    for k, v in params.items():
        psm.set_param(k, v)
    return experiment
Ejemplo n.º 12
0
def _create_test_data():
    user = User(username='******',
                first_name='Thomas',
                last_name='Atkins',
                email='*****@*****.**')
    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
Ejemplo n.º 13
0
def _create_test_data():
    user = User(username='******',
                first_name='Thomas',
                last_name='Atkins',
                email='*****@*****.**')
    user.save()
    user2 = User(username='******', email='*****@*****.**')
    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)
Ejemplo n.º 14
0
    def setUp(self):
        # create user
        self.testuser = User(username='******')
        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()
Ejemplo n.º 15
0
 def setUp(self):
     self.client = Client()
     # old_user
     user_old_username = '******'
     # new_user
     user_new_username = '******'
     pwd = 'secret'
     email = '*****@*****.**'
     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()
Ejemplo n.º 16
0
    def setUp(self):
        self.user = User(username='******', password='******', email='*****@*****.**')
        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'
            ])
Ejemplo n.º 17
0
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='******', password='******', email='*****@*****.**')
        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)
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
Ejemplo n.º 19
0
 def setUp(self):
     self.client = Client()
     # old_user
     user_old_username = '******'
     # new_user
     user_new_username = '******'
     pwd = 'secret'
     email = '*****@*****.**'
     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()
Ejemplo n.º 20
0
    def setUp(self):
        from os import path, mkdir
        from tempfile import mkdtemp

        user = '******'
        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 setUp(self):
        # Create test owner without enough details
        username, email, password = ('testuser',
                                     '*****@*****.**',
                                     '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')
                         ] 
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
    def setUp(self):
        # Create test owner without enough details
        username, email, password = ('testuser', '*****@*****.**',
                                     '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,
            isOwner=True,
            aclOwnershipType=ObjectACL.OWNER_OWNED,
        )
        acl.save()

        dataset = Dataset(description='dataset description...')
        dataset.save()
        dataset.experiments.add(experiment)
        dataset.save()

        def create_datafile(index):
            testfile = path.join(path.dirname(__file__), 'fixtures',
                                 'jeol_sem_test%d.txt' % index)

            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-jeol',
                '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(i) for i in (1, 2)]
Ejemplo n.º 24
0
    def setUp(self):
        # create a test user
        self.user = User.objects.create_user(username='******',
                                             email='',
                                             password='******')

        # 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(description='dangerous;name')
        self.dataset1.save()
        self.dataset1.experiments.add(self.experiment1)
        self.dataset1.save()

        # dataset2 belongs to experiment2
        self.dataset2 = Dataset(description='terrible\nname')
        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)
Ejemplo n.º 25
0
class IntegrityCheckTestCase(TestCase):
    def _make_dataset(self, exp, filenames):
        dataset = Dataset()
        dataset.save()
        dataset.experiments.add(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='******',
                         password='******',
                         email='*****@*****.**')
        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)
def _create_test_data():
    """
    Create Single experiment with two owners
    """
    user1 = User(username='******',
                first_name='Thomas',
                last_name='Atkins',
                email='*****@*****.**')
    user1.save()
    UserProfile(user=user1).save()

    user2 = User(username='******',
                first_name='Joe',
                last_name='Bloggs',
                email='*****@*****.**')
    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)
Ejemplo n.º 27
0
class TarDownloadTestCase(TestCase):
    def setUp(self):
        # create user
        self.testuser = User(username="******")
        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))
Ejemplo n.º 28
0
    def setUp(self):
        # create a test user
        self.user = User.objects.create_user(username='******',
                                             email='',
                                             password='******')

        # 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()
Ejemplo n.º 29
0
 def setUp(self):
     self.user = User.objects.create_user('test', '', 'test')
     self.expt = Experiment(title='test exp1',
                             institution_name='monash',
                             created_by=self.user,
                             )
     self.schema, _ = Schema.objects.get_or_create(namespace=settings.DOI_NAMESPACE)
     self.doi_name, _ = ParameterName.objects.get_or_create(schema=self.schema, full_name='DOI', name='doi')
     self.expt.save()
Ejemplo n.º 30
0
    def setUp(self):
        """Setup test fixtures if needed."""
        self.user = User.objects.create_user("doctor", '', "pwd")

        self.exp = Experiment(title="Wonderful",
                              institution_name="Monash University",
                              created_by=self.user)
        self.exp.save()

        group = Group(name="Group1")
        group.save()

        facility = Facility(name="Test Facility", manager_group=group)
        facility.save()

        self.inst = Instrument(name="Test Instrument1", facility=facility)
        self.inst.save()

        self.dataset = Dataset(description="Dataset1", instrument=self.inst)
        self.dataset.save()

        storage_classes = getattr(settings, "HSM_STORAGE_CLASSES",
                                  DEFAULT_HSM_CLASSES)
        self.sbox1 = StorageBox(name="SBOX1",
                                django_storage_class=storage_classes[0],
                                status='online',
                                max_size=256)
        self.sbox1.save()
        sbox1_attr = StorageBoxAttribute(storage_box=self.sbox1,
                                         key='type',
                                         value=StorageBox.DISK)
        sbox1_attr.save()
        sbox1_loc_opt = StorageBoxOption(storage_box=self.sbox1,
                                         key="location",
                                         value="/dummy/path")
        sbox1_loc_opt.save()

        self.sbox2 = StorageBox(
            name="SBOX2",
            django_storage_class="any.non.disk.StorageSystem",
            status='offline',
            max_size=256)
        self.sbox2.save()
        sbox2_attr = StorageBoxAttribute(storage_box=self.sbox2,
                                         key='type',
                                         value=StorageBox.TAPE)
        sbox2_attr.save()

        self.df1 = DataFile(dataset=self.dataset, filename="test_df.jpg")
        self.df1.save()
        self.dfo1 = DataFileObject(datafile=self.df1,
                                   storage_box=self.sbox1,
                                   uri="stream/test.jpg",
                                   verified=True)
        self.dfo1.save()
        self.df1.verify()
Ejemplo n.º 31
0
    def testNeverExpire(self):
        experiment = Experiment(created_by=self.user, end_time=dt.datetime(1999,4,3))
        experiment.save()

        eh = EmbargoHandler(experiment.id, True)
        self.assertFalse(eh.never_expires())

        eh.prevent_expiry()
        self.assertTrue(eh.never_expires())
        self.assertFalse(eh.because_no_end_date())
Ejemplo n.º 32
0
    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 = '******'
        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
Ejemplo n.º 33
0
def create_draft_publication(user, publication_title, publication_description):
    # Note: Maybe this logic can be taken from the tardis_portal/views.py?

    experiment = Experiment(created_by=user,
                            title=publication_title,
                            description=publication_description)
    experiment.save()

    ObjectACL(content_object=experiment,
              pluginId=django_user,
              entityId=str(user.id),
              canRead=True,
              canWrite=False,
              canDelete=False,
              isOwner=True,
              aclOwnershipType=ObjectACL.OWNER_OWNED).save()

    ObjectACL(content_object=experiment,
              pluginId=django_group,
              entityId=str(
                  Group.objects.get_or_create(
                      name=getattr(
                          settings, 'PUBLICATION_OWNER_GROUP',
                          default_settings.PUBLICATION_OWNER_GROUP))[0].id),
              canRead=True,
              canWrite=True,
              canDelete=True,
              isOwner=True,
              aclOwnershipType=ObjectACL.OWNER_OWNED).save()

    publication_schema = Schema.objects.get(
        namespace=getattr(settings, 'PUBLICATION_SCHEMA_ROOT',
                          default_settings.PUBLICATION_SCHEMA_ROOT))

    # Attach draft schema
    draft_publication_schema = Schema.objects.get(
        namespace=getattr(settings, 'PUBLICATION_DRAFT_SCHEMA',
                          default_settings.PUBLICATION_DRAFT_SCHEMA))
    ExperimentParameterSet(schema=draft_publication_schema,
                           experiment=experiment).save()

    # Attach root schema and blank form_state parameter
    publication_root_schema = Schema.objects.get(
        namespace=getattr(settings, 'PUBLICATION_SCHEMA_ROOT',
                          default_settings.PUBLICATION_SCHEMA_ROOT))
    publication_root_parameter_set = ExperimentParameterSet(
        schema=publication_schema,
        experiment=experiment)
    publication_root_parameter_set.save()
    form_state_param_name = ParameterName.objects.get(
        schema=publication_root_schema, name='form_state')
    ExperimentParameter(name=form_state_param_name,
                        parameterset=publication_root_parameter_set).save()

    return experiment
Ejemplo n.º 34
0
def create_draft_publication(user, publication_title, publication_description):
    # Note: Maybe this logic can be taken from the tardis_portal/views.py?

    experiment = Experiment(created_by=user,
                            title=publication_title,
                            description=publication_description)
    experiment.save()

    ObjectACL(content_object=experiment,
              pluginId=django_user,
              entityId=str(user.id),
              canRead=True,
              canWrite=False,
              canDelete=False,
              isOwner=True,
              aclOwnershipType=ObjectACL.OWNER_OWNED).save()

    ObjectACL(content_object=experiment,
              pluginId=django_group,
              entityId=str(
                  Group.objects.get_or_create(
                      name=getattr(
                          settings, 'PUBLICATION_OWNER_GROUP',
                          default_settings.PUBLICATION_OWNER_GROUP))[0].id),
              canRead=True,
              canWrite=True,
              canDelete=True,
              isOwner=True,
              aclOwnershipType=ObjectACL.OWNER_OWNED).save()

    publication_schema = Schema.objects.get(
        namespace=getattr(settings, 'PUBLICATION_SCHEMA_ROOT',
                          default_settings.PUBLICATION_SCHEMA_ROOT))

    # Attach draft schema
    draft_publication_schema = Schema.objects.get(
        namespace=getattr(settings, 'PUBLICATION_DRAFT_SCHEMA',
                          default_settings.PUBLICATION_DRAFT_SCHEMA))
    ExperimentParameterSet(schema=draft_publication_schema,
                           experiment=experiment).save()

    # Attach root schema and blank form_state parameter
    publication_root_schema = Schema.objects.get(
        namespace=getattr(settings, 'PUBLICATION_SCHEMA_ROOT',
                          default_settings.PUBLICATION_SCHEMA_ROOT))
    publication_root_parameter_set = ExperimentParameterSet(
        schema=publication_schema,
        experiment=experiment)
    publication_root_parameter_set.save()
    form_state_param_name = ParameterName.objects.get(
        schema=publication_root_schema, name='form_state')
    ExperimentParameter(name=form_state_param_name,
                        parameterset=publication_root_parameter_set).save()

    return experiment
Ejemplo n.º 35
0
    def setUp(self):
        from django.contrib.auth.models import User
        from tardis.tardis_portal.models import Experiment
        user = '******'
        pwd = 'secret'
        email = ''
        self.user = User.objects.create_user(user, email, pwd)
        self.experiment = Experiment(created_by=self.user)
        self.experiment.save()

        sys.modules['datetime'].datetime = FrozenTime
Ejemplo n.º 36
0
def _create_test_data():
    user = User(username='******',
                first_name="Voltaire",
                email='*****@*****.**')
    user.save()
    UserProfile(user=user).save()
    experiment = Experiment(title='Norwegian Blue',
                            description='Parrot + 40kV',
                            created_by=user)
    experiment.public_access = Experiment.PUBLIC_ACCESS_METADATA
    experiment.save()
    return (experiment, user)
Ejemplo n.º 37
0
def _create_test_data():
    user = User(username='******',
                first_name="Voltaire",
                email='*****@*****.**')
    user.save()
    UserProfile(user=user).save()
    experiment = Experiment(title='Norwegian Blue',
                            description='Parrot + 40kV',
                            created_by=user)
    experiment.public_access = Experiment.PUBLIC_ACCESS_METADATA
    experiment.save()
    return (experiment, user)
Ejemplo n.º 38
0
    def setUp(self):
        # Create test owner without enough details
        username, email, password = ('testuser',
                                     '*****@*****.**',
                                     '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)]
Ejemplo n.º 39
0
    def setUp(self):
        # Load schemas for test
        from django.core.management import call_command
        call_command('loaddata', 'as_schemas')

        self.client = Client()
        self.experiments = []

        try:
            user = User.objects.get(username='******')
        except User.DoesNotExist:
            user = User.objects.create_user('test', '', 'test')
            user.save()

        self.userprofile = user.userprofile

        # base_path = path.abspath(path.dirname(__file__))
        experiment = Experiment(title='SAXS Test',
                                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)
        acl.save()
        self.experiments += [experiment]

        schema = Schema.objects.get(type=Schema.DATAFILE, subtype='saxs')
        parameter = ParameterName.objects.get(schema=schema, name='io')
        parameter.is_searchable = True
        parameter.save()
        self.io_param_name = parameter.getUniqueShortName()

        schema = Schema.objects.get(type=Schema.DATASET, subtype='saxs')
        parameter = ParameterName.objects.get(schema=schema, name='frqimn')
        parameter.is_searchable = True
        parameter.save()
        self.frqimn_param_name = parameter.getUniqueShortName()

        new_schema = Schema()
        new_schema.namespace = 'testschemawithduplicatename'
        new_schema.save()
        new_param = ParameterName(
            schema=new_schema,
            name='title',
            full_name='Duplicate title parametername',
            is_searchable=True)
        new_param.save()
Ejemplo n.º 40
0
 def create_experiment(i):
     experiment = Experiment(title="Text Experiment #%d" % i, 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()
     return experiment
Ejemplo n.º 41
0
    def test_create_index(self):
        self.exp1 = Experiment(title='test exp1',
                               institution_name='monash',
                               description='Test Description',
                               created_by=self.user)
        self.exp2 = Experiment(title='test exp2',
                               institution_name='monash',
                               description='Test Description',
                               created_by=self.user)
        self.exp1.save()
        self.exp2.save()
        # get search instance
        search = ExperimentDocument.search()
        # query for title(exact matching)
        query = search.query("match", title='test exp1')
        result = query.execute(ignore_cache=True)
        self.assertEqual(result.hits[0].title, 'test exp1')
        # query for description
        query = search.query("match", description='Test Description')
        result = query.execute(ignore_cache=True)
        self.assertEqual(result.hits[0].description, 'Test Description')
        # query for created_time
        query = search.query("match", created_time=self.exp1.created_time)
        result = query.execute(ignore_cache=True)
        self.assertEqual(result.hits[0].created_time, self.exp1.created_time)
        # dataset
        # dataset1 belongs to experiment1
        self.dataset1 = Dataset(description='test_dataset')
        self.dataset1.save()
        self.dataset1.experiments.add(self.exp1)
        self.dataset1.save()

        # dataset2 belongs to experiment2
        self.dataset2 = Dataset(description='test_dataset2')
        self.dataset2.save()
        self.dataset2.experiments.add(self.exp2)
        self.dataset2.save()
        # search on dataset
        search = DatasetDocument.search()
        query = search.query("match", description='test_dataset')
        result = query.execute(ignore_cache=True)
        self.assertEqual(result.hits.total.value, 1)
        # search on datafile
        settings.REQUIRE_DATAFILE_SIZES = False
        settings.REQUIRE_DATAFILE_CHECKSUMS = False
        self.datafile = DataFile(dataset=self.dataset1, filename='test.txt')
        self.datafile.save()
        search = DataFileDocument.search()
        query = search.query("match", filename='test.txt')
        result = query.execute(ignore_cache=True)
        self.assertEqual(result.hits[0].filename, self.datafile.filename)
Ejemplo n.º 42
0
class ANDSDOITestCase(TestCase):
    def setUp(self):
        self.user = User.objects.create_user("test", "", "test")
        self.expt = Experiment(title="test exp1", institution_name="monash", created_by=self.user)
        self.schema, _ = Schema.objects.get_or_create(namespace=settings.DOI_NAMESPACE)
        self.doi_name, _ = ParameterName.objects.get_or_create(schema=self.schema, full_name="DOI", name="doi")
        self.expt.save()

    def test_init(self):
        doi_service = DOIService(self.expt)

    def test_get_doi_none(self):
        doi_service = DOIService(self.expt)
        self.assertEquals(None, doi_service.get_doi())
Ejemplo n.º 43
0
    def test_authors(self):
        exp = Experiment(
            title='test exp2',
            institution_name='monash',
            created_by=self.user,
        )
        exp.save()

        ExperimentAuthor(experiment=exp, author='nigel', order=0).save()

        exp = Experiment(
            title='test exp1',
            institution_name='monash',
            created_by=self.user,
        )
        exp.save()

        ae1 = ExperimentAuthor(experiment=exp, author='steve', order=100)
        ae1.save()

        ae2 = ExperimentAuthor(experiment=exp, author='russell', order=1)
        ae2.save()

        ae3 = ExperimentAuthor(experiment=exp, author='uli', order=50)
        ae3.save()

        authors = exp.experimentauthor_set.all()

        # confirm that there are 2 authors
        self.assertEqual(len(authors), 3)
        self.assertTrue(ae1 in authors)
        self.assertTrue(ae2 in authors)
        self.assertTrue(ae3 == authors[1])
Ejemplo n.º 44
0
    def testCleanExperiment(self):
        experiment = Experiment(created_by=self.user)
        experiment.save()

        eh = EmbargoHandler(experiment.id)
        self.assertTrue(eh.never_expires())
        self.assertFalse(eh.has_any_expiry())
        self.assertFalse(eh.can_be_defaulted())
        self.assertTrue(eh.because_no_end_date())
        self.assertEqual(None, eh.get_expiry_date())

        self.assertRaises(Exception, eh.prevent_expiry)
        eh.reset_to_default()  # should not raise Exception
        self.assertRaises(Exception, eh.set_expiry)
Ejemplo n.º 45
0
    def _get_experiment(self, entry, user):
        '''
        Finds the Experiment corresponding to this entry.
        If it doesn't exist, a new Experiment is created and given
        an appropriate ACL for the user.
        '''
        experimentId, title, public_access = self._get_experiment_details(entry, user)
        if (experimentId, title) == (None, None):
            return None
        
        if experimentId:
            try:
                # Try and match ExperimentID if we have one.
                param_name = ParameterName.objects.\
                    get(name=IngestOptions.PARAM_EXPERIMENT_ID, \
                        schema=AtomImportSchemas.get_schema(Schema.EXPERIMENT))
                parameter = ExperimentParameter.objects.\
                    get(name=param_name, string_value=experimentId)
                return parameter.parameterset.experiment
            except ExperimentParameter.DoesNotExist:
                pass
        
        # Failing that, match ExperimentTitle if possible
        if title:
            try:
                experiment = Experiment.objects.get(title=title, created_by=user)
                return experiment
            except Experiment.DoesNotExist:
                pass

        # No existing expriment - shall we create a new one?
        if not IngestOptions.ALLOW_EXPERIMENT_CREATION:
            logging.getLogger(__name__).info("Skipping dataset. ALLOW_EXPERIMENT_CREATION disabled, so ignoring (experimentId: {0}, title: {1}, user: {2})".format(
                    experimentId, title, user))
            return None
        experiment = Experiment(title=title, created_by=user, public_access=public_access)
        experiment.save()
        self._create_experiment_id_parameter_set(experiment, experimentId)
        logging.getLogger(__name__).info("Created experiment {0} (title: {1}, user: {2}, experimentId: {3})".format(
                        experiment.id, experiment.title, experiment.created_by, experimentId)) 
        acl = ExperimentACL(experiment=experiment,
                pluginId=django_user,
                entityId=user.id,
                canRead=True,
                canWrite=True,
                canDelete=True,
                isOwner=True,
                aclOwnershipType=ExperimentACL.OWNER_OWNED)
        acl.save()
        return experiment
Ejemplo n.º 46
0
 def setUp(self):
     self.user = User(username='******',
                      password='******',
                      email='*****@*****.**')
     self.user.save()
     self.exp = Experiment(approved=True,
                           title='title1',
                           institution_name='institution1',
                           description='description1',
                           created_by=self.user,
                           public_access=Experiment.PUBLIC_ACCESS_FULL)
     self.exp.save()
     self.uid = 0
     self.url = 'http://remotetardis:8080'
Ejemplo n.º 47
0
    def setUp(self):
        self.hostname = '127.0.0.1'
        self.username = '******'
        self.password = '******'
        email = ''
        self.user = User.objects.create_user(self.username, email,
                                             self.password)
        self.exp = Experiment(title='test exp1',
                              institution_name='monash',
                              created_by=self.user)
        self.exp.save()

        self.acl = ObjectACL(content_object=self.exp,
                             pluginId='django_user',
                             entityId=str(self.user.id),
                             isOwner=True,
                             canRead=True,
                             canWrite=True,
                             canDelete=True,
                             aclOwnershipType=ObjectACL.OWNER_OWNED)
        self.acl.save()

        self.dataset = Dataset(description='test dataset1')
        self.dataset.save()
        self.dataset.experiments.set([self.exp])
        self.dataset.save()

        def _build(dataset, filename, url):
            datafile_content = b"\n".join(
                [b'some data %d' % i for i in range(1000)])
            filesize = len(datafile_content)
            datafile = DataFile(dataset=dataset,
                                filename=filename,
                                size=filesize)
            datafile.save()
            dfo = DataFileObject(
                datafile=datafile,
                storage_box=datafile.get_default_storage_box(),
                uri=url)
            dfo.file_object = BytesIO(datafile_content)
            dfo.save()
            return datafile

        saved_setting = settings.REQUIRE_DATAFILE_CHECKSUMS
        try:
            settings.REQUIRE_DATAFILE_CHECKSUMS = False
            _build(self.dataset, 'file.txt', 'path/file.txt')
        finally:
            settings.REQUIRE_DATAFILE_CHECKSUMS = saved_setting
Ejemplo n.º 48
0
 def create_experiment(i):
     experiment = Experiment(title='Text Experiment #%d' % i,
                             institution_name='Test Uni',
                             created_by=user)
     experiment.save()
     acl = ExperimentACL(
         pluginId=django_user,
         entityId=str(user.id),
         experiment=experiment,
         canRead=True,
         isOwner=True,
         aclOwnershipType=ExperimentACL.OWNER_OWNED,
     )
     acl.save()
     return experiment
Ejemplo n.º 49
0
    def testResetToDefault(self):
        expiry = dt.datetime(2034,12,4)
        expiry_as_string = '2034/12/04'

        experiment = Experiment(created_by=self.user)
        experiment.save()
        eh = EmbargoHandler(experiment.id, True)
        eh.set_expiry(expiry_as_string)

        self.assertEqual(expiry, eh.get_expiry_date())

        eh = EmbargoHandler(experiment.id, True)
        eh.reset_to_default()

        self.assertEqual(None, eh.get_expiry_date())
Ejemplo n.º 50
0
    def setUp(self):
        # create user
        self.testuser = User(username="******")
        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()
Ejemplo n.º 51
0
    def setUp(self):
        """
        setting up essential objects, copied from tests above
        """

        user = '******'
        pwd = 'secret'
        email = ''
        self.user = User.objects.create_user(user, email, pwd)
        self.userProfile = self.user.userprofile
        self.exp = Experiment(title='test exp1',
                              institution_name='monash', created_by=self.user)
        self.exp.save()
        self.acl = ObjectACL(
            pluginId=django_user,
            entityId=str(self.user.id),
            content_object=self.exp,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ObjectACL.OWNER_OWNED,
        )
        self.acl.save()
        self.dataset = Dataset(description='dataset description...')
        self.dataset.save()
        self.dataset.experiments.add(self.exp)
        self.dataset.save()

        self.datafile = DataFile(dataset=self.dataset,
                                 size=42, filename="foo",
                                 md5sum="junk")
        self.datafile.save()
Ejemplo n.º 52
0
    def setUp(self):

        self.user = User(username='******', password='******', email='*****@*****.**')
        self.user.save()
        self.exp = Experiment(
                approved = True,
                title = 'title1',
                institution_name = 'institution1',
                description = 'description1',
                created_by = self.user,
                public_access = Experiment.PUBLIC_ACCESS_FULL
                )
        self.uid = 0
        self.url = 'http://remotetardis:8080'

        self.mock_ts = flexmock()
        flexmock(TransferClient).new_instances(self.mock_ts)

        self.mock_integrity = flexmock()
        flexmock(IntegrityCheck).new_instances(self.mock_integrity)

        self.status = {
                'human_status': 'this is a readable status',
                'message': 'this is a message'
                }
Ejemplo n.º 53
0
    def setUp(self):
        # Create test owner without enough details
        username, email, password = ('testuser',
                                     '*****@*****.**',
                                     'password')
        user = User.objects.create_user(username, email, password)
        profile = UserProfile(user=user, isDjangoAccount=True)
        profile.save()

        # 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 = ExperimentACL(
            pluginId='django_user',
            entityId=str(user.id),
            experiment=experiment,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ExperimentACL.OWNER_OWNED,
            )
        acl.save()

        dataset = Dataset(description='dataset description...')
        dataset.save()
        dataset.experiments.add(experiment)
        dataset.save()

        def create_datafile(index):
            testfile = path.join(path.dirname(__file__), 'fixtures',
                                 'jeol_sem_test%d.txt' % index)

            size, sha512sum = get_size_and_sha512sum(testfile)

            datafile = Dataset_File(dataset=dataset,
                                    filename=path.basename(testfile),
                                    url='file://'+path.abspath(testfile),
                                    protocol='file',
                                    size=size,
                                    sha512sum=sha512sum)
            datafile.verify()
            datafile.save()
            return datafile

        self.dataset = dataset
        self.datafiles = [create_datafile(i) for i in (1,2)]
Ejemplo n.º 54
0
def has_experiment_download_access(request, experiment_id):
    if Experiment.safe.owned_and_shared(request) \
                      .filter(id=experiment_id) \
                      .exists():
        return True
    else:
        exp = Experiment.objects.get(id=experiment_id)
        return Experiment.public_access_implies_distribution(exp.public_access)
Ejemplo n.º 55
0
 def setUp(self):
     self.user = User(username='******',
                      password='******',
                      email='*****@*****.**')
     self.user.save()
     self.exp = Experiment(approved=True,
                           title='title1',
                           institution_name='institution1',
                           description='description1',
                           created_by=self.user,
                           public_access=Experiment.PUBLIC_ACCESS_FULL)
     self.exp.save()
     self.synced_exp = SyncedExperiment(uid='tardis.1',
                                        experiment=self.exp,
                                        provider_url='url')
     self.synced_exp.msg = '{"message": "You broke everything!"}'
     self.synced_exp.save()
Ejemplo n.º 56
0
def generate_experiment(datasets=[], users=[]):
    from tardis.tardis_portal.models import Experiment, ObjectACL
    experiment = Experiment(created_by=users[0])
    experiment.save()
    for ds in datasets:
        ds.experiments.add(experiment)
        ds.save()
    for user in users:
        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
Ejemplo n.º 57
0
    def setUp(self):
        user, client = _create_user_and_login()

        experiment = Experiment(title='Norwegian Blue',
                                description='Parrot + 40kV',
                                created_by=user)
        experiment.save()
        acl = ObjectACL(content_object=experiment,
                        pluginId='django_user',
                        entityId=str(user.id),
                        isOwner=False,
                        canRead=True,
                        canWrite=False,
                        canDelete=False,
                        aclOwnershipType=ObjectACL.OWNER_OWNED)
        acl.save()
        self.client = client
        self.experiment = experiment
Ejemplo n.º 58
0
 def setUp(self):
     self.user = User.objects.create_user(username='******',
                                          email='*****@*****.**',
                                          password='******')
     self.settings = ('tardis.tardis_portal.tests.test_publishservice.MockRifCsProvider',)
     self.e1 = Experiment(id="1", title="Experiment 1",
                          description="This is my description.",
                          created_by=self.user,
                          public_access=Experiment.PUBLIC_ACCESS_NONE)
Ejemplo n.º 59
0
class ANDSDOITestCase(TestCase):

    def setUp(self):
        self.user = User.objects.create_user('test', '', 'test')
        self.expt = Experiment(title='test exp1',
                                institution_name='monash',
                                created_by=self.user,
                                )
        self.schema, _ = Schema.objects.get_or_create(namespace=settings.DOI_NAMESPACE)
        self.doi_name, _ = ParameterName.objects.get_or_create(schema=self.schema, full_name='DOI', name='doi')
        self.expt.save()

    def test_init(self):
        doi_service = DOIService(self.expt)

    def test_get_doi_none(self):
        doi_service = DOIService(self.expt)
        self.assertEquals(None, doi_service.get_doi())