Example #1
0
 def test_SciDrive_publicUrl(self):
     try:
         responseDelete = SciDrive.delete(SciDrive_Directory)
     except:
         pass
     responseCreate = SciDrive.createContainer(SciDrive_Directory)
     url = SciDrive.publicUrl(SciDrive_Directory)
     responseDelete = SciDrive.delete(SciDrive_Directory)
     isUrl = url.startswith("http")
     self.assertEqual(responseCreate, True)
     self.assertEqual(isUrl, True)
     self.assertEqual(responseDelete, True)
Example #2
0
    def test_SciDrive_createContainer_directoryList_delete(self):
        try:
            responseDelete = SciDrive.delete(SciDrive_Directory)
        except:
            pass

        try:
            responseCreate = SciDrive.createContainer(SciDrive_Directory)
            self.assertEqual(responseCreate, True)

            dirList = SciDrive.directoryList(SciDrive_Directory)
            self.assertTrue(dirList["path"].__contains__(SciDrive_Directory))

        finally:
            responseDelete = SciDrive.delete(SciDrive_Directory)
            self.assertEqual(responseDelete, True)
Example #3
0
 def _download_from_scidrive(self,
                             table_name,
                             save_to,
                             max_tries=20,
                             verbose=True):
     """Check if the table is ready to download and download it once ready"""
     tgt_file_path = CASJOBS_CONTAINER + '/' + table_name + '_{}'.format(
         self.uname) + '.csv'
     count = 0
     while True:
         list_of_files = sd.directoryList(CASJOBS_CONTAINER)['contents']
         for file in list_of_files:
             if file['path'].strip() == tgt_file_path:
                 sd.download(tgt_file_path,
                             localFilePath='{0}/{1}.csv'.format(
                                 save_to, table_name))
                 is_deleted = sd.delete(tgt_file_path)
                 print(
                     'Successfully downloaded the table csv, deleted in SciDrive: ',
                     is_deleted)
                 return
         count += 1
         if count > max_tries:
             break
         if verbose:
             print('Waiting')
         time.sleep(10)
     print('could not download file')
Example #4
0
    def test_SciDrive_upload_download_delete(self):
        try:

            if (sys.version_info > (3, 0)):  #python3
                file = open(SciDrive_FileName, "w")
            else:  #python2
                file = open(SciDrive_FileName, "wb")

            file.write(SciDrive_FileContent)
            file.close()

            responseUpload = SciDrive.upload(path=SciDrive_Directory + "/" +
                                             SciDrive_FileName,
                                             localFilePath=SciDrive_FileName)

            stringio = SciDrive.download(path=SciDrive_Directory + "/" +
                                         SciDrive_FileName,
                                         format="StringIO")
            fileContent = stringio.read()
            responseDelete = SciDrive.delete(SciDrive_Directory)
            self.assertEqual(responseUpload["path"],
                             SciDrive_Directory + "/" + SciDrive_FileName)
            self.assertEqual(fileContent, SciDrive_FileContent)
            self.assertEqual(responseDelete, True)

            responseUpload = SciDrive.upload(path=SciDrive_Directory + "/" +
                                             SciDrive_FileName,
                                             data=SciDrive_FileContent)
            fileContent = SciDrive.download(path=SciDrive_Directory + "/" +
                                            SciDrive_FileName,
                                            format="text")
            responseDelete = SciDrive.delete(SciDrive_Directory)
            self.assertEqual(responseUpload["path"],
                             SciDrive_Directory + "/" + SciDrive_FileName)
            self.assertEqual(fileContent, SciDrive_FileContent)
            self.assertEqual(responseDelete, True)

        finally:
            try:
                os.remove(SciDrive_FileName)
            except:
                pass
print(dirList)


# In[ ]:

#get the public url to access the directory content in SciDrive

url = SciDrive.publicUrl(SciDrive_Directory)
print(url)


# In[ ]:

#Delete folder or container in SciDrive:

responseDelete = SciDrive.delete(SciDrive_Directory)
print(responseDelete)


# In[ ]:

#create a local file:

file = open(SciDrive_FileName, "w")
file.write(SciDrive_FileContent)
file.close()


# In[ ]:

#uploading a file to SciDrive: