Skip to content

Commit 57fd14d

Browse files
committed
fix credentials tests
1 parent 47b8657 commit 57fd14d

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/cradl/credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def read_from_file(credentials_path: str = expanduser('~/.cradl/credentials.json
145145
client_secret = credentials.get('client_secret')
146146
auth_endpoint = credentials.get('auth_endpoint')
147147
api_endpoint = credentials.get('api_endpoint')
148-
cached_profile = profile if credentials.get('use_cache', fallback=False) in ['true', 'True'] else None
148+
cached_profile = profile if credentials.get('use_cache', False) else None
149149

150150
return [client_id, client_secret, auth_endpoint, api_endpoint, cached_profile]
151151

tests/test_credentials.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,25 @@
1818
def section():
1919
return 'test'
2020

21+
@pytest.fixture
22+
def use_cache():
23+
return None
24+
2125

2226
@pytest.fixture
23-
def credentials_path(tmp_path, section):
27+
def credentials_path(tmp_path, section, use_cache):
2428
credentials_path = tmp_path / 'credentials.json'
25-
credentials_path.write_text(json.dumps({
29+
credentials_dict = {
2630
section: {
2731
'client_id': 'test',
2832
'auth_endpoint': 'test',
2933
'api_endpoint': 'test',
3034
'client_secret': 'test',
3135
}
32-
}))
36+
}
37+
if isinstance(use_cache, bool):
38+
credentials_dict[section]['use_cache'] = use_cache
39+
credentials_path.write_text(json.dumps(credentials_dict, indent=2))
3340
return credentials_path
3441

3542

@@ -97,20 +104,17 @@ def test_credentials_with_cache(cache_path, token, section):
97104
assert credentials._token == (token['access_token'], token['expires_in'])
98105
assert credentials.cached_profile == section
99106

100-
107+
@pytest.mark.parametrize('use_cache', [True])
101108
def test_read_from_file_with_cache(credentials_path, section, token, cache_path):
102109
write_token_to_cache(section, (token['access_token'], token['expires_in']), cache_path)
103-
credentials_path.write_text(credentials_path.read_text() + '\nuse_cache = true')
104110
args = read_from_file(str(credentials_path), section)
105-
106111
credentials = Credentials(*args, cache_path=cache_path)
107112
assert credentials.cached_profile == section
108113
assert credentials._token == (token['access_token'], token['expires_in'])
109114

110-
115+
@pytest.mark.parametrize('use_cache', [False])
111116
def test_read_from_file_with_no_cache(credentials_path, section, token, cache_path):
112117
write_token_to_cache(section, (token['access_token'], token['expires_in']), cache_path)
113-
credentials_path.write_text(credentials_path.read_text() + '\nuse_cache = false')
114118
args = read_from_file(str(credentials_path), section)
115119

116120
credentials = Credentials(*args, cache_path=cache_path)

0 commit comments

Comments
 (0)