Esempio n. 1
0
    def testCreateAndDeleteProjectFolder(self):
        # avoid warning resourcewarning unclosed ssl.sslsocket due to Dropbox
        warnings.filterwarnings(action="ignore",
                                message="unclosed",
                                category=ResourceWarning)

        if os.name == 'posix':
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/dropbox_access_tst.ini'
        else:
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\dropbox_access_tst.ini'

        cm = ConfigManager(configFilePathName)
        projectName = 'transFileCloudTestProjectToCreate'

        # creating a DropboxAccess on an inexisting Dropbox folder
        # to ensure the folder does not exist
        drpa = DropboxAccess(cm, projectName)
        self.assertRaises(NotADirectoryError, drpa.getCloudFileNameList)

        # now, creating the project folder
        drpa.createProjectFolder()

        # should not raise any error
        drpa.getCloudFileNameList()

        # now deleting the newly created folder so that this test can be run again
        drpa = DropboxAccess(cm, projectName)
        drpa.deleteProjectFolder()

        # verify the project folder was deleted
        self.assertRaises(NotADirectoryError, drpa.getCloudFileNameList)
Esempio n. 2
0
    def testDownloadFile_in_subSubDir(self):
        """
		For this test to succeed, the dropbox test dir must contain one file:
		SubDirOne/subDirOne.py.

		The dropbox cloud folder is test_dropbox/transFileCloudTestProject
		"""
        if os.name == 'posix':
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/transfiles.ini'
            downloadDir = '/storage/emulated/0/Download'
        else:
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\transfiles.ini'
            downloadDir = 'D:\\Users\\Jean-Pierre\\Downloads'

        cm = ConfigManager(configFilePathName)
        projectName = 'transFileCloudTestProject'
        drpa = DropboxAccess(cm, projectName)
        fileName = 'subDirOneSubDir.py'
        fileSubDir = 'SubDirOne'
        fileSubSubDir = 'SubDirOneSubDir'
        cloudFilePathName = fileSubDir + '/' + fileSubSubDir + '/' + fileName
        downloadedFilePathName = downloadDir + sep + fileSubDir + sep + fileSubSubDir + sep + fileName
        drpa.downloadFile(cloudFilePathName, downloadedFilePathName)

        # verifying that the file was downloaded
        fileNameLst = [
            x.split(sep)[-1]
            for x in glob.glob(downloadDir + sep + fileSubDir + sep +
                               fileSubSubDir + sep + '*.py')
        ]
        self.assertEqual(sorted([fileName]), sorted(fileNameLst))

        # deleting downloaded file
        shutil.rmtree(downloadDir + sep + fileSubDir)
Esempio n. 3
0
    def testCreateEmptyFolder(self):
        # avoid warning resourcewarning unclosed ssl.sslsocket due to Dropbox
        warnings.filterwarnings(action="ignore",
                                message="unclosed",
                                category=ResourceWarning)

        if os.name == 'posix':
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/dropbox_access_tst.ini'
        else:
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\dropbox_access_tst.ini'

        cm = ConfigManager(configFilePathName)
        projectName = 'transFileCloudTestProject'
        newFolderName = 'newFolder'

        # creating a DropboxAccess on an inexisting Dropbox folder
        # to ensure the folder does not exist
        drpa = DropboxAccess(cm, projectName + '/' + newFolderName)
        self.assertRaises(NotADirectoryError, drpa.getCloudFileNameList)

        # now, creating the new folder. First recreate a DropboxAccess
        # on an existing project folder
        drpa = DropboxAccess(cm, projectName)

        # then create the new folder and ensure it is accessible
        drpa.createProjectSubFolder(newFolderName)

        # creating a DropboxAccess on the newly created Dropbox folder
        # to ensure the folder now exists
        drpa = DropboxAccess(cm, projectName + '/' + newFolderName)

        # should not raise any error
        drpa.getCloudFileNameList()

        # now deleting the newly created folder so that other tests are not
        # impacted
        drpa = DropboxAccess(cm, projectName)
        drpa.deleteProjectSubFolder(newFolderName)
