Exemple #1
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)
Exemple #2
0
  def setup_gfile_conversion_test(self):
    drive = GoogleDrive(self.ga)
    file1 = drive.CreateFile()

    # Create a file to upload.
    file_name = '_tmp_source_file.txt'
    downloaded_file_name = '_tmp_downloaded_file_name.txt'
    original_file_content = 'Generic, non-exhaustive\n ASCII test string.'
    source_file = open(file_name, mode='w+')
    source_file.write(original_file_content)
    source_file.close()
    original_file_content = test_util.StripNewlines(original_file_content)

    return file1, file_name, original_file_content, downloaded_file_name