Exemplo n.º 1
0
    def test_create_resource(self):
        # here we are testing the create_resource view function

        # test with no file upload
        post_data = {
            'resource-type': 'CompositeResource',
            'title': 'Test Composite Resource Creation',
            'irods_federated': 'false'
        }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(
            BaseResource.objects.filter(short_id=res_id).exists(), True)
        hydroshare.delete_resource(res_id)
        self.assertEqual(BaseResource.objects.count(), 0)

        # test with file upload

        # at this point there should not be any resource file
        self.assertEqual(ResourceFile.objects.count(), 0)
        # at this point there should not be any generic logical file
        self.assertEqual(GenericLogicalFile.objects.count(), 0)
        post_data = {
            'resource-type': 'CompositeResource',
            'title': 'Test Composite Resource Creation',
            'irods_federated': 'false',
            'files':
            (self.txt_file_name, open(self.txt_file_path), 'text/plain')
        }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        self.assertEqual(json_content['file_upload_status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(
            BaseResource.objects.filter(short_id=res_id).exists(), True)
        # at this point there should 1 resource file
        self.assertEqual(ResourceFile.objects.count(), 1)
        # at this point there should not be any generic logical file as we not more
        # by default making any uploaded file as part of generic logical file
        self.assertEqual(GenericLogicalFile.objects.count(), 0)

        hydroshare.delete_resource(res_id)
Exemplo n.º 2
0
    def test_create_resource(self):
        # here we are testing the create_resource view function

        # test with no file upload
        post_data = {
            'resource-type': 'TimeSeriesResource',
            'title': 'Test Time Series Resource Creation',
            'irods_federated': 'true'
        }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(
            BaseResource.objects.filter(short_id=res_id).exists(), True)
        hydroshare.delete_resource(res_id)
        self.assertEqual(BaseResource.objects.count(), 0)

        # test with file upload
        self.assertEqual(ResourceFile.objects.count(), 0)
        post_data = {
            'resource-type': 'TimeSeriesResource',
            'title': 'Test Time Series Resource Creation',
            'irods_federated': 'true',
            'files': (self.odm2_sqlite_file_name, open(self.odm2_sqlite_file))
        }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        self.assertEqual(json_content['file_upload_status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(
            BaseResource.objects.filter(short_id=res_id).exists(), True)
        self.assertEqual(ResourceFile.objects.count(), 1)
        ts_resource = BaseResource.objects.filter(short_id=res_id).first()
        # check that the resource title got updated due to metadata extraction as part of resource
        # creation
        self.assertEqual(
            ts_resource.metadata.title.value,
            "Water temperature data from the Little Bear River, UT")
        hydroshare.delete_resource(res_id)
    def test_create_resource(self):
        # here we are testing the create_resource view function

        # test with no file upload
        post_data = {'resource-type': 'CompositeResource',
                     'title': 'Test Composite Resource Creation',
                     'irods_federated': 'false'
                     }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(BaseResource.objects.filter(short_id=res_id).exists(), True)
        hydroshare.delete_resource(res_id)
        self.assertEqual(BaseResource.objects.count(), 0)

        # test with file upload

        # at this point there should not be any resource file
        self.assertEqual(ResourceFile.objects.count(), 0)
        # at this point there should not be any generic logical file
        self.assertEqual(GenericLogicalFile.objects.count(), 0)
        post_data = {'resource-type': 'CompositeResource',
                     'title': 'Test Composite Resource Creation',
                     'irods_federated': 'false',
                     'files': (self.txt_file_name, open(self.txt_file_path), 'text/plain')
                     }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        self.assertEqual(json_content['file_upload_status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(BaseResource.objects.filter(short_id=res_id).exists(), True)
        # at this point there should 1 resource file
        self.assertEqual(ResourceFile.objects.count(), 1)
        # at this point there should not be any generic logical file as we not more
        # by default making any uploaded file as part of generic logical file
        self.assertEqual(GenericLogicalFile.objects.count(), 0)

        hydroshare.delete_resource(res_id)
Exemplo n.º 4
0
    def test_create_resource(self):
        # here we are testing the create_resource view function

        # test with no file upload
        post_data = {
            'resource-type': 'GenericResource',
            'title': 'Test Generic Resource Creation',
            'irods_federated': 'true'
        }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user

        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(
            BaseResource.objects.filter(short_id=res_id).exists(), True)
        hydroshare.delete_resource(res_id)
        self.assertEqual(BaseResource.objects.count(), 0)

        # test with file upload
        self.assertEqual(ResourceFile.objects.count(), 0)
        post_data = {
            'resource-type': 'GenericResource',
            'title': 'Test Generic Resource Creation',
            'irods_federated': 'true',
            'files':
            (self.txt_file_name, open(self.txt_file_path), 'text/plain')
        }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        self.assertEqual(json_content['file_upload_status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(
            BaseResource.objects.filter(short_id=res_id).exists(), True)
        self.assertEqual(ResourceFile.objects.count(), 1)
        hydroshare.delete_resource(res_id)
    def test_create_resource(self):
        # here we are testing the create_resource view function

        # test with no file upload
        post_data = {'resource-type': 'TimeSeriesResource',
                     'title': 'Test Time Series Resource Creation',
                     'irods_federated': 'true'
                     }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(BaseResource.objects.filter(short_id=res_id).exists(), True)
        hydroshare.delete_resource(res_id)
        self.assertEqual(BaseResource.objects.count(), 0)

        # test with file upload
        self.assertEqual(ResourceFile.objects.count(), 0)
        post_data = {'resource-type': 'TimeSeriesResource',
                     'title': 'Test Time Series Resource Creation',
                     'irods_federated': 'true',
                     'files': (self.odm2_sqlite_file_name, open(self.odm2_sqlite_file))
                     }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        self.assertEqual(json_content['file_upload_status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(BaseResource.objects.filter(short_id=res_id).exists(), True)
        self.assertEqual(ResourceFile.objects.count(), 1)
        ts_resource = BaseResource.objects.filter(short_id=res_id).first()
        # check that the resource title got updated due to metadata extraction as part of resource
        # creation
        self.assertEqual(ts_resource.metadata.title.value,
                         "Water temperature data from the Little Bear River, UT")
        hydroshare.delete_resource(res_id)
    def test_create_resource_with_invalid_file(self):
        # here we are testing the create_resource view function

        self.assertEqual(BaseResource.objects.count(), 0)
        self.assertEqual(ResourceFile.objects.count(), 0)
        # test with bad sqlite file - this file should not be uploaded
        post_data = {'resource-type': 'TimeSeriesResource',
                     'title': 'Test Time Series Resource Creation',
                     'irods_federated': 'true',
                     'files': (self.odm2_sqlite_invalid_file_name,
                               open(self.odm2_sqlite_invalid_file))
                     }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        self.assertEqual(json_content['file_upload_status'], 'error')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(BaseResource.objects.filter(short_id=res_id).exists(), True)
        # that bad sqlite file was not uploaded
        self.assertEqual(ResourceFile.objects.count(), 0)
        hydroshare.delete_resource(res_id)
Exemplo n.º 7
0
    def test_create_resource_with_invalid_file(self):
        # here we are testing the create_resource view function

        self.assertEqual(BaseResource.objects.count(), 0)
        self.assertEqual(ResourceFile.objects.count(), 0)
        # test with bad sqlite file - this file should not be uploaded
        post_data = {
            'resource-type':
            'TimeSeriesResource',
            'title':
            'Test Time Series Resource Creation',
            'irods_federated':
            'true',
            'files': (self.odm2_sqlite_invalid_file_name,
                      open(self.odm2_sqlite_invalid_file))
        }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        self.assertEqual(json_content['file_upload_status'], 'error')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(
            BaseResource.objects.filter(short_id=res_id).exists(), True)
        # that bad sqlite file was not uploaded
        self.assertEqual(ResourceFile.objects.count(), 0)
        hydroshare.delete_resource(res_id)
    def test_create_resource_with_invalid_file(self):
        # here we are testing the create_resource view function

        self.assertEqual(BaseResource.objects.count(), 0)
        self.assertEqual(ResourceFile.objects.count(), 0)
        # test with bad nc file - this file should not be uploaded and the resource
        # is also not created
        post_data = {
            'resource-type': 'NetcdfResource',
            'title': 'Test NetCDF Resource Creation',
            'irods_federated': 'false',
            'files': (self.netcdf_bad_file_name, open(self.netcdf_bad_file))
        }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')

        self.assertEqual(BaseResource.objects.count(), 1)
Exemplo n.º 9
0
    def test_create_resource(self):
        # here we are testing the create_resource view function

        # test with no file upload
        post_data = {'resource-type': 'GenericResource',
                     'title': 'Test Generic Resource Creation',
                     'irods_federated': 'true'
                     }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user

        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(BaseResource.objects.filter(short_id=res_id).exists(), True)
        hydroshare.delete_resource(res_id)
        self.assertEqual(BaseResource.objects.count(), 0)

        # test with file upload
        self.assertEqual(ResourceFile.objects.count(), 0)
        post_data = {'resource-type': 'GenericResource',
                     'title': 'Test Generic Resource Creation',
                     'irods_federated': 'true',
                     'files': (self.txt_file_name, open(self.txt_file_path), 'text/plain')
                     }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'success')
        self.assertEqual(json_content['file_upload_status'], 'success')
        res_id = json_content['resource_url'].split('/')[2]
        self.assertEqual(BaseResource.objects.filter(short_id=res_id).exists(), True)
        self.assertEqual(ResourceFile.objects.count(), 1)
        hydroshare.delete_resource(res_id)
Exemplo n.º 10
0
    def test_create_resource_failure(self):
        # here we are testing the create_resource view function

        self.assertEqual(BaseResource.objects.count(), 0)
        # test with non-existing resource type
        post_data = {'resource-type': 'BadResourceType',
                     'title': 'Test Generic Resource Creation',
                     'irods_federated': 'true'
                     }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'error')
        self.assertEqual(BaseResource.objects.count(), 0)
Exemplo n.º 11
0
    def test_create_resource_failure(self):
        # here we are testing the create_resource view function

        self.assertEqual(BaseResource.objects.count(), 0)
        # test with non-existing resource type
        post_data = {
            'resource-type': 'BadResourceType',
            'title': 'Test Generic Resource Creation',
            'irods_federated': 'true'
        }
        url = reverse('create_resource')
        request = self.factory.post(url, data=post_data)
        request.user = self.user
        self.set_request_message_attributes(request)
        self.add_session_to_request(request)

        response = create_resource(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_content = json.loads(response.content)
        self.assertEqual(json_content['status'], 'error')
        self.assertEqual(BaseResource.objects.count(), 0)