Skip to content

Commit

Permalink
Drive class tested using new Auth class
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-martin-dev committed Apr 20, 2023
1 parent fb80963 commit 671293d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ driveup.egg-info/
__pycache__
tests/localTestfiles/
.vscode
tests/__testsDatafiles/
tests/__testsDatafiles/auth_testFiles/credentials.json
tests/__testsDatafiles/auth_testFiles/client_secrets.json
10 changes: 5 additions & 5 deletions Driveup/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Drive:
def __init__(self,client_secret_path=None,credentials_path=None):
self.client_secret_path = client_secret_path
self.gauth,self.credentials_path = Auth.authorize(client_secret_path,credentials_path)
self.gauth,self.credentials_path = Auth().authorize(client_secret_path,credentials_path)
self.drive = GoogleDrive(self.gauth)

def upload(self,file_path,folder_id,file_title=None,file_id=None,update=True,convert=False,url=True):
Expand All @@ -29,9 +29,9 @@ def upload(self,file_path,folder_id,file_title=None,file_id=None,update=True,con

if convert == True:
supported_types = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.presentationml.presentation']
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.presentationml.presentation']
if gfile['mimeType'] in supported_types:
gfile.Upload(param={'convert':convert}) # Upload the file with conversion.
else:
Expand Down Expand Up @@ -69,7 +69,7 @@ def find_duplicate(self,list,name):

return file_id

def upload_folder(self,local_folder_path,folder_id=None,update=True,subfolder=True,subfolder_name=None,subfolder_id=None,recursive=True,convert=False,url=True):
def upload_folder(self,local_folder_path,folder_id,update=True,subfolder=True,subfolder_name=None,subfolder_id=None,recursive=True,convert=False,url=True):

if url == True:
folder_id = self.url_to_id(folder_id)
Expand Down
6 changes: 6 additions & 0 deletions tests/__testsDatafiles/drive_testFiles/test_file.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test column key,test column value
test1,1
test2,2
test3,3
test4,4
test5,5
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test column key,test column value
test1,1
test2,2
test3,3
test4,4
test5,5
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test column key,test column value
test1,1
test2,2
test3,3
test4,4
test5,5
25 changes: 25 additions & 0 deletions tests/drive_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest
import os

from Driveup.drive import Drive

tests_dir = os.path.dirname(os.path.abspath(__file__)) # Driveup/tests/

CREDENTIALS_PATH = os.path.join(tests_dir,"__testsDataFiles","auth_testFiles","credentials.json")
CLIENT_SECRET_PATH = os.path.join(tests_dir,"__testsDataFiles","auth_testFiles","client_secrets.json")
UPLOAD_FILE_PATH = os.path.join(tests_dir,"__testsDataFiles","drive_testFiles","test_file.csv")
UPLOAD_FOLDER_PATH = os.path.join(tests_dir,"__testsDataFiles","drive_testFiles","test_folder")
DRIVE_FOLDER_ID = 'https://drive.google.com/drive/folders/1wXpG03SN0RXI7y1QAd03IDGH2eXFD_VS'

class TestDrive(unittest.TestCase):
def test_upload(self):
drive_obj = Drive(client_secret_path=CLIENT_SECRET_PATH,credentials_path=CREDENTIALS_PATH)
drive_obj.upload(UPLOAD_FILE_PATH,DRIVE_FOLDER_ID)

def test_upload_folder(self):
drive_obj = Drive(credentials_path=CREDENTIALS_PATH,client_secret_path=CLIENT_SECRET_PATH)
drive_obj.upload_folder(UPLOAD_FOLDER_PATH,DRIVE_FOLDER_ID)

if __name__ == "__main__":
unittest.main()
# Auth tests can't be tested simultaneously (API conflict)

0 comments on commit 671293d

Please sign in to comment.