def setUp(self):
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Shawn',
            last_name='Crawley',
            superuser=False,
            groups=[self.group]
        )
        self.allowance = 0.00001

        self.resWebApp = hydroshare.create_resource(
            resource_type='ToolResource',
            owner=self.user,
            title='Test Web App Resource',
            keywords=['kw1', 'kw2'])

        self.resComposite = hydroshare.create_resource(
            resource_type='CompositeResource',
            owner=self.user,
            title='Test Composite Resource',
            keywords=['kw1', 'kw2'])

        self.test_file_path = 'hs_composite_resource/tests/data/{}'

        self.factory = RequestFactory()
Exemple #2
0
    def setUp(self):
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account('*****@*****.**',
                                              username='******',
                                              first_name='Shawn',
                                              last_name='Crawley',
                                              superuser=False,
                                              groups=[self.group])
        self.allowance = 0.00001

        self.resWebApp = hydroshare.create_resource(
            resource_type='ToolResource',
            owner=self.user,
            title='Test Web App Resource',
            keywords=['kw1', 'kw2'])

        self.resComposite = hydroshare.create_resource(
            resource_type='CompositeResource',
            owner=self.user,
            title='Test Composite Resource',
            keywords=['kw1', 'kw2'])

        self.test_file_path = 'hs_composite_resource/tests/data/{}'

        self.factory = RequestFactory()
    def setUp(self):
        super(T01BasicFunction, self).setUp()
        global_reset()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        self.cat = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='f_cat',
            last_name='l_cat',
            superuser=False,
            groups=[]
        )

        self.dog = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='f_dog',
            last_name='l_dog',
            superuser=False,
            groups=[]
        )

        self.scratching = hydroshare.create_resource(resource_type='GenericResource',
                                                     owner=self.cat,
                                                     title='Test Resource',
                                                     metadata=[],)

        self.bones = hydroshare.create_resource(resource_type='GenericResource',
                                                owner=self.dog,
                                                title='all about dog bones',
                                                metadata=[],)
    def setUp(self):
        super(TestNewVersionResource, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        # create a user who is the owner of the resource to be versioned
        self.owner = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='owner_firstname',
            last_name='owner_lastname',
            superuser=False,
            groups=[]
        )

        # create a user who is NOT the owner of the resource to be versioned
        self.nonowner = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='nonowner_firstname',
            last_name='nonowner_lastname',
            superuser=False,
            groups=[]
        )

        # create a generic resource
        self.res_generic = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.owner,
            title='Test Generic Resource'
        )

        test_file1 = open('test1.txt', 'w')
        test_file1.write("Test text file in test1.txt")
        test_file1.close()
        test_file2 = open('test2.txt', 'w')
        test_file2.write("Test text file in test2.txt")
        test_file2.close()
        self.test_file1 = open('test1.txt', 'r')
        self.test_file2 = open('test2.txt', 'r')

        hydroshare.add_resource_files(self.res_generic.short_id, self.test_file1, self.test_file2)

        # create a raster resource that represents a specific resource type
        raster_file = 'hs_core/tests/data/cea.tif'
        temp_dir = tempfile.mkdtemp()
        temp_raster_file = os.path.join(temp_dir, 'cea.tif')
        shutil.copy(raster_file, temp_raster_file)
        self.raster_obj = open(temp_raster_file, 'r')
        files = [UploadedFile(file=self.raster_obj, name='cea.tif')]
        self.res_raster = hydroshare.create_resource(
            resource_type='RasterResource',
            owner=self.owner,
            title='Test Raster Resource',
            files=files,
            metadata=[]
        )
        # call the post creation process here for the metadata to be
        # extracted
        utils.resource_post_create_actions(resource=self.res_raster, user=self.owner, metadata=[])
