예제 #1
0
def test_pyfs_copy(pyfs, dummy_location):
    """Test send file."""
    s = PyFSFileStorage(join(dummy_location.uri, 'anotherpath/data'))
    s.save(BytesIO(b'otherdata'))

    pyfs.copy(s)
    fp = pyfs.open()
    assert fp.read() == b'otherdata'
예제 #2
0
def test_pyfs_copy(pyfs, dummy_location):
    """Test send file."""
    s = PyFSFileStorage(join(dummy_location.uri, 'anotherpath/data'))
    s.save(BytesIO(b'otherdata'))

    pyfs.copy(s)
    fp = pyfs.open()
    assert fp.read() == b'otherdata'
예제 #3
0
파일: rest.py 프로젝트: weko3-dev15/weko
    def put(self, **kwargs):
        """Create a uuid and return a links dict. file upload step is below ②
        upload file to server.

        :returns: Json Response have a links dict.
        """
        fn = request.view_args['key']

        # if ".xsd" not in fn:
        #     abort(405, "Xsd File only !!")

        pid = request.view_args['pid_value']
        furl = self.xsd_location_folder + 'tmp/' + pid + '/' + fn
        # size = len(request.data)

        try:
            fs = PyFSFileStorage(furl)
            fileurl, bytes_written, checksum = fs.save(request.stream)
        except Exception:
            raise InvalidDataRESTError()
        else:
            pass

        jd = {
            'key': fn,
            'mimetype': request.mimetype,
            'links': {},
            'size': bytes_written
        }
        data = dict(key=fn, mimetype='text/plain')
        response = current_app.response_class(json.dumps(jd),
                                              mimetype='application/json')
        response.status_code = 200
        return response
예제 #4
0
def test_copy(s3_bucket, s3fs):
    """Test copy file."""
    data = b'test'
    s3fs.save(BytesIO(data))

    s3_copy_path = 's3://{}/path/to/copy/data'.format(s3_bucket.name)
    s3fs_copy = S3FSFileStorage(s3_copy_path)
    s3fs_copy.copy(s3fs)

    assert s3fs_copy.open().read() == data

    tmppath = tempfile.mkdtemp()

    s = PyFSFileStorage(os.path.join(tmppath, 'anotherpath/data'))
    data = b'othertest'
    s.save(BytesIO(data))
    s3fs_copy.copy(s)
    assert s3fs_copy.open().read() == data

    shutil.rmtree(tmppath)