def test_remove_chunked_upload(self): uri = '/chunked_upload' chunk = os.urandom(random.randint(12, 64)) with app.test_request_context(uri, method='PUT', data=chunk): fs.register_chunk(self.id_, request.stream) with app.test_request_context(uri, method='PUT', data=chunk): fs.remove_chunked_upload(self.id_) test_path = os.path.join(fs.storage_root, config.chunk_storage) self.assertTrue(os.path.exists(test_path)) test_path = os.path.join(test_path, self.id_[:2]) self.assertTrue(os.path.exists(test_path)) test_path = os.path.join(test_path, self.id_[2:]) self.assertFalse(os.path.exists(test_path))
def test_register_chunk(self): data = os.urandom(64) uri = '/chunked_upload' with app.test_request_context(uri, method='PUT', data=data): offset = fs.register_chunk(self.id_, request.stream) self.assertEqual(offset, len(data)) test_path = os.path.join(fs.storage_root, config.chunk_storage) self.assertTrue(os.path.exists(test_path)) test_path = os.path.join(test_path, self.id_[:2]) self.assertTrue(os.path.exists(test_path)) test_path = os.path.join(test_path, self.id_[2:]) self.assertTrue(os.path.exists(test_path)) with open(test_path) as f: self.assertEqual(f.read(), data)
def test_retrieve_chunk(self): data = os.urandom(64) fs.register_chunk(self.id_, cStringIO.StringIO(data)) with fs.retrieve_chunk_stream(self.id_) as s: self.assertEqual(s.read(), data)