def test_media_io_base_upload_from_file_object(self): f = open(datafile("small.png"), "r") upload = MediaIoBaseUpload(fh=f, mimetype="image/png", chunksize=500, resumable=True) self.assertEqual("image/png", upload.mimetype()) self.assertEqual(190, upload.size()) self.assertEqual(True, upload.resumable()) self.assertEqual(500, upload.chunksize()) self.assertEqual("PNG", upload.getbytes(1, 3)) f.close()
def test_media_io_base_upload_from_file_object(self): f = open(datafile('small.png'), 'r') upload = MediaIoBaseUpload( fd=f, mimetype='image/png', chunksize=500, resumable=True) self.assertEqual('image/png', upload.mimetype()) self.assertEqual(190, upload.size()) self.assertEqual(True, upload.resumable()) self.assertEqual(500, upload.chunksize()) self.assertEqual('PNG', upload.getbytes(1, 3)) f.close()
def test_media_io_base_upload_from_string_io(self): f = open(datafile("small.png"), "r") fh = StringIO.StringIO(f.read()) f.close() upload = MediaIoBaseUpload(fh=fh, mimetype="image/png", chunksize=500, resumable=True) self.assertEqual("image/png", upload.mimetype()) self.assertEqual(None, upload.size()) self.assertEqual(True, upload.resumable()) self.assertEqual(500, upload.chunksize()) self.assertEqual("PNG", upload.getbytes(1, 3)) f.close()
def test_media_io_base_upload_from_file_io(self): try: import io fh = io.FileIO(datafile("small.png"), "r") upload = MediaIoBaseUpload(fh=fh, mimetype="image/png", chunksize=500, resumable=True) self.assertEqual("image/png", upload.mimetype()) self.assertEqual(190, upload.size()) self.assertEqual(True, upload.resumable()) self.assertEqual(500, upload.chunksize()) self.assertEqual("PNG", upload.getbytes(1, 3)) except ImportError: pass
def test_media_io_base_upload_from_string_io(self): f = open(datafile('small.png'), 'r') fd = StringIO.StringIO(f.read()) f.close() upload = MediaIoBaseUpload( fd=fd, mimetype='image/png', chunksize=500, resumable=True) self.assertEqual('image/png', upload.mimetype()) self.assertEqual(None, upload.size()) self.assertEqual(True, upload.resumable()) self.assertEqual(500, upload.chunksize()) self.assertEqual('PNG', upload.getbytes(1, 3)) f.close()
def test_media_io_base_upload_from_file_io(self): try: import io fd = io.FileIO(datafile('small.png'), 'r') upload = MediaIoBaseUpload( fd=fd, mimetype='image/png', chunksize=500, resumable=True) self.assertEqual('image/png', upload.mimetype()) self.assertEqual(190, upload.size()) self.assertEqual(True, upload.resumable()) self.assertEqual(500, upload.chunksize()) self.assertEqual('PNG', upload.getbytes(1, 3)) except ImportError: pass
def test_media_io_base_upload_from_string_io(self): f = open(datafile('small.png'), 'rb') fd = io.BytesIO(f.read()) f.close() upload = MediaIoBaseUpload(fd=fd, mimetype='image/png', chunksize=500, resumable=True) self.assertEqual('image/png', upload.mimetype()) self.assertEqual(190, upload.size()) self.assertEqual(True, upload.resumable()) self.assertEqual(500, upload.chunksize()) self.assertEqual(b'PNG', upload.getbytes(1, 3)) f.close()