Esempio n. 4
0
    def testUploadSameFileNameTwice(self):
        if os.name == 'posix':
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/dropbox_access_tst.ini'
            localDir = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/testproject_1/fromdir_saved'
        else:
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\dropbox_access_tst.ini'
            localDir = 'D:\\Development\\Python\\trans_file_cloud\\test\\testproject_1\\fromdir_saved'

        cm = ConfigManager(configFilePathName)
        projectName = 'transFileCloudTestProjectForUpload'

        # creating a DropboxAccess on an inexisting Dropbox folder
        # to ensure the folder does not exist
        drpa = DropboxAccess(cm, projectName)

        try:
            drpa.getCloudFileNameList()
        except NotADirectoryError:
            # if project folder does not exist
            drpa.createProjectFolder()

        # should not raise any error
        self.assertEqual([], drpa.getCloudFileNameList())

        # now, uploading a file
        uploadFileName = 'uploadTwice'
        localFilePathName = localDir + sep + uploadFileName
        drpa.uploadFileName(localFilePathName)

        self.assertEqual([uploadFileName], drpa.getCloudFileNameList())

        # modifiying the file before uploading it again. Since
        # dropbox.files.WriteMode.overwrite is set when calling
        # dropbox.files_upload, no WriteConflictError is raised
        # when uploading the modified file.
        with open(localFilePathName, 'w') as f:
            f.write('modified at date {}'.format(
                datetime.datetime.now().strftime(
                    DATE_TIME_FORMAT_CONFIG_FILE)))
            f.close()

        drpa.uploadFileName(localFilePathName)

        self.assertEqual([uploadFileName], drpa.getCloudFileNameList())
        # now deleting the newly created file so that this test can be run again
        drpa.deleteFile(uploadFileName)

        # should not raise any error
        self.assertEqual([], drpa.getCloudFileNameList())
Esempio n. 5
0
    def testUploadAndDeleteFilePathName(self):
        if os.name == 'posix':
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/transfiles.ini'
            localDir = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/testproject_3/projectdir'
        else:
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\transfiles.ini'
            localDir = 'D:\\Development\\Python\\trans_file_cloud\\test\\testproject_3\\projectdir'

        cm = ConfigManager(configFilePathName)
        projectName = 'transFileCloudFilePathNameProject'

        # creating a DropboxAccess on an inexisting Dropbox folder
        # to ensure the folder does not exist
        drpa = DropboxAccess(cm, projectName)

        try:
            drpa.getCloudFileNameList()
        except NotADirectoryError:
            # if project folder does not exist
            drpa.createProjectFolder()

        # should not raise any error
        self.assertEqual([], drpa.getCloudFileNameList())

        # now, uploading two files, one in the root of project dir, the other
        # in a project sub dir
        localProjectDir = cm.getProjectLocalDir(projectName)
        uploadFileNameProjectRoot = 'filemover_2.py'
        localFilePathName = localDir + sep + uploadFileNameProjectRoot
        drpa.uploadFilePathName(localFilePathName)

        uploadFileNameProjectSubdir = 'test' + sep + 'testfilemover_2.py'
        localFilePathName = localDir + sep + uploadFileNameProjectSubdir
        drpa.uploadFilePathName(localFilePathName)

        uploadFileNameProjectSubdirSlashDirSep = uploadFileNameProjectSubdir.replace(
            '\\', '/')
        self.assertEqual([
            uploadFileNameProjectRoot, uploadFileNameProjectSubdirSlashDirSep
        ], drpa.getCloudFilePathNameList())

        # now deleting the newly created file so that this test can be run again
        drpa.deleteFile(uploadFileNameProjectRoot)
        drpa.deleteFile(uploadFileNameProjectSubdirSlashDirSep)

        # should not raise any error
        self.assertEqual([], drpa.getCloudFilePathNameList())
        drpa.deleteProjectFolder()
Esempio n. 6
0
    def testGetCloudFileNameList(self):
        """
		For this test to succeed, the dropbox test dir must contain two files:
		my_file_one.py and my_file_two.py. 
		
		The dropbox cloud folder is test_dropbox/transFileCloudTestProject
		"""
        if os.name == 'posix':
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/transfiles.ini'
        else:
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\transfiles.ini'

        cm = ConfigManager(configFilePathName)
        projectName = 'transFileCloudTestProject'
        drpa = DropboxAccess(cm, projectName)

        self.assertEqual(sorted(['my_file_one.py', 'my_file_two.py']),
                         sorted(drpa.getCloudFileNameList()))
    def initTransferFileOnProject(self, configFilePath=None, projectName=None):
        """
		This method enables the transfer files utility to be executed in a loop.
		It initializes the TransferFile class with the data specific to the
		project selected by the user.
		
	    @param configFilePath: used for unit testing only
	    @param projectName used for unit testing only
	    
		@return: True if the user selects another project, False otherwise
		"""
        if projectName == None:
            # we are not unit testing ...
            projectName = self.requester.getProjectName(commandLineArgs=None)

            if projectName == None:
                # user did choose Quit
                self.projectName = None
                return False

        self.projectName = projectName
        self.localProjectDir = None

        try:
            self.localProjectDir = self.configManager.getProjectLocalDir(
                self.projectName)
        except KeyError as e:
            # this happens only when TransferFiles is launched from the command line
            # with an invalid project name passed as -p command line parm
            print(
                '\nProject {} not defined in configuration file {}. Program closed.\n'
                .format(str(e), configFilePath))
            self.projectName = None
            return False

        # currently, only Dropbox as cloud space is implemented
        self.cloudAccess = DropboxAccess(self.configManager, self.projectName)
        self.fileLister = FileLister(self.configManager)

        return True
