def setUp(self): from django.contrib.auth.models import User from tempfile import mkdtemp user = '******' pwd = 'secret' email = '' self.user = User.objects.create_user(user, email, pwd) self.test_dir = mkdtemp() self.exp = models.Experiment( title='test exp1', institution_name='monash', created_by=self.user, ) self.exp.save() self.dataset = models.Dataset(description="dataset description...", experiment=self.exp) self.dataset.save() self.datafile = models.Dataset_File(dataset=self.dataset,\ filename="testfile.txt", url="file://1/testfile.txt") self.datafile.save() self.schema = models.Schema(namespace="http://localhost/psmtest/df/", name="Parameter Set Manager", type=3) self.schema.save() self.parametername1 = models.ParameterName(schema=self.schema, name="parameter1", full_name="Parameter 1") self.parametername1.save() self.parametername2 = models.ParameterName( schema=self.schema, name="parameter2", full_name="Parameter 2", data_type=models.ParameterName.NUMERIC) self.parametername2.save() self.datafileparameterset = models.DatafileParameterSet( schema=self.schema, dataset_file=self.datafile) self.datafileparameterset.save() self.datafileparameter1 = models.DatafileParameter( parameterset=self.datafileparameterset, name=self.parametername1, string_value="test1") self.datafileparameter1.save() self.datafileparameter2 = models.DatafileParameter( parameterset=self.datafileparameterset, name=self.parametername2, numerical_value=2) self.datafileparameter2.save()
def test_parameter(self): from tardis.tardis_portal import models exp = models.Experiment( title='test exp1', institution_name='Australian Synchrotron', approved=True, created_by=self.user, public_access=models.Experiment.PUBLIC_ACCESS_NONE, ) exp.save() dataset = models.Dataset(description="dataset description") dataset.save() dataset.experiments.add(exp) dataset.save() df_file = models.Dataset_File( dataset=dataset, filename='file.txt', url='path/file.txt', ) df_file.save() df_schema = models.Schema( namespace='http://www.cern.ch/felzmann/schema1.xml', type=models.Schema.DATAFILE) df_schema.save() ds_schema = models.Schema( namespace='http://www.cern.ch/felzmann/schema2.xml', type=models.Schema.DATASET) ds_schema.save() exp_schema = models.Schema( namespace='http://www.cern.ch/felzmann/schema3.xml', type=models.Schema.EXPERIMENT) exp_schema.save() df_parname = models.ParameterName( schema=df_schema, name='name', full_name='full_name', units='image/jpg', data_type=models.ParameterName.FILENAME) df_parname.save() ds_parname = models.ParameterName( schema=ds_schema, name='name', full_name='full_name', units='image/jpg', data_type=models.ParameterName.FILENAME) ds_parname.save() exp_parname = models.ParameterName( schema=exp_schema, name='name', full_name='full_name', units='image/jpg', data_type=models.ParameterName.FILENAME) exp_parname.save() df_parset = models.DatafileParameterSet(schema=df_schema, dataset_file=df_file) df_parset.save() ds_parset = models.DatasetParameterSet(schema=ds_schema, dataset=dataset) ds_parset.save() exp_parset = models.ExperimentParameterSet(schema=exp_schema, experiment=exp) exp_parset.save() from base64 import b64encode from os import path from os import remove filename = path.join(path.dirname(__file__), 'test.jpg') df_parameter = models.DatafileParameter(name=df_parname, parameterset=df_parset, string_value=b64encode( open(filename).read())) df_parameter.save() ds_parameter = models.DatasetParameter(name=ds_parname, parameterset=ds_parset, string_value=b64encode( open(filename).read())) ds_parameter.save() exp_parameter = models.ExperimentParameter(name=exp_parname, parameterset=exp_parset, string_value=b64encode( open(filename).read())) exp_parameter.save() self.assertEqual( "<a href='/test/DatafileImage/load/%i/' target='_blank'><img src='/test/DatafileImage/load/%i/' /></a>" % (df_parameter.id, df_parameter.id), df_parameter.get()) self.assertEqual( "<a href='/test/DatasetImage/load/%i/' target='_blank'><img src='/test/DatasetImage/load/%i/' /></a>" % (ds_parameter.id, ds_parameter.id), ds_parameter.get()) self.assertEqual( "<a href='/test/ExperimentImage/load/%i/' target='_blank'><img src='/test/ExperimentImage/load/%i/' /></a>" % (exp_parameter.id, exp_parameter.id), exp_parameter.get()) remove(path.join(settings.FILE_STORE_PATH, df_parameter.string_value)) remove(path.join(settings.FILE_STORE_PATH, ds_parameter.string_value)) remove(path.join(settings.FILE_STORE_PATH, exp_parameter.string_value))
def test_parameter(self): from tardis.tardis_portal import models exp = models.Experiment( title='test exp1', institution_name='Australian Synchrotron', approved=True, created_by=self.user, public_access=models.Experiment.PUBLIC_ACCESS_NONE, ) exp.save() dataset = models.Dataset(description="dataset description") dataset.save() dataset.experiments.add(exp) dataset.save() df_file = models.DataFile(dataset=dataset, filename='file.txt', size=42, md5sum='bogus') df_file.save() df_schema = models.Schema( namespace='http://www.cern.ch/felzmann/schema1.xml', type=models.Schema.DATAFILE) df_schema.save() ds_schema = models.Schema( namespace='http://www.cern.ch/felzmann/schema2.xml', type=models.Schema.DATASET) ds_schema.save() exp_schema = models.Schema( namespace='http://www.cern.ch/felzmann/schema3.xml', type=models.Schema.EXPERIMENT) exp_schema.save() df_parname = models.ParameterName( schema=df_schema, name='name', full_name='full_name', units='image/jpg', data_type=models.ParameterName.FILENAME) df_parname.save() ds_parname = models.ParameterName( schema=ds_schema, name='name', full_name='full_name', units='image/jpg', data_type=models.ParameterName.FILENAME) ds_parname.save() exp_parname = models.ParameterName( schema=exp_schema, name='name', full_name='full_name', units='image/jpg', data_type=models.ParameterName.FILENAME) exp_parname.save() df_parset = models.DatafileParameterSet(schema=df_schema, datafile=df_file) df_parset.save() ds_parset = models.DatasetParameterSet(schema=ds_schema, dataset=dataset) ds_parset.save() exp_parset = models.ExperimentParameterSet(schema=exp_schema, experiment=exp) exp_parset.save() from os import path with self.settings(METADATA_STORE_PATH=path.dirname(__file__)): filename = 'test.jpg' df_parameter = models.DatafileParameter(name=df_parname, parameterset=df_parset, string_value=filename) df_parameter.save() ds_parameter = models.DatasetParameter(name=ds_parname, parameterset=ds_parset, string_value=filename) ds_parameter.save() exp_parameter = models.ExperimentParameter(name=exp_parname, parameterset=exp_parset, string_value=filename) exp_parameter.save() self.assertEqual( "<a href='/display/DatafileImage/load/%i/' target='_blank'><img style='width: 300px;' src='/display/DatafileImage/load/%i/' /></a>" % # noqa (df_parameter.id, df_parameter.id), df_parameter.get()) self.assertEqual( "<a href='/display/DatasetImage/load/%i/' target='_blank'><img style='width: 300px;' src='/display/DatasetImage/load/%i/' /></a>" % # noqa (ds_parameter.id, ds_parameter.id), ds_parameter.get()) self.assertEqual( "<a href='/display/ExperimentImage/load/%i/' target='_blank'><img style='width: 300px;' src='/display/ExperimentImage/load/%i/' /></a>" % # noqa (exp_parameter.id, exp_parameter.id), exp_parameter.get())