Esempio n. 1
0
    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))
Esempio n. 2
0
    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)
Esempio n. 3
0
 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)