Exemple #5
0
    def setUp(self):
        super(TestNewVersionResource, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        # create a user who is the owner of the resource to be versioned
        self.owner = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='owner_firstname',
            last_name='owner_lastname',
            superuser=False,
            groups=[]
        )

        # create a user who is NOT the owner of the resource to be versioned
        self.nonowner = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='nonowner_firstname',
            last_name='nonowner_lastname',
            superuser=False,
            groups=[]
        )

        # create a generic resource
        self.res_generic = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.owner,
            title='Test Generic Resource'
        )

        test_file1 = open('test1.txt', 'w')
        test_file1.write("Test text file in test1.txt")
        test_file1.close()
        test_file2 = open('test2.txt', 'w')
        test_file2.write("Test text file in test2.txt")
        test_file2.close()
        self.test_file1 = open('test1.txt', 'r')
        self.test_file2 = open('test2.txt', 'r')

        hydroshare.add_resource_files(self.res_generic.short_id, self.test_file1, self.test_file2)

        # create a raster resource that represents a specific resource type
        raster_file = 'hs_core/tests/data/cea.tif'
        temp_dir = tempfile.mkdtemp()
        temp_raster_file = os.path.join(temp_dir, 'cea.tif')
        shutil.copy(raster_file, temp_raster_file)
        self.raster_obj = open(temp_raster_file, 'r')
        files = [UploadedFile(file=self.raster_obj, name='cea.tif')]
        self.res_raster = hydroshare.create_resource(
            resource_type='RasterResource',
            owner=self.owner,
            title='Test Raster Resource',
            files=files,
            metadata=[]
        )
        # call the post creation process here for the metadata to be
        # extracted
        utils.resource_post_create_actions(resource=self.res_raster, user=self.owner, metadata=[])
    def setUp(self):
        super(T11ExplicitGet, self).setUp()
        global_reset()

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.A_user = hydroshare.create_account('*****@*****.**',
                                                username='******',
                                                first_name='A First',
                                                last_name='A Last',
                                                superuser=False,
                                                groups=[])

        self.B_user = hydroshare.create_account('*****@*****.**',
                                                username='******',
                                                first_name='B First',
                                                last_name='B Last',
                                                superuser=False,
                                                groups=[])

        self.C_user = hydroshare.create_account('*****@*****.**',
                                                username='******',
                                                first_name='C First',
                                                last_name='C Last',
                                                superuser=False,
                                                groups=[])

        self.r1_resource = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.A_user,
            title='R1',
            metadata=[],
        )

        self.r2_resource = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.A_user,
            title='R2',
            metadata=[],
        )

        self.r3_resource = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.A_user,
            title='R3',
            metadata=[],
        )

        self.A_group = self.A_user.uaccess\
            .create_group(title='Test Group A',
                          description="This group is all about testing")

        self.B_group = self.B_user.uaccess\
            .create_group(title='Test Group B',
                          description="This group is all about testing")

        self.C_group = self.C_user.uaccess\
            .create_group(title='Test Group C',
                          description="This group is all about testing")
    def setUp(self):
        super(TestMODFLOWModelInstanceMetaData, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[self.group]
        )

        self.res = hydroshare.create_resource(
            resource_type='MODFLOWModelInstanceResource',
            owner=self.user,
            title='Test MODFLOW Model Instance Resource'
        )

        self.resGenModelProgram = hydroshare.create_resource(
            resource_type='ModelProgramResource',
            owner=self.user,
            title='Model MODFLOW Program Resource'
        )

        self.resMODFLOWModelProgram = hydroshare.create_resource(
            resource_type='ModelProgramResource',
            owner=self.user,
            title='Model Program Resource 2'
        )

        self.temp_dir = tempfile.mkdtemp()

        d = 'hs_modflow_modelinstance/tests/modflow_example/'
        self.file_list = []
        self.file_names = []
        self.sample_nam_name = 'example.nam'
        self.sample_nam_name2 = 'example2.nam'
        self.sample_dis_file = 'example.dis'
        for file in os.listdir(d):
            self.file_names.append(file)
            target_temp_file = os.path.join(self.temp_dir, file)
            shutil.copy("{}{}".format(d, file), target_temp_file)
            if self.sample_nam_name == file:
                self.sample_nam_obj = open(target_temp_file, 'r')
            elif self.sample_nam_name2 == file:
                self.sample_nam_obj2 = open(target_temp_file, 'r')
            elif self.sample_dis_file == file:
                self.sample_dis_obj = open(target_temp_file, 'r')
            else:
                self.file_list.append(target_temp_file)

        self.file_name = "MIR.txt"
        temp_text_file = os.path.join(self.temp_dir, self.file_name)
        text_file = open(temp_text_file, 'w')
        text_file.write("Model Instance resource files")
        self.text_file_obj = open(temp_text_file, 'r')
    def setUp(self):
        super(T08ResourceFlags, self).setUp()
        global_reset()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.admin = hydroshare.create_account('*****@*****.**',
                                               username='******',
                                               first_name='administrator',
                                               last_name='couch',
                                               superuser=True,
                                               groups=[])

        self.cat = hydroshare.create_account('*****@*****.**',
                                             username='******',
                                             first_name='not a dog',
                                             last_name='last_name_cat',
                                             superuser=False,
                                             groups=[])

        self.dog = hydroshare.create_account('*****@*****.**',
                                             username='******',
                                             first_name='a little arfer',
                                             last_name='last_name_dog',
                                             superuser=False,
                                             groups=[])

        self.bat = hydroshare.create_account('*****@*****.**',
                                             username='******',
                                             first_name='not a man',
                                             last_name='last_name_bat',
                                             superuser=False,
                                             groups=[])

        self.nobody = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='no one in particular',
            last_name='last_name_nobody',
            superuser=False,
            groups=[])

        self.bones = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.dog,
            title='all about dog bones',
            metadata=[],
        )

        self.chewies = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.dog,
            title='all about dog chewies',
            metadata=[],
        )
    def setUp(self):
        super(T11ExplicitGet, self).setUp()
        global_reset()

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.A_user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='A First',
            last_name='A Last',
            superuser=False,
            groups=[]
        )

        self.B_user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='B First',
            last_name='B Last',
            superuser=False,
            groups=[]
        )

        self.C_user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='C First',
            last_name='C Last',
            superuser=False,
            groups=[]
        )

        self.r1_resource = hydroshare.create_resource(
            resource_type='GenericResource', owner=self.A_user, title='R1', metadata=[],)

        self.r2_resource = hydroshare.create_resource(
            resource_type='GenericResource', owner=self.A_user, title='R2', metadata=[],)

        self.r3_resource = hydroshare.create_resource(
            resource_type='GenericResource', owner=self.A_user, title='R3', metadata=[],)

        self.A_group = self.A_user.uaccess\
            .create_group(title='Test Group A',
                          description="This group is all about testing")

        self.B_group = self.B_user.uaccess\
            .create_group(title='Test Group B',
                          description="This group is all about testing")

        self.C_group = self.C_user.uaccess\
            .create_group(title='Test Group C',
                          description="This group is all about testing")
Exemple #10
0
    def setUp(self):
        super(TestMODFLOWModelInstanceMetaData, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account('*****@*****.**',
                                              username='******',
                                              first_name='Creator_FirstName',
                                              last_name='Creator_LastName',
                                              superuser=False,
                                              groups=[self.group])

        self.res = hydroshare.create_resource(
            resource_type='MODFLOWModelInstanceResource',
            owner=self.user,
            title='Test MODFLOW Model Instance Resource')

        self.resGenModelProgram = hydroshare.create_resource(
            resource_type='ModelProgramResource',
            owner=self.user,
            title='Model MODFLOW Program Resource')

        self.resMODFLOWModelProgram = hydroshare.create_resource(
            resource_type='ModelProgramResource',
            owner=self.user,
            title='Model Program Resource 2')

        self.temp_dir = tempfile.mkdtemp()

        d = 'hs_modflow_modelinstance/tests/modflow_example/'
        self.file_list = []
        self.file_names = []
        self.sample_nam_name = 'example.nam'
        self.sample_nam_name2 = 'example2.nam'
        self.sample_dis_file = 'example.dis'
        for file in os.listdir(d):
            self.file_names.append(file)
            target_temp_file = os.path.join(self.temp_dir, file)
            shutil.copy("{}{}".format(d, file), target_temp_file)
            if self.sample_nam_name == file:
                self.sample_nam_obj = open(target_temp_file, 'rb')
            elif self.sample_nam_name2 == file:
                self.sample_nam_obj2 = open(target_temp_file, 'rb')
            elif self.sample_dis_file == file:
                self.sample_dis_obj = open(target_temp_file, 'rb')
            else:
                self.file_list.append(target_temp_file)

        self.file_name = "MIR.txt"
        temp_text_file = os.path.join(self.temp_dir, self.file_name)
        text_file = open(temp_text_file, 'w')
        text_file.write("Model Instance resource files")
        self.text_file_obj = open(temp_text_file, 'rb')
    def setUp(self):
        # create two users
        self.user1 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[]
        )

        self.user2 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator2_FirstName',
            last_name='Creator2_LastName',
            superuser=False,
            groups=[]
        )

        # create a group
        self.group = hydroshare.create_group(
            'Test group',
            members=[],
            owners=[self.user1]
        )

        # create a resource
        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user1,
            'Test Resource',
            #edit_groups=[self.group],
            edit_users=[self.user1, self.user2]
        )
