|
18 | 18 | def section(): |
19 | 19 | return 'test' |
20 | 20 |
|
| 21 | +@pytest.fixture |
| 22 | +def use_cache(): |
| 23 | + return None |
| 24 | + |
21 | 25 |
|
22 | 26 | @pytest.fixture |
23 | | -def credentials_path(tmp_path, section): |
| 27 | +def credentials_path(tmp_path, section, use_cache): |
24 | 28 | credentials_path = tmp_path / 'credentials.json' |
25 | | - credentials_path.write_text(json.dumps({ |
| 29 | + credentials_dict = { |
26 | 30 | section: { |
27 | 31 | 'client_id': 'test', |
28 | 32 | 'auth_endpoint': 'test', |
29 | 33 | 'api_endpoint': 'test', |
30 | 34 | 'client_secret': 'test', |
31 | 35 | } |
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)) |
33 | 40 | return credentials_path |
34 | 41 |
|
35 | 42 |
|
@@ -97,20 +104,17 @@ def test_credentials_with_cache(cache_path, token, section): |
97 | 104 | assert credentials._token == (token['access_token'], token['expires_in']) |
98 | 105 | assert credentials.cached_profile == section |
99 | 106 |
|
100 | | - |
| 107 | +@pytest.mark.parametrize('use_cache', [True]) |
101 | 108 | def test_read_from_file_with_cache(credentials_path, section, token, cache_path): |
102 | 109 | 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') |
104 | 110 | args = read_from_file(str(credentials_path), section) |
105 | | - |
106 | 111 | credentials = Credentials(*args, cache_path=cache_path) |
107 | 112 | assert credentials.cached_profile == section |
108 | 113 | assert credentials._token == (token['access_token'], token['expires_in']) |
109 | 114 |
|
110 | | - |
| 115 | +@pytest.mark.parametrize('use_cache', [False]) |
111 | 116 | def test_read_from_file_with_no_cache(credentials_path, section, token, cache_path): |
112 | 117 | 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') |
114 | 118 | args = read_from_file(str(credentials_path), section) |
115 | 119 |
|
116 | 120 | credentials = Credentials(*args, cache_path=cache_path) |
|
0 commit comments