Exemplo n.º 1
0
    def test_09_Files_Update_File(self):
        delete_file(self.first_file + "1")
        delete_file(self.second_file + "1")
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        filename = "preupdatetestfile"
        newfilename = "updatetestfile"

        file1["title"] = filename
        file1.SetContentFile(self.first_file)
        pydrive_retry(file1.Upload)  # Files.insert
        self.assertEqual(file1.metadata["title"], filename)

        pydrive_retry(
            file1.FetchContent)  # Force download and double check content.
        pydrive_retry(lambda: file1.GetContentFile(self.first_file + "1"))
        self.assertEqual(filecmp.cmp(self.first_file, self.first_file + "1"),
                         True)

        file1["title"] = newfilename
        file1.SetContentFile(self.second_file)
        pydrive_retry(file1.Upload)  # Files.update
        self.assertEqual(file1.metadata["title"], newfilename)
        pydrive_retry(lambda: file1.GetContentFile(self.second_file + "1"))
        self.assertEqual(filecmp.cmp(self.second_file, self.second_file + "1"),
                         True)

        self.DeleteUploadedFiles(drive, [file1["id"]])

        delete_file(self.first_file + "1")
        delete_file(self.second_file + "1")
Exemplo n.º 2
0
    def test_Files_Delete_Permission(self):
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        pydrive_retry(file1.Upload)
        pydrive_retry(
            file1.InsertPermission,
            {
                "type": "anyone",
                "value": "anyone",
                "role": "reader"
            },
        )
        permissions = pydrive_retry(file1.GetPermissions)
        self.assertEqual(len(permissions), 2)
        self.assertEqual(len(file1["permissions"]), 2)

        pydrive_retry(file1.DeletePermission, permissions[0]["id"])
        self.assertEqual(len(file1["permissions"]), 1)

        # Verify remote changes made.
        file2 = drive.CreateFile({"id": file1["id"]})
        permissions = pydrive_retry(file2.GetPermissions)
        self.assertEqual(len(permissions), 1)

        pydrive_retry(file1.Delete)
Exemplo n.º 3
0
 def cleanup_gfile_conversion_test(self, file1, file_name,
                                   downloaded_file_name):
     # Delete temporary files.
     os.path.exists(file_name) and os.remove(file_name)
     os.path.exists(downloaded_file_name) and os.remove(
         downloaded_file_name)
     pydrive_retry(file1.Delete)  # Delete uploaded file.
Exemplo n.º 4
0
    def test_GFile_Conversion_Remove_BOM(self):
        (
            file1,
            file_name,
            original_file_content,
            downloaded_file_name,
        ) = self.setup_gfile_conversion_test()
        try:
            # Upload source_file and convert into Google Doc format.
            file1.SetContentFile(file_name)
            pydrive_retry(file1.Upload, {"convert": True})

            # Download as string.
            downloaded_content_no_bom = file1.GetContentString(
                mimetype="text/plain", remove_bom=True)
            downloaded_content_no_bom = test_util.StripNewlines(
                downloaded_content_no_bom)
            self.assertEqual(original_file_content, downloaded_content_no_bom)

            # Download as file.
            pydrive_retry(file1.GetContentFile,
                          downloaded_file_name,
                          remove_bom=True)
            downloaded_content = open(downloaded_file_name).read()
            downloaded_content = test_util.StripNewlines(downloaded_content)
            self.assertEqual(original_file_content, downloaded_content)

        finally:
            self.cleanup_gfile_conversion_test(file1, file_name,
                                               downloaded_file_name)
Exemplo n.º 5
0
    def test_Gfile_Conversion_Add_Remove_BOM(self):
        """Tests whether you can switch between the BOM appended and removed
    version on the fly."""
        (
            file1,
            file_name,
            original_file_content,
            downloaded_file_name,
        ) = self.setup_gfile_conversion_test()
        try:
            file1.SetContentFile(file_name)
            pydrive_retry(lambda: file1.Upload({"convert": True}))

            content_bom = file1.GetContentString(mimetype="text/plain")
            content_no_bom = file1.GetContentString(mimetype="text/plain",
                                                    remove_bom=True)
            content_bom_2 = file1.GetContentString(mimetype="text/plain")

            self.assertEqual(content_bom, content_bom_2)
            self.assertNotEqual(content_bom, content_no_bom)
            self.assertTrue(len(content_bom) > len(content_no_bom))

        finally:
            self.cleanup_gfile_conversion_test(file1, file_name,
                                               downloaded_file_name)