Exemple #12
0
    def setUp(self):
        super(TestGroup, self).setUp()
        patcher_email_send_call = patch('hs_core.views.send_action_to_take_email')
        patcher_email_send_call.start()
        self.addCleanup(patcher_email_send_call.stop)

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.username = '******'
        self.password = '******'
        self.john = hydroshare.create_account(
            '*****@*****.**',
            username=self.username,
            first_name='John',
            last_name='Clarson',
            superuser=False,
            password=self.password,
            groups=[]
        )
        self.mike = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Mike',
            last_name='Jensen',
            superuser=False,
            groups=[]
        )

        # create a resource for sharing with group
        self.resource = hydroshare.create_resource(resource_type='GenericResource',
                                                   owner=self.john,
                                                   title='Test Resource',
                                                   metadata=[]
                                                   )
    def setUp(self):
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        # create a user
        self.user = users.create_account(
            '*****@*****.**',
            username='******',
            first_name='some_first_name',
            last_name='some_last_name',
            superuser=False,
            groups=[self.group])

        # get the user's id
        self.userid = User.objects.get(username=self.user).pk

        self.group = users.create_group(
            'MyGroup',
            members=[self.user],
            owners=[self.user]
        )

        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user,
            'My Test Resource'
        )
Exemple #14
0
def create_netcdf(request, *args, **kwargs):

    NetcdfFormset = inlineformset_factory(NetcdfResource,
                                          NetcdfVariable,
                                          extra=1)

    if request.method == 'POST':
        formset = NetcdfFormset(request.POST)
        if formset.is_valid():

            res = hydroshare.create_resource(
                resource_type='NetcdfResource',
                owner=request.user,
                #dublin_metadata=dcterms
            )

            for form in formset:
                print(form.as_table())
            # TODO add netcdf variable instance. Need to know what is in the form
            #formset.save()

            return HttpResponseRedirect(res.get_absolute_url())
    else:
        formset = NetcdfFormset()

    return render_to_response("create-netcdf.html", {"formset": formset})
    def _test_delete_optional_file(self, file_extension):
        # test that deleting the optional file with the specified extension *file_extension*
        # deletes only that file

        self.resGeoFeature = hydroshare.create_resource(
            resource_type='GeographicFeatureResource',
            owner=self.user,
            title='Test Geographic Feature (shapefiles)'
        )
        # check that the resource has no files
        self.assertEqual(self.resGeoFeature.files.count(), 0)

        # add files first
        files = []
        target = 'hs_geographic_feature_resource/tests/gis.osm_adminareas_v06_all_files.zip'
        files.append(UploadedFile(file=open(target, 'r'),
                                  name='gis.osm_adminareas_v06_all_files.zip'))
        hydroshare.utils.resource_file_add_process(self.resGeoFeature, files, self.user, )

        # check that the resource has 15 files
        self.assertEqual(self.resGeoFeature.files.count(), 15)

        # find the .shp file and delete it
        for f in self.resGeoFeature.files.all():
            if f.extension == file_extension:
                hydroshare.delete_resource_file(self.resGeoFeature.short_id, f.id, self.user)
                break
        # resource should have 14 files
        self.assertEqual(self.resGeoFeature.files.count(), 14)
        self.resGeoFeature.delete()
Exemple #16
0
    def setUp(self):
        super(TestUtils, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[]
        )

        self.user2 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='user2_FirstName',
            last_name='user2_LastName',
            superuser=False,
            groups=[]
        )

        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user,
            'test resource',
        )
        self.res.doi = 'doi1000100010001'
        self.res.save()
Exemple #17
0
    def setUp(self):
        super(TestGroup, self).setUp()
        patcher_email_send_call = patch(
            'hs_core.views.send_action_to_take_email')
        patcher_email_send_call.start()
        self.addCleanup(patcher_email_send_call.stop)

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.username = '******'
        self.password = '******'
        self.john = hydroshare.create_account('*****@*****.**',
                                              username=self.username,
                                              first_name='John',
                                              last_name='Clarson',
                                              superuser=False,
                                              password=self.password,
                                              groups=[])
        self.mike = hydroshare.create_account('*****@*****.**',
                                              username='******',
                                              first_name='Mike',
                                              last_name='Jensen',
                                              superuser=False,
                                              groups=[])

        # create a resource for sharing with group
        self.resource = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.john,
            title='Test Resource',
            metadata=[])
def create_ref_time_series(request, *args, **kwargs):
    try:
        ts_dict = request.session.get('ts', False)
        if not ts_dict:
            raise Exception("No ts in session")

        url = ts_dict['url']
        reference_type = ts_dict['ref_type']
        frm = CreateRefTimeSeriesForm(request.POST)
        if frm.is_valid():
            metadata = []
            ts_utils.prepare_metadata_list(metadata=metadata,
                                           ts_dict=ts_dict,
                                           url=url,
                                           reference_type=reference_type)

            res = hydroshare.create_resource(
                resource_type='RefTimeSeriesResource',
                owner=request.user,
                title=frm.cleaned_data.get('title'),
                metadata=metadata)

            if ts_dict:
                del request.session['ts']

            request.session['just_created'] = True
            return HttpResponseRedirect(res.get_absolute_url())
        else:
            raise Exception("Parameters validation error")
    except Exception as ex:
        logger.exception("create_ref_time_series: %s" % (ex.message))
        context = {
            'resource_creation_error': "Error: failed to create resource."
        }
        return render(request, 'pages/create-ref-time-series.html', context)
Exemple #19
0
    def setUp(self):
        super(TestUtils, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[]
        )

        self.user2 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='user2_FirstName',
            last_name='user2_LastName',
            superuser=False,
            groups=[]
        )

        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user,
            'test resource',
        )
        self.res.doi = 'doi1000100010001'
        self.res.save()
Exemple #20
0
    def setUp(self):
        self.api_client = TestApiClient()
        self.username = '******'
        self.password = '******'

        # create a user
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username=self.username,
            first_name='Tian',
            last_name='Gan',
            superuser=False,
            password=self.password,
            groups=[]
        )

        # create a resource
        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user,
            'My resource'
        )

        # create a group
        self.group = hydroshare.create_group(
            'Test group',
            members=[],
            owners=[self.user1]
        )
