Skip to content

Commit 3945fac

Browse files
committed
test fix-163: thread safe auth on load and save credentials
1 parent 84311eb commit 3945fac

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
client_config_backend: service
2+
service_config:
3+
client_json_file_path: /tmp/pydrive2/credentials.json
4+
5+
save_credentials: False
6+
7+
oauth_scope:
8+
- https://www.googleapis.com/auth/drive
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
client_config_backend: service
2+
service_config:
3+
client_json_file_path: /tmp/pydrive2/credentials.json
4+
5+
save_credentials: True
6+
save_credentials_backend: file
7+
save_credentials_file: credentials/9.dat
8+
9+
oauth_scope:
10+
- https://www.googleapis.com/auth/drive

pydrive2/test/test_oauth.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
delete_file,
99
settings_file_path,
1010
)
11+
from oauth2client.file import Storage
1112

1213

1314
def setup_module(module):
@@ -99,6 +100,31 @@ def test_07_ServiceAuthFromSavedCredentialsJsonFile():
99100
time.sleep(1)
100101

101102

103+
def test_08_ServiceAuthFromJsonFileNoCredentialsSaving():
104+
# Test that no credentials are saved and API is still functional
105+
# We are testing that there are no exceptions at least
106+
ga = GoogleAuth(settings_file_path("test_oauth_test_08.yaml"))
107+
assert not ga.settings["save_credentials"]
108+
ga.ServiceAuth()
109+
time.sleep(1)
110+
111+
112+
def test_09_SaveLoadCredentialsUsesDefaultStorage(mocker):
113+
# Test fix for https://github.com/iterative/PyDrive2/issues/163
114+
# Make sure that Load and Save credentials by default reuse the
115+
# same Storage (since it defined lock which make it TS)
116+
ga = GoogleAuth(settings_file_path("test_oauth_test_09.yaml"))
117+
credentials_file = ga.settings["save_credentials_file"]
118+
# Delete old credentials file
119+
delete_file(credentials_file)
120+
assert not os.path.exists(credentials_file)
121+
spy = mocker.spy(Storage, "__init__")
122+
ga.ServiceAuth()
123+
ga.LoadCredentials()
124+
ga.SaveCredentials()
125+
assert spy.call_count == 0
126+
127+
102128
def CheckCredentialsFile(credentials, no_file=False):
103129
ga = GoogleAuth(settings_file_path("test_oauth_default.yaml"))
104130
ga.LoadCredentialsFile(credentials)

0 commit comments

Comments
 (0)