|
| 1 | +import json |
1 | 2 | import os
|
2 | 3 | import time
|
3 | 4 | import pytest
|
|
7 | 8 | setup_credentials,
|
8 | 9 | delete_file,
|
9 | 10 | settings_file_path,
|
| 11 | + GDRIVE_USER_CREDENTIALS_DATA, |
10 | 12 | )
|
11 | 13 | from oauth2client.file import Storage
|
12 | 14 |
|
@@ -152,6 +154,40 @@ def test_10_ServiceAuthFromSavedCredentialsDictionary():
|
152 | 154 | time.sleep(1)
|
153 | 155 |
|
154 | 156 |
|
| 157 | +def test_11_ServiceAuthFromJsonNoCredentialsSaving(): |
| 158 | + client_json = os.environ[GDRIVE_USER_CREDENTIALS_DATA] |
| 159 | + settings = { |
| 160 | + "client_config_backend": "service", |
| 161 | + "service_config": { |
| 162 | + "client_json": client_json, |
| 163 | + }, |
| 164 | + "oauth_scope": ["https://www.googleapis.com/auth/drive"], |
| 165 | + } |
| 166 | + # Test that no credentials are saved and API is still functional |
| 167 | + # We are testing that there are no exceptions at least |
| 168 | + ga = GoogleAuth(settings=settings) |
| 169 | + assert not ga.settings["save_credentials"] |
| 170 | + ga.ServiceAuth() |
| 171 | + time.sleep(1) |
| 172 | + |
| 173 | + |
| 174 | +def test_12_ServiceAuthFromJsonDictNoCredentialsSaving(): |
| 175 | + client_json_dict = json.loads(os.environ[GDRIVE_USER_CREDENTIALS_DATA]) |
| 176 | + settings = { |
| 177 | + "client_config_backend": "service", |
| 178 | + "service_config": { |
| 179 | + "client_json_dict": client_json_dict, |
| 180 | + }, |
| 181 | + "oauth_scope": ["https://www.googleapis.com/auth/drive"], |
| 182 | + } |
| 183 | + # Test that no credentials are saved and API is still functional |
| 184 | + # We are testing that there are no exceptions at least |
| 185 | + ga = GoogleAuth(settings=settings) |
| 186 | + assert not ga.settings["save_credentials"] |
| 187 | + ga.ServiceAuth() |
| 188 | + time.sleep(1) |
| 189 | + |
| 190 | + |
155 | 191 | def CheckCredentialsFile(credentials, no_file=False):
|
156 | 192 | ga = GoogleAuth(settings_file_path("test_oauth_default.yaml"))
|
157 | 193 | ga.LoadCredentialsFile(credentials)
|
|
0 commit comments