Exemple #21
0
    def setUp(self):
        super(TestFileTypeViewFunctions, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.username = '******'
        self.password = '******'
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username=self.username,
            first_name='John',
            last_name='Clarson',
            superuser=False,
            password=self.password,
            groups=[]
        )

        self.composite_resource = hydroshare.create_resource(
            resource_type='CompositeResource',
            owner=self.user,
            title='Test Raster File Metadata'
        )

        self.factory = RequestFactory()

        self.temp_dir = tempfile.mkdtemp()
        self.raster_file_name = 'small_logan.tif'
        self.raster_file = 'hs_file_types/tests/{}'.format(self.raster_file_name)
        target_temp_raster_file = os.path.join(self.temp_dir, self.raster_file_name)
        shutil.copy(self.raster_file, target_temp_raster_file)
        self.raster_file_obj = open(target_temp_raster_file, 'r')

        self.netcdf_file_name = 'netcdf_valid.nc'
        self.netcdf_file = 'hs_file_types/tests/{}'.format(self.netcdf_file_name)
        target_temp_netcdf_file = os.path.join(self.temp_dir, self.netcdf_file_name)
        shutil.copy(self.netcdf_file, target_temp_netcdf_file)
        self.netcdf_file_obj = open(target_temp_netcdf_file, 'r')
    def test_resolve_doi(self):
        self.user_creator = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[])

        new_resource = hydroshare.create_resource('GenericResource',
                                                  self.user_creator,
                                                  'My Test Resource')

        # assign doi to the resource
        new_resource.doi = 'xyz'
        new_resource.save()
        # test that the api call resolve_doi() returns the short_id of the resource when we pass the
        # resource doi in this api call
        self.assertEqual(new_resource.short_id,
                         hydroshare.resolve_doi(new_resource.doi))

        # test the exception 'Http404' is raised when we make the api call
        # passing a random doi ( e.g., '123') that does not exist
        with self.assertRaises(Http404):
            hydroshare.resolve_doi("123")
    def setUp(self):
        super(TestContentTypes, self).setUp()
        self.hydroshare_author_group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        # create a user to be used for creating the resource
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[]
        )

        self.res = hydroshare.create_resource(
            'CompositeResource',
            self.user,
            'My Test Resource'
        )

        # create empty files with appropriate extensions
        self.filenames = ['file.pdf', 'file.doc', 'file.ppt', 'file.csv', 'file.ipynb']
        self.content_types = ['Document', 'Document', 'Presentation', 'Spreadsheet',
                              'Jupyter Notebook']
        for f in self.filenames:
            test_file = open(f, 'w')
            test_file.close()

        # create empty files with non-conforming extensions
        self.weird_filenames = ['file.foo', 'file.bar']
        self.weird_extensions = ['foo', 'bar']
        for f in self.weird_filenames:
            test_file = open(f, 'w')
            test_file.close()
    def test_resolve_doi(self):
        self.user_creator = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[]
        )

        new_resource = hydroshare.create_resource(
            'GenericResource',
            self.user_creator,
            'My Test Resource'
        )

        # assign doi to the resource
        new_resource.doi = 'xyz'
        new_resource.save()
        # test that the api call resolve_doi() returns the short_id of the resource when we pass the
        # resource doi in this api call
        self.assertEqual(new_resource.short_id, hydroshare.resolve_doi(new_resource.doi))

        # test the exception 'Http404' is raised when we make the api call
        # passing a random doi ( e.g., '123') that does not exist
        with self.assertRaises(Http404):
            hydroshare.resolve_doi("123")
    def setUp(self):
        super(TestReplicateBagToUserZone, self).setUp()
        super(TestReplicateBagToUserZone,
              self).assert_federated_irods_available()

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.username = '******'
        self.password = '******'
        self.user = hydroshare.create_account('*****@*****.**',
                                              username=self.username,
                                              first_name='John',
                                              last_name='Clarson',
                                              superuser=False,
                                              password=self.password,
                                              groups=[])

        # create corresponding irods account in user zone
        super(TestReplicateBagToUserZone,
              self).create_irods_user_in_user_zone()

        self.gen_res = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.user,
            title='Generic Resource Key/Value Metadata Testing')

        self.factory = RequestFactory()
    def setUp(self):
        super(T12UserActive, self).setUp()

        global_reset()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.admin = hydroshare.create_account('*****@*****.**',
                                               username='******',
                                               first_name='administrator',
                                               last_name='couch',
                                               superuser=True,
                                               groups=[])

        self.cat = hydroshare.create_account('*****@*****.**',
                                             username='******',
                                             first_name='not a dog',
                                             last_name='last_name_cat',
                                             superuser=False,
                                             groups=[])

        self.dog = hydroshare.create_account('*****@*****.**',
                                             username='******',
                                             first_name='a little arfer',
                                             last_name='last_name_dog',
                                             superuser=False,
                                             groups=[])

        self.scratching = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.cat,
            title='all about sofas as scrathing posts',
            metadata=[],
        )

        self.felines = self.cat.uaccess.create_group(
            title='felines', description="We are the feliness")
Exemple #27
0
    def setUp(self):
        super(TestShareResource, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        self.owner = hydroshare.create_account('*****@*****.**',
                                               username='******',
                                               first_name='John',
                                               last_name='Clarson',
                                               superuser=False,
                                               password='******',
                                               groups=[])

        self.user = hydroshare.create_account('*****@*****.**',
                                              username='******',
                                              first_name='Lisa',
                                              last_name='Ziggler',
                                              superuser=False,
                                              password='******',
                                              groups=[])
        # crate a group for testing group access to resource
        self.test_group = self.owner.uaccess.create_group(
            title='Test Group',
            description="This is to test group access to resource",
            purpose="Testing group access to resource")

        self.gen_res = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.owner,
            title='Generic Resource Share Resource Testing')

        self.factory = RequestFactory()
Exemple #28
0
    def setUp(self):
        super(TestAddDeleteResourceFiles, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.username = '******'
        self.password = '******'
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username=self.username,
            first_name='John',
            last_name='Clarson',
            superuser=False,
            password=self.password,
            groups=[]
        )
        self.gen_res = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.user,
            title='Generic Resource Key/Value Metadata Testing'
        )

        # Make a text file
        self.txt_file_name_1 = 'text-1.txt'
        self.txt_file_path_1 = os.path.join(self.temp_dir, self.txt_file_name_1)
        txt = open(self.txt_file_path_1, 'w')
        txt.write("Hello World-1\n")
        txt.close()

        self.txt_file_name_2 = 'text-2.txt'
        self.txt_file_path_2 = os.path.join(self.temp_dir, self.txt_file_name_2)
        txt = open(self.txt_file_path_2, 'w')
        txt.write("Hello World-2\n")
        txt.close()
    def test_read_shp_xml(self):
        # test parsing shapefile xml metadata
        shp_xml_full_path = 'hs_geographic_feature_resource/tests/beaver_ponds_1940.shp.xml'
        metadata = geofeature.parse_shp_xml(shp_xml_full_path)
        resGeoFeature2 = hydroshare.create_resource(
            resource_type='GeographicFeatureResource',
            owner=self.user,
            title="",
            metadata=metadata
        )

        # test abstract
        self.assertIn("white aerial photographs taken in July 1940 by the U.S. "
                      "Department of Agriculture",
                      resGeoFeature2.metadata.description.abstract)

        # test title
        self.assertIn("beaver_ponds_1940",
                      resGeoFeature2.metadata.title.value)

        # test keywords
        self.assertEqual(resGeoFeature2.metadata.subjects.all().count(), 3)
        subject_list = [s.value for s in resGeoFeature2.metadata.subjects.all()]
        self.assertIn("beaver ponds", subject_list)
        self.assertIn("beaver meadows", subject_list)
        self.assertIn("Voyageurs National Park", subject_list)
        resGeoFeature2.delete()
    def test_move_to_folder_basic(self):
        group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        user = hydroshare.create_account('*****@*****.**',
                                         username='******',
                                         first_name='Creator_FirstName',
                                         last_name='Creator_LastName',
                                         superuser=False,
                                         groups=[])

        resource = hydroshare.create_resource(
            'GenericResource',
            user,
            'test resource',
        )

        resource.save()

        open('myfile.txt', "w").close()
        file = open('myfile.txt', 'rb')

        hydroshare.add_resource_files(resource.short_id, file)
        create_folder(resource.short_id, "data/contents/test_folder")

        move_to_folder(user,
                       resource.short_id,
                       src_paths=['data/contents/myfile.txt'],
                       tgt_path="data/contents/test_folder",
                       validate_move=True)

        folder_contents = list_folder(resource.short_id,
                                      "data/contents/test_folder")
        self.assertTrue(['myfile.txt'] in folder_contents)

        resource.delete()
