def test_upload(self): f, sz = gen_temp_file() md5 = hashing.hash_file_obj(f) n = self.acd_client.upload_file(f.name) self.assertIn('id', n) self.assertEqual(n['contentProperties']['size'], sz) self.assertEqual(n['contentProperties']['md5'], md5) n = self.acd_client.move_to_trash(n['id'])
def test_download_chunked(self): ch_sz = gen_rand_sz() content.CHUNK_SIZE = ch_sz f, sz = gen_temp_file(size=5 * ch_sz) md5 = hashing.hash_file_obj(f) n = self.acd_client.upload_file(f.name) self.assertEqual(n['contentProperties']['md5'], md5) f.close() self.assertFalse(os.path.exists(f.name)) f = io.BytesIO() self.acd_client.chunked_download(n['id'], f, length=sz) self.acd_client.move_to_trash(n['id']) dl_md5 = hashing.hash_file_obj(f) self.assertEqual(sz, f.tell()) self.assertEqual(md5, dl_md5)
def test_upload(self): f, sz = gen_temp_file() md5 = hashing.hash_file_obj(f) n = self.acd_client.upload_file(f.name) self.assertIn("id", n) self.assertEqual(n["contentProperties"]["size"], sz) self.assertEqual(n["contentProperties"]["md5"], md5) n = self.acd_client.move_to_trash(n["id"])
def test_download(self): f, sz = gen_temp_file() self.assertTrue(sz < content.CONSECUTIVE_DL_LIMIT) md5 = hashing.hash_file_obj(f) n = self.acd_client.upload_file(f.name) self.assertIn('id', n) f.close() self.assertFalse(os.path.exists(f.name)) self.acd_client.download_file(n['id'], f.name) md5_dl = hashing.hash_file(f.name) self.assertEqual(md5, md5_dl) self.acd_client.move_to_trash(n['id'])
def test_download(self): f, sz = gen_temp_file() self.assertTrue( sz < self.acd_client._conf.getint('transfer', 'dl_chunk_size')) md5 = hashing.hash_file_obj(f) n = self.acd_client.upload_file(f.name) self.assertIn('id', n) f.close() self.assertFalse(os.path.exists(f.name)) self.acd_client.download_file(n['id'], f.name) md5_dl = hashing.hash_file(f.name) self.assertEqual(md5, md5_dl) self.acd_client.move_to_trash(n['id'])
def test_incomplete_download(self): ch_sz = gen_rand_sz() content.CHUNK_SIZE = ch_sz f, sz = gen_temp_file(size=5 * ch_sz) md5 = hashing.hash_file_obj(f) n = self.acd_client.upload_file(f.name) self.assertEqual(n['contentProperties']['md5'], md5) f.close() with self.assertRaises(RequestError) as cm: self.acd_client.download_file(n['id'], f.name, length=sz + 1) self.assertEqual(cm.exception.status_code, RequestError.CODE.INCOMPLETE_RESULT) self.acd_client.download_file(n['id'], f.name, length=sz) self.acd_client.move_to_trash(n['id']) os.remove(f.name)