Exemplo n.º 6
0
    def test_09_Files_Update_File(self):
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        filename = self.getTempFile("preupdatetestfile")
        newfilename = self.getTempFile("updatetestfile")
        contentFile = self.getTempFile("actual_content", "some string")
        contentFile2 = self.getTempFile("actual_content_2", "some string")

        file1["title"] = filename
        file1.SetContentFile(contentFile)
        pydrive_retry(file1.Upload)  # Files.insert
        self.assertEqual(file1.metadata["title"], filename)

        pydrive_retry(
            file1.FetchContent)  # Force download and double check content.
        fileOut = self.getTempFile()
        pydrive_retry(file1.GetContentFile, fileOut)
        self.assertEqual(filecmp.cmp(contentFile, fileOut), True)

        file1["title"] = newfilename
        file1.SetContentFile(contentFile2)
        pydrive_retry(file1.Upload)  # Files.update
        self.assertEqual(file1.metadata["title"], newfilename)

        fileOut = self.getTempFile()
        pydrive_retry(file1.GetContentFile, fileOut)
        self.assertEqual(filecmp.cmp(contentFile2, fileOut), True)

        self.DeleteUploadedFiles(drive, [file1["id"]])
Exemplo n.º 7
0
    def test_GFile_Conversion_Lossless_String(self):
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()

        # Upload a string, and convert into Google Doc format.
        test_string = "Generic, non-exhaustive ASCII test string."
        file1.SetContentString(test_string)
        pydrive_retry(file1.Upload, {"convert": True})

        # Download string as plain text.
        downloaded_string = file1.GetContentString(mimetype="text/plain")
        self.assertEqual(test_string, downloaded_string,
                         "Strings do not match")

        # Download content into file and ensure that file content matches original
        # content string.
        downloaded_file_name = "_tmp_downloaded_file_name.txt"
        pydrive_retry(
            file1.GetContentFile,
            downloaded_file_name,
            mimetype="text/plain",
            remove_bom=True,
        )
        downloaded_string = open(downloaded_file_name).read()
        self.assertEqual(test_string, downloaded_string,
                         "Strings do not match")

        # Delete temp file.
        delete_file(downloaded_file_name)
Exemplo n.º 8
0
    def test_UpdateMetadataNotInfinitelyNesting(self):
        # Verify 'metadata' field present.
        self.assertTrue(self.file1.metadata is not None)
        pydrive_retry(self.file1.UpdateMetadata)

        # Verify 'metadata' field still present.
        self.assertTrue(self.file1.metadata is not None)
        # Ensure no 'metadata' field in 'metadata' (i.e. nested).
        self.assertTrue('metadata' not in self.file1.metadata)
Exemplo n.º 9
0
    def setUp(self):
        title = test_util.CreateRandomFileName()
        file_list = []
        for x in range(0, 10):
            file1 = self.drive.CreateFile()
            file1['title'] = title
            pydrive_retry(file1.Upload)
            file_list.append(file1)

        self.title = title
        self.file_list = file_list
Exemplo n.º 10
0
  def test_02_Files_Insert_Unicode(self):
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()
    filename = u'첫번째 파일'
    file1['title'] = filename
    pydrive_retry(file1.Upload)  # Files.insert

    self.assertEqual(file1.metadata['title'], filename)
    file2 = drive.CreateFile({'id': file1['id']})  # Download file from id.
    self.assertEqual(file2['title'], filename)

    self.DeleteUploadedFiles(drive, [file1['id']])
Exemplo n.º 11
0
  def test_Files_Get_Permissions(self):
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()
    pydrive_retry(file1.Upload)

    self.assertFalse('permissions' in file1)

    permissions = pydrive_retry(file1.GetPermissions)
    self.assertTrue(permissions is not None)
    self.assertTrue('permissions' in file1)

    pydrive_retry(file1.Delete)
Exemplo n.º 12
0
    def test_02_Files_Insert_Unicode(self):
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        filename = self.getTempFile(u"첫번째 파일")
        file1["title"] = filename
        pydrive_retry(file1.Upload)  # Files.insert

        self.assertEqual(file1.metadata["title"], filename)
        file2 = drive.CreateFile({"id": file1["id"]})  # Download file from id.
        self.assertEqual(file2["title"], filename)

        self.DeleteUploadedFiles(drive, [file1["id"]])
