def test_save_dir(self): fu = FileUpload(open(__file__, 'rb'), 'testfile', __file__) dirpath = tempfile.mkdtemp() filepath = os.path.join(dirpath, fu.filename) fu.save(dirpath) self.assertEqual(fu.file.read(), open(filepath, 'rb').read()) os.unlink(filepath) os.rmdir(dirpath)
def test_save_dir(self): fu = FileUpload(open(__file__, 'rb'), 'testfile', __file__) dirpath = tempfile.mkdtemp() filepath = os.path.join(dirpath, fu.filename) fu.save(dirpath) self.assertEqual(fu.file.read(), open(filepath, 'rb').read()) os.unlink(filepath) os.rmdir(dirpath)
def _upload_to_path(body, headers, path): file_saver = FileUpload(body, None, filename=os.path.basename(path), headers=headers) if os.path.exists(path): os.unlink(path) if not os.path.exists(os.path.dirname(path)): mkdir(os.path.dirname(path)) file_saver.save(os.path.dirname(path))
def test_save_file(self): fu = FileUpload(open(__file__, 'rb'), 'testfile', __file__) buff = tempfile.TemporaryFile() fu.save(buff) buff.seek(0) self.assertEqual(fu.file.read(), buff.read())
def test_save_buffer(self): fu = FileUpload(open(__file__, 'rb'), 'testfile', __file__) buff = BytesIO() fu.save(buff) buff.seek(0) self.assertEqual(fu.file.read(), buff.read())
def test_save_file(self): fu = FileUpload(open(__file__, 'rb'), 'testfile', __file__) buff = tempfile.TemporaryFile() fu.save(buff) buff.seek(0) self.assertEqual(fu.file.read(), buff.read())
def test_save_buffer(self): fu = FileUpload(open(__file__, 'rb'), 'testfile', __file__) buff = BytesIO() fu.save(buff) buff.seek(0) self.assertEqual(fu.file.read(), buff.read())