def test_create_update(self): # create plain NyBlobFile bf = NyBlobFile() self.assertEqual(bf.content_type, 'application/octet-stream') self.assertEqual(bf.filename, None) self.assertEqual(bf.open().read(), '') # create NyBlobFile with properties and content bf2 = NyBlobFile(filename='my_file.txt', content_type='text/plain') f = bf2.open_write() f.write('hello world') f.close() self.assertEqual(bf2.content_type, 'text/plain') self.assertEqual(bf2.filename, 'my_file.txt') self.assertEqual(bf2.open().read(), 'hello world') # change properties and content f = bf2.open_write() f.write('other content') f.close() bf2.filename = 'other_file.txt' bf2.content_type = 'text/html' self.assertEqual(bf2.content_type, 'text/html') self.assertEqual(bf2.filename, 'other_file.txt') self.assertEqual(bf2.open().read(), 'other content')
def image2blob(image, filename, content_type): blobfile = NyBlobFile(filename=filename, content_type=content_type) bf_stream = blobfile.open_write() # data = image.data # bf_stream.write(data) bf_stream.write(image) bf_stream.close() blobfile.size = len(image) return blobfile
def make_blobfile(self, filename='bf.txt', content='hello world', content_type='text/plain'): bf = NyBlobFile( filename=filename, content_type=content_type, timestamp=datetime.utcnow(), contributor='tester') bf.removed = False bf.size = len(content) f = bf.open_write() f.write(content) f.close() return bf
def make_blobfile(self, filename='bf.txt', content='hello world', content_type='text/plain'): bf = NyBlobFile(filename=filename, content_type=content_type, timestamp=datetime.utcnow(), contributor='tester') bf.removed = False bf.size = len(content) f = bf.open_write() f.write(content) f.close() return bf