Exemplo n.º 13
0
    def test_Files_Insert_Permission(self):
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        pydrive_retry(file1.Upload)

        # Verify only one permission before inserting permission.
        permissions = pydrive_retry(file1.GetPermissions)
        self.assertEqual(len(permissions), 1)
        self.assertEqual(len(file1["permissions"]), 1)

        # Insert the permission.
        permission = pydrive_retry(
            file1.InsertPermission,
            {
                "type": "anyone",
                "value": "anyone",
                "role": "reader"
            },
        )
        self.assertTrue(permission)
        self.assertEqual(len(file1["permissions"]), 2)
        self.assertEqual(file1["permissions"][0]["type"], "anyone")

        permissions = pydrive_retry(file1.GetPermissions)
        self.assertEqual(len(file1["permissions"]), 2)
        self.assertEqual(file1["permissions"][0]["type"], "anyone")
        self.assertEqual(permissions[0]["type"], "anyone")

        # Verify remote changes made.
        file2 = drive.CreateFile({"id": file1["id"]})
        permissions = pydrive_retry(file2.GetPermissions)
        self.assertEqual(len(permissions), 2)
        self.assertEqual(permissions[0]["type"], "anyone")

        pydrive_retry(file1.Delete)
Exemplo n.º 14
0
    def test_12_Upload_Download_Empty_File(self):
        filename = os.path.join(self.tmpdir, str(time()))
        create_file(filename, "")

        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        file1.SetContentFile(filename)
        pydrive_retry(file1.Upload)

        fileOut1 = self.getTempFile()
        pydrive_retry(file1.GetContentFile, fileOut1)
        self.assertEqual(os.path.getsize(fileOut1), 0)

        self.DeleteUploadedFiles(drive, [file1["id"]])
Exemplo n.º 15
0
  def test_Files_Insert_Permission(self):
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()
    pydrive_retry(file1.Upload)

    # Verify only one permission before inserting permission.
    permissions = pydrive_retry(file1.GetPermissions)
    self.assertEqual(len(permissions), 1)
    self.assertEqual(len(file1['permissions']), 1)

    # Insert the permission.
    permission = pydrive_retry(lambda: file1.InsertPermission({'type': 'anyone',
                            'value': 'anyone',
                            'role': 'reader'}))
    self.assertTrue(permission)
    self.assertEqual(len(file1["permissions"]), 2)
    self.assertEqual(file1["permissions"][0]["type"], "anyone")

    permissions = pydrive_retry(file1.GetPermissions)
    self.assertEqual(len(file1["permissions"]), 2)
    self.assertEqual(file1["permissions"][0]["type"], "anyone")
    self.assertEqual(permissions[0]["type"], "anyone")

    # Verify remote changes made.
    file2 = drive.CreateFile({'id': file1['id']})
    permissions = pydrive_retry(file2.GetPermissions)
    self.assertEqual(len(permissions), 2)
    self.assertEqual(permissions[0]["type"], "anyone")

    pydrive_retry(file1.Delete)
Exemplo n.º 16
0
    def test_05_Files_Insert_Content_File(self):
        delete_file(self.first_file + "1")
        delete_file(self.first_file + "2")
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        filename = "filecontent"
        file1["title"] = filename
        file1.SetContentFile(self.first_file)
        pydrive_retry(file1.Upload)  # Files.insert

        self.assertEqual(file1.metadata["title"], filename)
        pydrive_retry(
            file1.FetchContent)  # Force download and double check content.
        pydrive_retry(lambda: file1.GetContentFile(self.first_file + "1"))
        self.assertEqual(filecmp.cmp(self.first_file, self.first_file + "1"),
                         True)

        file2 = drive.CreateFile({"id": file1["id"]})  # Download file from id.
        pydrive_retry(lambda: file2.GetContentFile(self.first_file + "2"))
        self.assertEqual(filecmp.cmp(self.first_file, self.first_file + "2"),
                         True)

        self.DeleteUploadedFiles(drive, [file1["id"]])
        delete_file(self.first_file + "1")
        delete_file(self.first_file + "2")