Esempio n. 8
0
    def testGetCloudFileList_invalid_cloud_dir(self):
        '''
		Tests that the getCloudFileNameList() method raises a NotADirectoryError
		if the cloud project path which is equal to cloud transfer base dir + 
		'/' + projectName as defined in the tranfiles.ini file does not exist.
		'''
        # avoid warning resourcewarning unclosed ssl.sslsocket due to Dropbox
        warnings.filterwarnings(action="ignore",
                                message="unclosed",
                                category=ResourceWarning)

        if os.name == 'posix':
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/dropbox_access_tst.ini'
        else:
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\dropbox_access_tst.ini'

        cm = ConfigManager(configFilePathName)
        projectName = 'not_exist'
        drpa = DropboxAccess(cm, projectName)

        # project name which has an invalid (not existing) project path in the
        # transfiles.ini file
        invalidProjectName = 'transFileCloudInvalidProject'
        self.assertRaises(NotADirectoryError, drpa.getCloudFileNameList)
Esempio n. 9
0
    def testUploadAndDeleteFileName(self):
        if os.name == 'posix':
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/dropbox_access_tst.ini'
            localDir = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/testproject_1/fromdir_saved'
        else:
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\dropbox_access_tst.ini'
            localDir = 'D:\\Development\\Python\\trans_file_cloud\\test\\testproject_1\\fromdir_saved'

        cm = ConfigManager(configFilePathName)
        projectName = 'transFileCloudTestProjectForUpload'

        # creating a DropboxAccess on an inexisting Dropbox folder
        # to ensure the folder does not exist
        drpa = DropboxAccess(cm, projectName)

        try:
            drpa.getCloudFileNameList()
        except NotADirectoryError:
            # if project folder does not exist
            drpa.createProjectFolder()

        # should not raise any error
        self.assertEqual([], drpa.getCloudFileNameList())

        # now, uploading a file
        uploadFileName = 'filemover_1.py'
        localFilePathName = localDir + sep + uploadFileName
        drpa.uploadFileName(localFilePathName)

        self.assertEqual([uploadFileName], drpa.getCloudFileNameList())

        # now deleting the newly created file so that this test can be run again
        drpa.deleteFile(uploadFileName)

        # should not raise any error
        self.assertEqual([], drpa.getCloudFileNameList())