Exemple #31
0
    def create_resource(self):
        if not get_user(self.request).is_authenticated():
            print self.request.user
            raise exceptions.PermissionDenied('user must be logged in.')

        params = utils.create_form(ResourceCRUD.CreateResourceForm,
                                   self.request)
        if params.is_valid():
            r = params.cleaned_data
            res = hydroshare.create_resource(
                resource_type=r['resource_type'],
                owner=self.request.user,
                title=r['title'],
                edit_users=r['edit_users'],
                view_users=r['view_users'],
                edit_groups=r['edit_groups'],
                view_groups=r['view_groups'],
                keywords=r['keywords'],
                dublin_metadata=json.loads(r['dublin_metadata'])
                if r['dublin_metadata'] else {},
                files=self.request.FILES.values(),
                **{
                    k: v
                    for k, v in self.request.REQUEST.items() if k not in r
                })
            return HttpResponse(res.short_id, content_type='text/plain')
        else:
            raise exceptions.ValidationError(params.errors)
    def setUp(self):
        super(TestResourceFileAPI, self).setUp()
        self.hydroshare_author_group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        # create a user to be used for creating the resource
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[]
        )

        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user,
            'My Test Resource'
        )

        # create a file
        self.test_file_name1 = 'file1.txt'
        self.file_name_list = [self.test_file_name1, ]

        # put predictable contents into these
        test_file = open(self.test_file_name1, 'w')
        test_file.write("Test text file in file1.txt")
        test_file.close()

        self.test_file_1 = open(self.test_file_name1, 'r')
    def setUp(self):
        self.serializer = Serializer()
        self.logger = logging.getLogger(__name__)

        self.api_client = Client()

        self.username = '******'
        self.password = '******'

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        # create a user to be used for creating the resource
        self.user_creator = hydroshare.create_account(
            '*****@*****.**',
            username=self.username,
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            password=self.password,
            groups=[self.group]
        )

        self.api_client.login(username=self.username, password=self.password)

                # create a resource
        self.resource = hydroshare.create_resource(
            resource_type='ToolResource',
            title='My resource',
            owner=self.user_creator,
        )
    def setUp(self):
        super(TestUpdateNetcdfFile, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.username = '******'
        self.password = '******'
        self.john = hydroshare.create_account(
            '*****@*****.**',
            username=self.username,
            first_name='John',
            last_name='Clarson',
            superuser=False,
            password=self.password,
            groups=[]
        )

        self.temp_dir = tempfile.mkdtemp()
        self.netcdf_file_name = 'netcdf_file_update.nc'
        self.netcdf_file = 'hs_app_netCDF/tests/{}'.format(self.netcdf_file_name)
        target_temp_netcdf_file = os.path.join(self.temp_dir, self.netcdf_file_name)
        shutil.copy(self.netcdf_file, target_temp_netcdf_file)
        self.netcdf_file_obj = open(target_temp_netcdf_file, 'r')

        self.genResource = hydroshare.create_resource(resource_type='GenericResource',
                                                      owner=self.john,
                                                      title='Test Resource',
                                                      metadata=[])

        self.factory = RequestFactory()
Exemple #35
0
    def setUp(self):
        self.logger = logging.getLogger(__name__)

        self.api_client = TestApiClient()

        self.username = "******"
        self.password = "******"

        # create a user to be used for creating the resource
        self.user_creator = hydroshare.create_account(
            "*****@*****.**",
            username=self.username,
            first_name="Creator_FirstName",
            last_name="Creator_LastName",
            superuser=False,
            password=self.password,
            groups=[],
        )
        self.user_url = "/hsapi/accounts/{0}/".format(self.user_creator.username)

        self.api_client.client.login(username=self.username, password=self.password)

        # create a resource
        self.resource = hydroshare.create_resource(
            resource_type="GenericResource",
            title="My resource",
            owner=self.user_creator,
            last_changed_by=self.user_creator,
        )
        self.resource_url_base = "/hsapi/resource/"
        self.resource_url = "{0}{1}/".format(self.resource_url_base, self.resource.short_id)

        self.post_data = {"title": "My REST API-created resource", "resource_type": "GenericResource"}
Exemple #36
0
    def setUp(self):
        super(NetCDFFileTypeMetaDataTest, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account('*****@*****.**',
                                              username='******',
                                              first_name='Creator_FirstName',
                                              last_name='Creator_LastName',
                                              superuser=False,
                                              groups=[self.group])

        self.composite_resource = hydroshare.create_resource(
            resource_type='CompositeResource',
            owner=self.user,
            title='Test NetCDF File Type Metadata')

        self.temp_dir = tempfile.mkdtemp()
        self.netcdf_file_name = 'netcdf_valid.nc'
        self.netcdf_file = 'hs_file_types/tests/{}'.format(
            self.netcdf_file_name)

        target_temp_netcdf_file = os.path.join(self.temp_dir,
                                               self.netcdf_file_name)
        shutil.copy(self.netcdf_file, target_temp_netcdf_file)
        self.netcdf_file_obj = open(target_temp_netcdf_file, 'r')

        self.netcdf_invalid_file_name = 'netcdf_invalid.nc'
        self.netcdf_invalid_file = 'hs_file_types/tests/{}'.format(
            self.netcdf_invalid_file_name)

        target_temp_netcdf_invalid_file = os.path.join(
            self.temp_dir, self.netcdf_invalid_file_name)
        shutil.copy(self.netcdf_invalid_file, target_temp_netcdf_invalid_file)
    def setUp(self):
        super(TestChangeQuotaHolder, self).setUp()
        self.hs_group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        # create two users
        self.user1 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='owner1_first_name',
            last_name='owner1_last_name',
            superuser=False,
            groups=[self.hs_group]
        )
        self.user2 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='owner2_first_name',
            last_name='owner2_last_name',
            superuser=False,
            groups=[self.hs_group]
        )

        self.res = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.user1,
            title='My Test Resource'
        )
        # test to make sure one owner can transfer quota holder to another owner
        self.user1.uaccess.share_resource_with_user(self.res, self.user2, PrivilegeCodes.OWNER)
    def setUp(self):
        self.serializer = Serializer()
        self.logger = logging.getLogger(__name__)

        self.api_client = Client()

        self.username = '******'
        self.password = '******'

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        # create a user to be used for creating the resource
        self.user_creator = hydroshare.create_account(
            '*****@*****.**',
            username=self.username,
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            password=self.password,
            groups=[self.group]
        )

        self.api_client.login(username=self.username, password=self.password)

                # create a resource
        self.resource = hydroshare.create_resource(
            resource_type='ToolResource',
            title='My resource',
            owner=self.user_creator,
        )
        self.url1 = 'www.one.com'
        self.url2 = 'www.two.com'
        self.res1 = 'res_type1'
        self.res2 = 'res_type2'
        self.desc1 = 'description1'
        self.desc2 = 'description2'
        self.fee1 = Decimal('1')
        self.fee2 = Decimal('2')
        self.version1 = '1'
        self.version2 = '2'
        hydroshare.resource.create_metadata_element(self.resource.short_id,
                                                    'RequestUrlBase',
                                                    value=self.url1
                                                    )

        hydroshare.resource.create_metadata_element(self.resource.short_id,
                                                    'ToolResourceType',
                                                    tool_res_type=self.res1
                                                    )

        hydroshare.resource.create_metadata_element(self.resource.short_id,
                                                    'Fee',
                                                    description=self.desc1,
                                                    value=self.fee1
                                                    )

        hydroshare.resource.create_metadata_element(self.resource.short_id,
                                                    'ToolVersion',
                                                    value=self.version1
                                                    )