Exemplo n.º 17
0
    def test_File_List_Folders(self):
        drive = GoogleDrive(self.ga)
        folder1 = drive.CreateFile({
            'mimeType': 'application/vnd.google-apps.folder',
            'title': self.title
        })
        pydrive_retry(folder1.Upload)
        self.file_list.append(folder1)
        query = "title = '{}' and trashed = false".format(self.title)
        count = 0
        for file1 in pydrive_list_item(drive, query):
            self.assertFileInFileList(file1)
            count += 1

        self.assertTrue(count == 11)
Exemplo n.º 18
0
    def _parallel_uploader(self,
                           num_of_uploads,
                           num_of_workers,
                           use_per_thread_http=False):
        drive = GoogleDrive(self.ga)
        thread_pool = ThreadPoolExecutor(max_workers=num_of_workers)

        # Create list of gdrive_files.
        upload_files = []
        remote_name = test_util.CreateRandomFileName()
        for i in range(num_of_uploads):
            file_name = self.first_file if i % 2 == 0 else self.second_file
            up_file = drive.CreateFile()
            up_file["title"] = remote_name
            up_file.SetContentFile(file_name)
            upload_files.append(up_file)

        # Ensure there are no files with the random file name.
        files = pydrive_retry(lambda: drive.ListFile(
            param={
                "q": "title = '%s' and trashed = false" % remote_name
            }).GetList())
        self.assertTrue(len(files) == 0)

        # Submit upload jobs to ThreadPoolExecutor.
        futures = []
        for i in range(num_of_uploads):
            upload_worker = self.UploadWorker(upload_files[i],
                                              use_per_thread_http)
            futures.append(thread_pool.submit(upload_worker.run))

        # Ensure that all threads a) return, and b) encountered no exceptions.
        for future in as_completed(futures):
            self.assertIsNone(future.exception())
        thread_pool.shutdown()

        # Ensure all files were uploaded.
        files = pydrive_retry(lambda: drive.ListFile(
            param={
                "q": "title = '%s' and trashed = false" % remote_name
            }).GetList())
        self.assertTrue(len(files) == self.FILE_UPLOAD_COUNT)

        # Remove uploaded files.
        self.DeleteUploadedFiles(drive, [fi["id"] for fi in upload_files])
Exemplo n.º 19
0
    def _parallel_uploader(self, num_of_uploads, num_of_workers):
        """
        :returns: list[str] of file IDs
        """
        drive = GoogleDrive(self.ga)
        thread_pool = ThreadPoolExecutor(max_workers=num_of_workers)
        first_file = self.getTempFile("first_file", "some string")
        second_file = self.getTempFile("second_file", "another string")

        # Create list of gdrive_files.
        upload_files = []
        remote_name = test_util.CreateRandomFileName()
        for i in range(num_of_uploads):
            file_name = first_file if i % 2 == 0 else second_file
            up_file = drive.CreateFile()
            up_file["title"] = remote_name
            up_file.SetContentFile(file_name)
            upload_files.append(up_file)

        # Ensure there are no files with the random file name.
        files = pydrive_retry(lambda: drive.ListFile(
            param={
                "q": "title = '%s' and trashed = false" % remote_name
            }).GetList())
        self.assertTrue(len(files) == 0)

        # Submit upload jobs to ThreadPoolExecutor.
        futures = []
        for up_file in upload_files:
            futures.append(thread_pool.submit(pydrive_retry, up_file.Upload))

        # Ensure that all threads a) return, and b) encountered no exceptions.
        for future in as_completed(futures):
            self.assertIsNone(future.exception())
        thread_pool.shutdown()

        # Ensure all files were uploaded.
        files = pydrive_retry(lambda: drive.ListFile(
            param={
                "q": "title = '%s' and trashed = false" % remote_name
            }).GetList())
        self.assertTrue(len(files) == self.FILE_UPLOAD_COUNT)

        return [fi["id"] for fi in upload_files]
Exemplo n.º 20
0
    def test_11_Files_Get_Content_Buffer(self):
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        filename = self.getTempFile()
        content = "hello world!\ngoodbye, cruel world!"
        file1["title"] = filename
        file1.SetContentString(content)
        pydrive_retry(file1.Upload)  # Files.insert

        buffer1 = pydrive_retry(file1.GetContentIOBuffer)
        self.assertEqual(file1.metadata["title"], filename)
        self.assertEqual(len(buffer1), len(content))
        self.assertEqual(b"".join(iter(buffer1)).decode("ascii"), content)

        buffer2 = pydrive_retry(file1.GetContentIOBuffer, encoding="ascii")
        self.assertEqual(len(buffer2), len(content))
        self.assertEqual("".join(iter(buffer2)), content)

        self.DeleteUploadedFiles(drive, [file1["id"]])