Esempio n. 10
0
    def testUploadModifiedFilesToCloud_noFilePath(self):
        # avoid warning resourcewarning unclosed ssl.sslsocket due to Dropbox
        warnings.filterwarnings(action="ignore",
                                message="unclosed",
                                category=ResourceWarning)

        if os.name == 'posix':
            localProjectDir = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/testproject_2/projectdir'
            localProjectDirSaved = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/testproject_2/projectdir_saved'
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/test_TransferFiles.ini'
        else:
            localProjectDir = 'D:\\Development\\Python\\trans_file_cloud\\test\\testproject_2\\projectdir'
            localProjectDirSaved = 'D:\\Development\\Python\\trans_file_cloud\\test\\testproject_2\\projectdir_saved'
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\test_TransferFiles.ini'

        # cleaning up the target cloud folder

        cm = ConfigManager(configFilePathName)
        projectName = 'TransferFilesTestProject'
        drpa = DropboxAccess(cm, projectName)

        cloudFileLst = drpa.getCloudFileNameList()

        for file in cloudFileLst:
            drpa.deleteFile(file)

        self.assertEqual([], drpa.getCloudFileNameList())

        # reading and rewriting test project files to update their modification date

        tstFileToModifyLst = ['testfilemover_2.py']
        pythonFileToModifyLst = ['filemover_2.py', 'filelister_2.py']
        docFileToModifyLst = ['doc_21.docx', 'doc_22.docx']
        imgFileToModifyLst = ['current_state_21.jpg']

        tstFilePathNameToModifyLst = [
            localProjectDir + sep + 'test' + sep + x
            for x in tstFileToModifyLst
        ]
        pythonFilePathNameToModifyLst = [
            localProjectDir + sep + x for x in pythonFileToModifyLst
        ]
        docFilePathNameToModifyLst = [
            localProjectDir + sep + 'doc' + sep + x for x in docFileToModifyLst
        ]
        imgFilePathNameToModifyLst = [
            localProjectDir + sep + 'images' + sep + x
            for x in imgFileToModifyLst
        ]

        filePathNameToModifyLst = tstFilePathNameToModifyLst + pythonFilePathNameToModifyLst + docFilePathNameToModifyLst + imgFilePathNameToModifyLst

        for filePathName in filePathNameToModifyLst:
            # opening file as readwrite in binary mode
            with open(filePathName, 'rb+') as f:
                content = f.read()
                f.seek(0)
                f.write(content)
                f.close()

        # simulating user input

        stdin = sys.stdin

        # selecting project 1 (the test project 'TransferFilesTestProject' is
        # the first project defined in test_TransferFiles.ini !)
        sys.stdin = StringIO('1')

        print('\nstdout temporarily captured. Test is running ...')

        stdout = sys.stdout
        outputCapturingString = StringIO()
        sys.stdout = outputCapturingString

        # now asking TransferFiles to upload the modified files

        tf = TransferFiles(configFilePath=configFilePathName)

        # confirming modified files upload
        sys.stdin = StringIO('Y')

        tf.uploadModifiedFilesToCloud()

        sys.stdin = stdin
        sys.stdout = stdout

        expectedUploadedFileNameLst = tstFileToModifyLst + pythonFileToModifyLst + docFileToModifyLst + imgFileToModifyLst

        self.assertEqual(sorted(expectedUploadedFileNameLst),
                         sorted(drpa.getCloudFileNameList()))

        # now restoring the modified files dir to its saved version
        dir_util.copy_tree(localProjectDirSaved, localProjectDir)
