def test_07_ServiceAuthFromSavedCredentialsJsonFile(self): # Have an initial auth so that credentials/7.dat gets saved ga = GoogleAuth(settings_file_path("test_oauth_test_07.yaml")) ga.ServiceAuth() self.assertTrue(os.path.exists(ga.settings["save_credentials_file"])) # Secondary auth should be made only using the previously saved # login info ga = GoogleAuth(settings_file_path("test_oauth_test_07.yaml")) ga.ServiceAuth() self.assertEqual(ga.access_token_expired, False) time.sleep(1)
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"]])
def setup_class(cls): setup_credentials() cls.tmpdir = mkdtemp() cls.ga = GoogleAuth( settings_file_path("default.yaml", os.path.join(cls.tmpdir, ""))) cls.ga.ServiceAuth()
def setup_class(cls): setup_credentials() create_file(cls.first_file, cls.first_file) create_file(cls.second_file, cls.second_file) cls.ga = GoogleAuth(settings_file_path("default.yaml")) cls.ga.ServiceAuth()
def test_04_CommandLineAuthWithClientConfigFromFile(self): # Delete old credentials file delete_file("credentials/4.dat") # Test if authentication works with config read from file ga = GoogleAuth(settings_file_path("test_oauth_test_04.yaml")) ga.CommandLineAuth() self.assertEqual(ga.access_token_expired, False) # Test if correct credentials file is created self.CheckCredentialsFile("credentials/4.dat") time.sleep(1)
def test_03_LocalWebServerAuthWithNoCredentialsSaving(self): # Delete old credentials file delete_file("credentials/3.dat") # Provide wrong credentials file ga = GoogleAuth(settings_file_path("test_oauth_test_03.yaml")) ga.LocalWebserverAuth() self.assertEqual(ga.access_token_expired, False) # Test if correct credentials file is created self.CheckCredentialsFile("credentials/3.dat", no_file=True) time.sleep(1)
def test_02_LocalWebserverAuthWithClientConfigFromSettings(self): # Delete old credentials file delete_file("credentials/2.dat") # Test if authentication works with config read from settings ga = GoogleAuth(settings_file_path("test_oauth_test_02.yaml")) ga.LocalWebserverAuth() self.assertEqual(ga.access_token_expired, False) # Test if correct credentials file is created self.CheckCredentialsFile("credentials/2.dat") time.sleep(1)
def fs(tmpdir, base_remote_dir): setup_credentials() auth = GoogleAuth(settings_file_path("default.yaml", tmpdir / "")) auth.ServiceAuth() bucket, base = base_remote_dir.split("/", 1) fs = GDriveFileSystem(base_remote_dir, auth) fs._gdrive_create_dir("root", base) return fs
def CheckCredentialsFile(self, credentials, no_file=False): ga = GoogleAuth(settings_file_path("test_oauth_default.yaml")) ga.LoadCredentialsFile(credentials) self.assertEqual(ga.access_token_expired, no_file)
def test_06_ServiceAuthFromSavedCredentialsP12File(self): setup_credentials("credentials/6.dat") ga = GoogleAuth(settings_file_path("test_oauth_test_06.yaml")) ga.ServiceAuth() self.assertEqual(ga.access_token_expired, False) time.sleep(1)
def test_05_ConfigFromSettingsWithoutOauthScope(self): # Test if authentication works without oauth_scope ga = GoogleAuth(settings_file_path("test_oauth_test_05.yaml")) ga.LocalWebserverAuth() self.assertEqual(ga.access_token_expired, False) time.sleep(1)
def setUp(self): ga = GoogleAuth(settings_file_path("default.yaml")) ga.ServiceAuth() self.drive = GoogleDrive(ga) self.file1 = self.drive.CreateFile() pydrive_retry(self.file1.Upload)
def setup_class(cls): setup_credentials() cls.ga = GoogleAuth(settings_file_path("default.yaml")) cls.ga.ServiceAuth() cls.drive = GoogleDrive(cls.ga)