Exemplo n.º 21
0
    def test_07_Files_Patch_Skipping_Content(self):
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        filename = self.getTempFile("prepatchtestfile")
        newfilename = self.getTempFile("patchtestfile")
        content = "hello world!"

        file1["title"] = filename
        file1.SetContentString(content)
        pydrive_retry(file1.Upload)  # Files.insert
        self.assertEqual(file1.metadata["title"], filename)

        file1["title"] = newfilename
        pydrive_retry(file1.Upload)  # Files.patch
        self.assertEqual(file1.metadata["title"], newfilename)
        self.assertEqual(file1.GetContentString(), content)
        self.assertEqual(file1.GetContentString(), content)

        self.DeleteUploadedFiles(drive, [file1["id"]])
Exemplo n.º 22
0
  def test_07_Files_Patch_Skipping_Content(self):
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()
    filename = 'prepatchtestfile'
    newfilename = 'patchtestfile'
    content = 'hello world!'

    file1['title'] = filename
    file1.SetContentString(content)
    pydrive_retry(file1.Upload)  # Files.insert
    self.assertEqual(file1.metadata['title'], filename)

    file1['title'] = newfilename
    pydrive_retry(file1.Upload)  # Files.patch
    self.assertEqual(file1.metadata['title'], newfilename)
    self.assertEqual(file1.GetContentString(), content)
    self.assertEqual(file1.GetContentString(), content)

    self.DeleteUploadedFiles(drive, [file1['id']])
Exemplo n.º 23
0
  def test_Files_Delete_Permission(self):
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()
    pydrive_retry(file1.Upload)
    pydrive_retry(lambda: file1.InsertPermission({'type': 'anyone',
                            'value': 'anyone',
                            'role': 'reader'}))
    permissions = pydrive_retry(file1.GetPermissions)
    self.assertEqual(len(permissions), 2)
    self.assertEqual(len(file1['permissions']), 2)

    pydrive_retry(lambda: file1.DeletePermission(permissions[0]['id']))
    self.assertEqual(len(file1['permissions']), 1)

    # Verify remote changes made.
    file2 = drive.CreateFile({'id': file1['id']})
    permissions = pydrive_retry(file2.GetPermissions)
    self.assertEqual(len(permissions), 1)

    pydrive_retry(file1.Delete)
Exemplo n.º 24
0
  def test_Files_UnTrash_File(self):
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()
    pydrive_retry(file1.Upload)
    pydrive_retry(file1.Trash)
    self.assertTrue(file1.metadata[u'labels'][u'trashed'])

    # Verify that file is trashed by downloading metadata.
    file2 = drive.CreateFile({'id': file1['id']})
    pydrive_retry(file2.FetchMetadata)
    self.assertTrue(file2.metadata[u'labels'][u'trashed'])

    # Un-trash the file, and assert local metadata is updated correctly.
    pydrive_retry(file1.UnTrash)
    self.assertFalse(file1.metadata[u'labels'][u'trashed'])

    # Re-fetch the metadata, and assert file un-trashed on GDrive.
    pydrive_retry(file2.FetchMetadata)
    self.assertFalse(file2.metadata[u'labels'][u'trashed'])

    self.DeleteUploadedFiles(drive, [file1['id']])
Exemplo n.º 25
0
    def test_10_Files_Download_Service(self):
        """
        Tests that a fresh GoogleDrive object can correctly authenticate
        and download from a file ID.
        """
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        filename = self.getTempFile("prepatchtestfile")
        content = "hello world!"

        file1["title"] = filename
        file1.SetContentString(content)
        pydrive_retry(file1.Upload)  # Files.insert
        self.assertEqual(file1.metadata["title"], filename)
        fileOut1 = self.getTempFile()
        pydrive_retry(file1.GetContentFile, fileOut1)

        # fresh download-only instance
        auth = GoogleAuth(
            settings_file_path("default.yaml", os.path.join(self.tmpdir, "")))
        auth.ServiceAuth()
        drive2 = GoogleDrive(auth)
        file2 = drive2.CreateFile({"id": file1["id"]})
        fileOut2 = self.getTempFile()
        pydrive_retry(file2.GetContentFile, fileOut2)
        self.assertEqual(filecmp.cmp(fileOut1, fileOut2), True)

        self.DeleteUploadedFiles(drive, [file1["id"]])
