Skip to content

Commit f2de358

Browse files
committed
tests: oauth: add service_config.client_json tests
1 parent 1753e0d commit f2de358

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pydrive2/test/test_oauth.py

+36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import os
23
import time
34
import pytest
@@ -7,6 +8,7 @@
78
setup_credentials,
89
delete_file,
910
settings_file_path,
11+
GDRIVE_USER_CREDENTIALS_DATA,
1012
)
1113
from oauth2client.file import Storage
1214

@@ -152,6 +154,40 @@ def test_10_ServiceAuthFromSavedCredentialsDictionary():
152154
time.sleep(1)
153155

154156

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+
155191
def CheckCredentialsFile(credentials, no_file=False):
156192
ga = GoogleAuth(settings_file_path("test_oauth_default.yaml"))
157193
ga.LoadCredentialsFile(credentials)

0 commit comments

Comments
 (0)