Esempio n. 11
0
    def testTransferFilesFromCloudToLocalDirs_filePath(self):
        # avoid warning resourcewarning unclosed ssl.sslsocket due to Dropbox
        warnings.filterwarnings(action="ignore",
                                message="unclosed",
                                category=ResourceWarning)

        if os.name == 'posix':
            localProjectDir = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/testproject_2/projectdir'
            localProjectDirSaved = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/testproject_2/projectdir_saved'
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/test_TransferFiles.ini'
        else:
            localProjectDir = 'D:\\Development\\Python\\trans_file_cloud\\test\\testproject_2\\projectdir'
            localProjectDirSaved = 'D:\\Development\\Python\\trans_file_cloud\\test\\testproject_2\\projectdir_saved'
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\test_TransferFiles.ini'

        cm = ConfigManager(configFilePathName)
        projectName = 'TransferPathFilesTestProject'

        # storing the last synch update time to compare it to the new update
        # time once download and move has been performed
        storedLastSynchTimeStr = cm.getLastSynchTime(projectName)
        storedLastSyncTime = datetime.datetime.strptime(
            storedLastSynchTimeStr, DATE_TIME_FORMAT_CONFIG_FILE)

        # cleaning up the cloud folder before uploading the test files

        drpa = DropboxAccess(cm, projectName)

        cloudFileLst = drpa.getCloudFilePathNameList()

        for file in cloudFileLst:
            drpa.deleteFile(file)

        self.assertEqual([], drpa.getCloudFileNameList())

        # listing the test files which wiLl be uploaded to
        # the cloud in order to be available for download
        # and move to local dirs

        tstFileToUploadLst = ['testfilemover_2.py']
        pythonFileToUploadLst = ['filemover_2.py', 'filelister_2.py']
        docFileToUploadLst = ['doc_21.docx', 'doc_22.docx']
        imgFileToUploadLst = ['current_state_21.jpg']

        fileNameToUploadLst = tstFileToUploadLst + pythonFileToUploadLst + docFileToUploadLst + imgFileToUploadLst

        tstFilePathNameToUploadLst = [
            localProjectDir + sep + 'test' + sep + x
            for x in tstFileToUploadLst
        ]
        pythonFilePathNameToUploadLst = [
            localProjectDir + sep + x for x in pythonFileToUploadLst
        ]
        docFilePathNameToUploadLst = [
            localProjectDir + sep + 'doc' + sep + x for x in docFileToUploadLst
        ]
        imgFilePathNameToUploadLst = [
            localProjectDir + sep + 'images' + sep + x
            for x in imgFileToUploadLst
        ]

        filePathNameToUploadLst = tstFilePathNameToUploadLst + pythonFilePathNameToUploadLst + docFilePathNameToUploadLst + imgFilePathNameToUploadLst

        # uploading the test files which will then be downloaded and moved to
        # local dirs

        drpa = DropboxAccess(cm, projectName)

        for filePathName in filePathNameToUploadLst:
            drpa.uploadFilePathName(filePathName)

        # simulating user input

        stdin = sys.stdin

        # selecting project 2 (the test project 'TransferPathFilesTestProject' is
        # the second project defined in test_TransferFiles.ini !)
        sys.stdin = StringIO('2')  # TransferPathFilesTestProject

        print('\nstdout temporarily captured. Test is running ...')

        stdout = sys.stdout
        outputCapturingString = StringIO()
        sys.stdout = outputCapturingString

        # now asking TransferFiles to download the cloud files and move them
        # to the local dirs

        tf = TransferFiles(configFilePath=configFilePathName)

        # confirming cloud files download
        sys.stdin = StringIO('Y')

        tf.transferFilesFromCloudToLocalDirs(drpa.getCloudFilePathNameList())

        sys.stdin = stdin
        sys.stdout = stdout

        # testing that the last synch time is after the stored synch time

        cm_reloaded = ConfigManager(configFilePathName)
        newLastSynchTimeStr = cm_reloaded.getLastSynchTime(projectName)
        newLastSyncTime = datetime.datetime.strptime(
            newLastSynchTimeStr, DATE_TIME_FORMAT_CONFIG_FILE)
        self.assertTrue(newLastSyncTime > storedLastSyncTime)

        # now testing that the files downloaded from the cloud and moved to
        # the local dirs are the expected ones

        # first, reset the last synch time to the stored one so that FileLister
        # will list files whose modification date is oreater than this time
        cm.updateLastSynchTime(projectName, storedLastSynchTimeStr)

        fl = FileLister(cm)
        allFileNameLst, allFilePathNameLst, lastSyncTimeStr = fl.getModifiedFileLst(
            projectName)

        self.assertEqual(sorted(fileNameToUploadLst), sorted(allFileNameLst))
        self.assertEqual(sorted(filePathNameToUploadLst),
                         sorted(allFilePathNameLst))

        # now restoring the modified files dir to its saved version
        shutil.rmtree(localProjectDir)
        dir_util.copy_tree(localProjectDirSaved, localProjectDir)
Esempio n. 12
0
    def testUploadToCloud_invalid_fileName(self):
        # avoid warning resourcewarning unclosed ssl.sslsocket due to Dropbox
        warnings.filterwarnings(action="ignore",
                                message="unclosed",
                                category=ResourceWarning)

        if os.name == 'posix':
            localProjectDir = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/testproject_2/projectdir'
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/test_TransferFiles.ini'
        else:
            localProjectDir = 'D:\\Development\\Python\\trans_file_cloud\\test\\testproject_2\\projectdir'
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\test_TransferFiles.ini'

        # cleaning up the target cloud folder

        cm = ConfigManager(configFilePathName)
        projectName = 'TransferFilesTestProject'
        drpa = DropboxAccess(cm, projectName)

        cloudFileLst = drpa.getCloudFilePathNameList()

        for file in cloudFileLst:
            drpa.deleteFile(file)

        self.assertEqual([], drpa.getCloudFilePathNameList())

        # reading and rewriting test project files to update their modification date

        fileToUploadLst = ['youtube-dl test video \'\'_ä↭𝕐-BaW_jenozKc.m4a']

        filePathNameToUploadLst = [
            localProjectDir + sep + x for x in fileToUploadLst
        ]

        # simulating user input

        stdin = sys.stdin

        # selecting project 1 (the test project 'TransferFilesTestProject' is
        # the first project defined in test_TransferFiles.ini !)
        sys.stdin = StringIO('2')

        print('\nstdout temporarily captured. Test is running ...')

        stdout = sys.stdout
        outputCapturingString = StringIO()
        sys.stdout = outputCapturingString

        # now asking TransferFiles to upload the modified files

        tf = TransferFiles(configFilePath=configFilePathName)
        outputCapturingString = StringIO()
        sys.stdout = outputCapturingString
        tf.uploadToCloud(filePathNameToUploadLst)

        sys.stdin = stdin
        sys.stdout = stdout

        expectedUploadedFilePathNameLst = []

        actualUploadedFilePathNameLst = drpa.getCloudFilePathNameList()
        self.assertEqual(sorted(expectedUploadedFilePathNameLst),
                         sorted(actualUploadedFilePathNameLst))

        if os.name == 'posix':
            self.assertTrue(
                '\tUploading youtube-dl test video \'\'_ä↭𝕐-BaW_jenozKc.m4a failed. Possible cause: invalid file name ...'
                in outputCapturingString.getvalue())
        else:
            self.assertTrue(
                '\tUploading youtube-dl test video \'\'_ä↭𝕐-BaW_jenozKc.m4a failed. Possible cause: invalid file name ...'
                in outputCapturingString.getvalue())