Exemple #39
0
    def setUp(self):
        # create two users
        self.user1 = hydroshare.create_account('*****@*****.**',
                                               username='******',
                                               first_name='Creator_FirstName',
                                               last_name='Creator_LastName',
                                               superuser=False,
                                               groups=[])

        self.user2 = hydroshare.create_account('*****@*****.**',
                                               username='******',
                                               first_name='Creator2_FirstName',
                                               last_name='Creator2_LastName',
                                               superuser=False,
                                               groups=[])

        # create a group
        self.group = hydroshare.create_group('Test group',
                                             members=[],
                                             owners=[self.user1])

        # create a resource
        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user1,
            'Test Resource',
            #edit_groups=[self.group],
            edit_users=[self.user1, self.user2])
    def test_extra_tif_with_vrt_upload(self):
        # test that when a vrt file is uploaded, all tif files referenced in vrt must be uploaded
        # and no extra file can be uploaded, otherwise file validation fails

        tif_1 = UploadedFile(file=open(self.logan_tif_1_file, 'r'),
                             name=self.logan_tif_1_file_name)
        tif_2 = UploadedFile(file=open(self.logan_tif_2_file, 'r'),
                             name=self.logan_tif_2_file_name)
        extra_tif = UploadedFile(file=self.raster_tif_file_obj, name=self.raster_tif_file_name)
        vrt = UploadedFile(file=open(self.logan_vrt_file, 'r'),
                           name=self.logan_vrt_file_name)

        files = [tif_1, tif_2, extra_tif, vrt]

        self.resRaster = hydroshare.create_resource(
            'RasterResource',
            self.user,
            'My Test Raster Resource Coverage',
            files=files,
            metadata=[]
        )

        # uploaded file validation and metadata extraction happens in post resource
        # creation handler - which should raise validation exception
        with self.assertRaises(utils.ResourceFileValidationException):
            utils.resource_post_create_actions(resource=self.resRaster, user=self.user, metadata=[])
        # resource should not have any files
        self.assertEqual(self.resRaster.files.all().count(), 0)
Exemple #41
0
    def setUp(self):
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Shawn',
            last_name='Crawley',
            superuser=False,
            groups=[self.group]
        )
        self.user.set_password('password')
        self.user.save()
        profile = self.user.userprofile
        profile_data = {
            'country': 'USA',
        }
        for field in profile_data:
            setattr(profile, field, profile_data[field])
        profile.save()
        self.visitor = Visitor.objects.create()
        self.session = Session.objects.create(visitor=self.visitor)

        self.resWebApp = hydroshare.create_resource(
            resource_type='ToolResource',
            owner=self.user,
            title='Test Web App Resource',
            keywords=['kw1', 'kw2'])
Exemple #42
0
    def test_read_shp_xml(self):
        # test parsing shapefile xml metadata
        shp_xml_full_path = 'hs_geographic_feature_resource/tests/beaver_ponds_1940.shp.xml'
        metadata = geofeature.parse_shp_xml(shp_xml_full_path)
        resGeoFeature2 = hydroshare.create_resource(
            resource_type='GeographicFeatureResource',
            owner=self.user,
            title="",
            metadata=metadata
        )

        # test abstract
        self.assertIn("white aerial photographs taken in July 1940 by the U.S. "
                      "Department of Agriculture",
                      resGeoFeature2.metadata.description.abstract)

        # test title
        self.assertIn("beaver_ponds_1940",
                      resGeoFeature2.metadata.title.value)

        # test keywords
        self.assertEqual(resGeoFeature2.metadata.subjects.all().count(), 3)
        subject_list = [s.value for s in resGeoFeature2.metadata.subjects.all()]
        self.assertIn("beaver ponds", subject_list)
        self.assertIn("beaver meadows", subject_list)
        self.assertIn("Voyageurs National Park", subject_list)
        resGeoFeature2.delete()