Exemplo n.º 26
0
    def test_08_Files_Update_String(self):
        drive = GoogleDrive(self.ga)
        file1 = drive.CreateFile()
        filename = self.getTempFile("preupdatetestfile")
        newfilename = self.getTempFile("updatetestfile")
        content = "hello world!"
        newcontent = "hello new world!"

        file1["title"] = filename
        file1.SetContentString(content)
        pydrive_retry(file1.Upload)  # Files.insert
        self.assertEqual(file1.metadata["title"], filename)
        self.assertEqual(file1.GetContentString(), content)

        pydrive_retry(
            file1.FetchContent)  # Force download and double check content.
        self.assertEqual(file1.GetContentString(), content)

        file1["title"] = newfilename
        file1.SetContentString(newcontent)
        pydrive_retry(file1.Upload)  # Files.update
        self.assertEqual(file1.metadata["title"], newfilename)
        self.assertEqual(file1.GetContentString(), newcontent)
        self.assertEqual(file1.GetContentString(), newcontent)

        self.DeleteUploadedFiles(drive, [file1["id"]])
Exemplo n.º 27
0
  def test_08_Files_Update_String(self):
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()
    filename = 'preupdatetestfile'
    newfilename = 'updatetestfile'
    content = 'hello world!'
    newcontent = 'hello new world!'

    file1['title'] = filename
    file1.SetContentString(content)
    pydrive_retry(file1.Upload)  # Files.insert
    self.assertEqual(file1.metadata['title'], filename)
    self.assertEqual(file1.GetContentString(), content)

    pydrive_retry(file1.FetchContent)  # Force download and double check content.
    self.assertEqual(file1.GetContentString(), content)

    file1['title'] = newfilename
    file1.SetContentString(newcontent)
    pydrive_retry(file1.Upload)  # Files.update
    self.assertEqual(file1.metadata['title'], newfilename)
    self.assertEqual(file1.GetContentString(), newcontent)
    self.assertEqual(file1.GetContentString(), newcontent)

    self.DeleteUploadedFiles(drive, [file1['id']])
Exemplo n.º 28
0
  def test_Files_UnTrash_File_Just_ID(self):
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()
    pydrive_retry(file1.Upload)
    pydrive_retry(file1.Trash)
    self.assertTrue(file1.metadata[u'labels'][u'trashed'])

    file2 = drive.CreateFile({'id': file1['id']})
    pydrive_retry(file2.UnTrash)  # UnTrash without fetching metadata.

    pydrive_retry(file1.FetchMetadata)
    self.assertFalse(file1.metadata[u'labels'][u'trashed'])

    self.DeleteUploadedFiles(drive, [file1['id']])
Exemplo n.º 29
0
  def test_09_Files_Update_File(self):
    delete_file(self.first_file+'1')
    delete_file(self.second_file+'1')
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()
    filename = 'preupdatetestfile'
    newfilename = 'updatetestfile'

    file1['title'] = filename
    file1.SetContentFile(self.first_file)
    pydrive_retry(file1.Upload)  # Files.insert
    self.assertEqual(file1.metadata['title'], filename)

    pydrive_retry(file1.FetchContent)  # Force download and double check content.
    file1.GetContentFile(self.first_file+'1')
    self.assertEqual(filecmp.cmp(self.first_file, self.first_file+'1'), True)

    file1['title'] = newfilename
    file1.SetContentFile(self.second_file)
    pydrive_retry(file1.Upload)  # Files.update
    self.assertEqual(file1.metadata['title'], newfilename)
    file1.GetContentFile(self.second_file+'1')
    self.assertEqual(filecmp.cmp(self.second_file, self.second_file+'1'), True)

    self.DeleteUploadedFiles(drive, [file1['id']])

    delete_file(self.first_file + '1')
    delete_file(self.second_file + '1')
Exemplo n.º 30
0
  def test_Files_FetchMetadata_Fields(self):
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()
    pydrive_retry(file1.Upload)

    self.assertFalse('permissions' in file1)

    pydrive_retry(lambda: file1.FetchMetadata('permissions'))
    self.assertTrue('permissions' in file1)
    pydrive_retry(file1.Delete)