Esempio n. 13
0
    def testPathUploadToCloud(self):
        # avoid warning resourcewarning unclosed ssl.sslsocket due to Dropbox
        warnings.filterwarnings(action="ignore",
                                message="unclosed",
                                category=ResourceWarning)

        if os.name == 'posix':
            localProjectDir = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/testproject_2/projectdir'
            configFilePathName = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/trans_file_cloud/test/test_TransferFiles.ini'
        else:
            localProjectDir = 'D:\\Development\\Python\\trans_file_cloud\\test\\testproject_2\\projectdir'
            configFilePathName = 'D:\\Development\\Python\\trans_file_cloud\\test\\test_TransferFiles.ini'

        # cleaning up the target cloud folder

        cm = ConfigManager(configFilePathName)
        projectName = 'TransferFilesTestProject'
        drpa = DropboxAccess(cm, projectName)

        cloudFileLst = drpa.getCloudFilePathNameList()

        for file in cloudFileLst:
            drpa.deleteFile(file)

        self.assertEqual([], drpa.getCloudFilePathNameList())

        # reading and rewriting test project files to update their modification date

        tstFileToUploadLst = ['testfilemover_2.py']
        pythonFileToUploadLst = ['filemover_2.py', 'filelister_2.py']
        docFileToUploadLst = ['doc_21.docx', 'doc_22.docx']
        imgFileToUploadLst = ['current_state_21.jpg']

        tstFilePathNameToUploadLst = [
            localProjectDir + sep + 'test' + sep + x
            for x in tstFileToUploadLst
        ]
        pythonFilePathNameToUploadLst = [
            localProjectDir + sep + x for x in pythonFileToUploadLst
        ]
        docFilePathNameToUploadLst = [
            localProjectDir + sep + 'doc' + sep + x for x in docFileToUploadLst
        ]
        imgFilePathNameToUploadLst = [
            localProjectDir + sep + 'images' + sep + x
            for x in imgFileToUploadLst
        ]

        filePathNameToUploadLst = tstFilePathNameToUploadLst + pythonFilePathNameToUploadLst + docFilePathNameToUploadLst + imgFilePathNameToUploadLst

        # simulating user input

        stdin = sys.stdin

        # selecting project 1 (the test project 'TransferFilesTestProject' is
        # the first project defined in test_TransferFiles.ini !)
        sys.stdin = StringIO('1')

        print('\nstdout temporarily captured. Test is running ...')

        stdout = sys.stdout
        outputCapturingString = StringIO()
        sys.stdout = outputCapturingString

        # now asking TransferFiles to upload the modified files

        tf = TransferFiles(configFilePath=configFilePathName)
        outputCapturingString = StringIO()
        sys.stdout = outputCapturingString
        tf.pathUploadToCloud(filePathNameToUploadLst)

        sys.stdin = stdin
        sys.stdout = stdout

        expectedUploadedFilePathNameLst = [
            'doc/doc_21.docx', 'doc/doc_22.docx', 'filelister_2.py',
            'filemover_2.py', 'images/current_state_21.jpg',
            'test/testfilemover_2.py'
        ]

        actualUploadedFilePathNameLst = drpa.getCloudFilePathNameList()
        self.assertEqual(sorted(expectedUploadedFilePathNameLst),
                         sorted(actualUploadedFilePathNameLst))

        if os.name == 'posix':
            self.assertTrue(
                'Uploading testproject_2/projectdir/test/testfilemover_2.py to the cloud ...'
                in outputCapturingString.getvalue())
        else:
            self.assertTrue(
                'Uploading testproject_2\projectdir\\test\\testfilemover_2.py to the cloud ...'
                in outputCapturingString.getvalue())