Exemple #43
0
    def setUp(self):
        super(TestUpdateNetcdfFile, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.username = '******'
        self.password = '******'
        self.john = hydroshare.create_account('*****@*****.**',
                                              username=self.username,
                                              first_name='John',
                                              last_name='Clarson',
                                              superuser=False,
                                              password=self.password,
                                              groups=[])

        self.temp_dir = tempfile.mkdtemp()
        self.netcdf_file_name = 'netcdf_file_update.nc'
        self.netcdf_file = 'hs_app_netCDF/tests/{}'.format(
            self.netcdf_file_name)
        target_temp_netcdf_file = os.path.join(self.temp_dir,
                                               self.netcdf_file_name)
        shutil.copy(self.netcdf_file, target_temp_netcdf_file)
        self.netcdf_file_obj = open(target_temp_netcdf_file, 'r')

        self.genResource = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.john,
            title='Test Resource',
            metadata=[])

        self.factory = RequestFactory()
    def setUp(self):
        super(TestResourceFileAPI, self).setUp()
        self.hydroshare_author_group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        # create a user to be used for creating the resource
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[]
        )

        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user,
            'My Test Resource'
        )

        # create a file
        self.test_file_name1 = 'file1.txt'
        self.file_name_list = [self.test_file_name1, ]

        # put predictable contents into these
        test_file = open(self.test_file_name1, 'w')
        test_file.write("Test text file in file1.txt")
        test_file.close()

        self.test_file_1 = open(self.test_file_name1, 'rb')
    def test_resource_file_put(self):

        myfile = open(self.filename, 'w')
        myfile.write('hello world!\n')
        myfile.close()
        myfile = open(self.filename, 'r')

        res1 = hydroshare.create_resource('GenericResource', self.user, 'res1')

        hydroshare.add_resource_files(res1.short_id, myfile)

        mynewfile = open(self.filename, 'w')
        mynewfile.write('anyone there?\n')
        mynewfile.close()
        mynewfile = open(self.filename, 'r')

        url = self.url_proto.format(res1.short_id, self.filename)

        put_data = { 'resource_file': mynewfile
        }

        resp = self.api_client.put(url, data=put_data)
        self.assertHttpAccepted(resp)

        resp = self.api_client.get(url)
        self.assertIn(resp.status_code, [201, 200])
Exemple #46
0
    def _test_delete_optional_file(self, file_extension):
        # test that deleting the optional file with the specified extension *file_extension*
        # deletes only that file

        self.resGeoFeature = hydroshare.create_resource(
            resource_type='GeographicFeatureResource',
            owner=self.user,
            title='Test Geographic Feature (shapefiles)'
        )
        # check that the resource has no files
        self.assertEqual(self.resGeoFeature.files.count(), 0)

        # add files first
        files = []
        target = 'hs_geographic_feature_resource/tests/gis.osm_adminareas_v06_all_files.zip'
        files.append(UploadedFile(file=open(target, 'r'),
                                  name='gis.osm_adminareas_v06_all_files.zip'))
        hydroshare.utils.resource_file_add_process(self.resGeoFeature, files, self.user, )

        # check that the resource has 15 files
        self.assertEqual(self.resGeoFeature.files.count(), 15)

        # find the .shp file and delete it
        for f in self.resGeoFeature.files.all():
            if f.extension == file_extension:
                hydroshare.delete_resource_file(self.resGeoFeature.short_id, f.id, self.user)
                break
        # resource should have 14 files
        self.assertEqual(self.resGeoFeature.files.count(), 14)
        self.resGeoFeature.delete()
 def setUp(self):
     self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
     self.user = hydroshare.create_account(
             '*****@*****.**',
             username='******',
             first_name='Creator_FirstName',
             last_name='Creator_LastName',
             superuser=False,
             groups=[self.group]
         )
     self.refts_res = hydroshare.create_resource(
             resource_type='RefTimeSeries',
             owner=self.user,
             title='Test RefTS resource')
     resource.create_metadata_element(self.refts_res.short_id, 'QualityControlLevel', value='test quality level')
     resource.create_metadata_element(self.refts_res.short_id, 'ReferenceURL', value='www.example.com', type='REST')
     resource.create_metadata_element(self.refts_res.short_id, 'Method', value='test method')
     resource.create_metadata_element(
             self.refts_res.short_id,
             'Variable',
             name='test variable name',
             code='test code',
             data_type='test data type',
             sample_medium='test sample medium')
     resource.create_metadata_element(
             self.refts_res.short_id,
             'Site',
             name='test site name',
             code='test site code',
             latitude=150.15,
             longitude=150.15)
    def test_move_to_folder_basic(self):
        group, _ = Group.objects.get_or_create(name='Hydroshare Author')

        user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[]
        )

        resource = hydroshare.create_resource(
            'GenericResource',
            user,
            'test resource',
        )

        resource.save()

        open('myfile.txt', "w").close()
        file = open('myfile.txt', 'r')

        hydroshare.add_resource_files(resource.short_id, file)
        create_folder(resource.short_id, "data/contents/test_folder")

        move_to_folder(user, resource.short_id,
                       src_paths=['data/contents/myfile.txt'],
                       tgt_path="data/contents/test_folder",
                       validate_move=True)

        folder_contents = list_folder(resource.short_id, "data/contents/test_folder")
        self.assertTrue(['myfile.txt'] in folder_contents)

        resource.delete()
    def test_multiple_tif_file_with_vrt_upload(self):
        # test that multiple tif files along with a vrt file can be uploaded and
        # be successful with file validation

        tif_1 = UploadedFile(file=open(self.logan_tif_1_file, 'r'),
                             name=self.logan_tif_1_file_name)
        tif_2 = UploadedFile(file=open(self.logan_tif_2_file, 'r'),
                             name=self.logan_tif_2_file_name)
        vrt = UploadedFile(file=open(self.logan_vrt_file, 'r'),
                           name=self.logan_vrt_file_name)
        files = [tif_1, tif_2, vrt]

        self.resRaster = hydroshare.create_resource(
            'RasterResource',
            self.user,
            'My Test Raster Resource Coverage',
            files=files,
            metadata=[]
        )

        # uploaded file validation and metadata extraction happens in post resource
        # creation handler
        utils.resource_post_create_actions(resource=self.resRaster, user=self.user, metadata=[])
        # if the 3 files are in resource, assume file validation successful
        self.assertEqual(self.resRaster.files.all().count(), 3)
    def setUp(self):
        super(TestTickets, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[]
        )

        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user,
            'test resource',
        )

        # create a file
        self.test_file_name1 = 'file1.txt'
        self.file_name_list = [self.test_file_name1, ]

        # put predictable contents into the file
        test_file = open(self.test_file_name1, 'w')
        test_file.write("Test text file in file1.txt")
        test_file.close()

        self.test_file_1 = open(self.test_file_name1, 'r')

        # add one file to the resource: necessary so data/contents is created.
        hydroshare.add_resource_files(self.res.short_id, self.test_file_1)
