class CustomOperationsTestCase(unittest.TestCase): def setUp(self): self.api = BasicClient(API_KEY, API_PASSWORD) # Make directory for tests self.api.post('/path/oper/mkdir/', path=TESTFN2) def get_data(self): data = self.api.get("/path/info/testfn") return data def tearDown(self): self.api.remove('/testfn2') os.remove('testfn') def upload(self): f = StringIO(file_contents) f.seek(0) self.api.upload(TESTFN, f) self.assertEquals(self.get_data()['size'], f.tell()) def download(self): response = self.api.download(TESTFN, False) self.assertTrue(isinstance(response, requests.Response)) self.api.download(TESTFN) self.assertEquals(self.get_data()['size'], os.path.getsize(TESTFN)) def move(self): self.api.move(TESTFN, TESTFN2) def remove(self): self.api.remove(os.path.join(TESTFN2, TESTFN)) with self.assertRaises(ResponseError): self.api.remove(os.path.join(TESTFN2, TESTFN)) def test_upload_download_move_delete(self): self.upload() self.download() self.move() self.remove()
class CustomOperationsTestCase(unittest.TestCase): def setUp(self): self.api = BasicClient(API_KEY, API_PASSWORD) # Make directory for tests self.api.post('/path/oper/mkdir/', path=TESTFN2) def get_data(self): data = self.api.get("/path/info/testfn") return data def tearDown(self): self.api.remove('/testfn2') os.remove('testfn') def upload(self): f = StringIO(file_contents) f.seek(0) self.api.upload(TESTFN, f) self.assertEquals(self.get_data()['size'], f.len) def download(self): self.api.download(TESTFN) self.assertEquals(self.get_data()['size'], os.path.getsize(TESTFN)) def move(self): self.api.move(TESTFN, TESTFN2) def remove(self): self.api.remove(os.path.join(TESTFN2, TESTFN)) with self.assertRaises(ResponseError): self.api.remove(os.path.join(TESTFN2, TESTFN)) def test_upload_download_move_delete(self): self.upload() self.download() self.move() self.remove()
def upload_smartfile(request): file_path = request.GET.get('filepath') #path api = BasicClient("TxHYvbTZHmxnYcpTWvFYXKwPVb1xUh","Qlw9pGFhtl0MJFiOkBBWDLco4bV0yX") file = open(file_path,'rb') api.upload(os.path.split(file_path)[1],file) return HttpResponse("<h1>UPLOADED</h1>")