Exemple #51
0
    def setUp(self):
        super(TestModelProgramMetaData, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account('*****@*****.**',
                                              username='******',
                                              first_name='Creator_FirstName',
                                              last_name='Creator_LastName',
                                              superuser=False,
                                              groups=[self.group])

        self.resModelProgram = hydroshare.create_resource(
            resource_type='ModelProgramResource',
            owner=self.user,
            title='Test Model Program Resource')

        self.temp_dir = tempfile.mkdtemp()

        self.file_name = "MP.txt"
        temp_text_file = os.path.join(self.temp_dir, self.file_name)
        text_file = open(temp_text_file, 'w')
        text_file.write("Model Program resource files")
        text_file.close()
        self.text_file_obj = open(temp_text_file, 'rb')

        self.file_name_2 = "MP.csv"
        temp_text_file_2 = os.path.join(self.temp_dir, self.file_name_2)
        text_file = open(temp_text_file_2, 'w')
        text_file.write("Model,Program,resource,file")
        text_file.close()
        self.text_file_obj_2 = open(temp_text_file_2, 'rb')
    def setUp(self):
        super(TestModelProgramMetaData, self).setUp()
        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[self.group]
        )

        self.resModelProgram = hydroshare.create_resource(
            resource_type='ModelProgramResource',
            owner=self.user,
            title='Test Model Program Resource'
        )

        self.temp_dir = tempfile.mkdtemp()

        self.file_name = "MP.txt"
        temp_text_file = os.path.join(self.temp_dir, self.file_name)
        text_file = open(temp_text_file, 'w')
        text_file.write("Model Program resource files")
        text_file.close()
        self.text_file_obj = open(temp_text_file, 'r')

        self.file_name_2 = "MP.csv"
        temp_text_file_2 = os.path.join(self.temp_dir, self.file_name_2)
        text_file = open(temp_text_file_2, 'w')
        text_file.write("Model,Program,resource,file")
        text_file.close()
        self.text_file_obj_2 = open(temp_text_file_2, 'r')
    def setUp(self):
        super(TestReplicateBagToUserZone, self).setUp()
        super(TestReplicateBagToUserZone, self).assert_federated_irods_available()

        self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        self.username = '******'
        self.password = '******'
        self.user = hydroshare.create_account(
            '*****@*****.**',
            username=self.username,
            first_name='John',
            last_name='Clarson',
            superuser=False,
            password=self.password,
            groups=[]
        )

        # create corresponding irods account in user zone
        super(TestReplicateBagToUserZone, self).create_irods_user_in_user_zone()

        self.gen_res = hydroshare.create_resource(
            resource_type='GenericResource',
            owner=self.user,
            title='Generic Resource Key/Value Metadata Testing'
        )

        self.factory = RequestFactory()
Exemple #54
0
    def test_resource_file_put(self):

        myfile = open(self.filename, 'w')
        myfile.write('hello world!\n')
        myfile.close()
        myfile = open(self.filename, 'r')

        res1 = hydroshare.create_resource('GenericResource', self.user, 'res1')

        hydroshare.add_resource_files(res1.short_id, myfile)

        mynewfile = open(self.filename, 'w')
        mynewfile.write('anyone there?\n')
        mynewfile.close()
        mynewfile = open(self.filename, 'r')

        url = self.url_proto.format(res1.short_id, self.filename)

        put_data = {'resource_file': mynewfile}

        resp = self.api_client.put(url, data=put_data)
        self.assertHttpAccepted(resp)

        resp = self.api_client.get(url)
        self.assertIn(resp.status_code, [201, 200])
Exemple #55
0
def create_ref_time_series(request, *args, **kwargs):
    url = ts['url']
    reference_type = ts['ref_type']
    frm = CreateRefTimeSeriesForm(request.POST)
    if frm.is_valid():
        site_name, site_code, variable_name, variable_code = None, None, None, None
        metadata = frm.cleaned_data.get('metadata')
        metadata = ast.literal_eval(metadata)
        res = hydroshare.create_resource(
            resource_type='RefTimeSeries',
            owner=request.user,
            title=frm.cleaned_data.get('title'),
            metadata=metadata
        )

        hydroshare.resource.create_metadata_element(
            res.short_id,
            'QualityControlLevel',
            value=ts['QClevel'],
            )

        hydroshare.resource.create_metadata_element(
            res.short_id,
            'Method',
            value=ts['method'],
            )

        hydroshare.resource.create_metadata_element(
            res.short_id,
            'ReferenceURL',
            value=url,
            type=reference_type
        )

        hydroshare.resource.create_metadata_element(
            res.short_id,
            'Site',
            name=ts['site_name'],
            code=ts['site_code'],
            latitude=ts['latitude'],
            longitude=ts['longitude']
        )

        hydroshare.resource.create_metadata_element(
            res.short_id,
            'Variable',
            name=ts['variable_name'],
            code=ts['variable_code'],
            sample_medium=ts.get('sample_medium', 'unknown')
        )

        ts_utils.generate_files(res.short_id,ts)

        for file_name in os.listdir("theme/static/img"):
            if 'visualization' in file_name:
                # open(file_name, 'w')
                os.remove("theme/static/img/"+file_name)

        return HttpResponseRedirect(res.get_absolute_url())
    def test_generic(self):
        user = hydroshare.create_account(email='*****@*****.**', username='******', first_name='shaun',
                                         last_name='livingston', superuser=False, groups=[self.group])
        res1 = hydroshare.create_resource('GenericResource', user, 'Test Resource')

        # this is the api call we are testing
        extras = hydroshare.get_capabilities(res1.short_id)
        self.assertIsNone(extras)
    def create(self, request, *args, **kwargs):
        if not request.user.is_authenticated():
            raise NotAuthenticated()

        resource_create_request_validator = serializers.ResourceCreateRequestValidator(data=request.data)
        if not resource_create_request_validator.is_valid():
            raise ValidationError(detail=resource_create_request_validator.errors)

        validated_request_data = resource_create_request_validator.validated_data
        resource_type = validated_request_data["resource_type"]

        res_title = validated_request_data.get("title", "Untitled resource")
        keywords = validated_request_data.get("keywords", None)
        abstract = validated_request_data.get("abstract", None)

        num_files = len(request.FILES)
        if num_files > 0:
            if num_files > 1:
                raise ValidationError(
                    detail={
                        "file": "Multiple file upload is not allowed on resource creation. Add additional files after the resource is created."
                    }
                )
            # Place files into format expected by hydroshare.utils.resource_pre_create_actions and
            # hydroshare.create_resource, i.e. a tuple of django.core.files.uploadedfile.TemporaryUploadedFile objects.
            files = (request.FILES["file"],)
        else:
            files = ()

        _, res_title, metadata = hydroshare.utils.resource_pre_create_actions(
            resource_type=resource_type,
            resource_title=res_title,
            page_redirect_url_key=None,
            files=files,
            metadata=None,
            **kwargs
        )
        try:
            resource = hydroshare.create_resource(
                resource_type=resource_type,
                owner=request.user,
                title=res_title,
                edit_users=validated_request_data.get("edit_users", None),
                view_users=validated_request_data.get("view_users", None),
                edit_groups=validated_request_data.get("edit_groups", None),
                view_groups=validated_request_data.get("view_groups", None),
                keywords=keywords,
                metadata=metadata,
                files=files,
            )
            if abstract:
                resource.metadata.create_element("description", abstract=abstract)
        except Exception as ex:
            error_msg = {"resource": "Resource creation failed. %s" % ex.message}
            raise ValidationError(detail=error_msg)

        response_data = {"resource_type": resource_type, "resource_id": resource.short_id}
        return Response(data=response_data, status=status.HTTP_201_CREATED)