|
| 1 | +from pathlib import Path |
| 2 | + |
1 | 3 | import keyring |
2 | 4 | import keyring.backend |
3 | 5 | import keyring.backends.chainer |
|
7 | 9 | ArtifactsHelperCredentialProvider, |
8 | 10 | CodespacesArtifactsHelperKeyringBackend, |
9 | 11 | ) |
| 12 | +from jaraco.classes import properties |
10 | 13 |
|
11 | 14 | # Shouldn't be accessed by tests, but needs to be able |
12 | 15 | # to get past the quick check. |
@@ -139,3 +142,44 @@ def test_cannot_delete_password(passwords, fake_provider): |
139 | 142 |
|
140 | 143 | with pytest.raises(keyring.errors.PasswordDeleteError): |
141 | 144 | keyring.delete_password(SUPPORTED_HOST + "1234", creds.username) |
| 145 | + |
| 146 | + |
| 147 | +def test_priority_when_helper_installed(monkeypatch): |
| 148 | + class MockProvider(ArtifactsHelperCredentialProvider): |
| 149 | + @staticmethod |
| 150 | + def resolve_auth_helper_path(auth_helper_path): |
| 151 | + return Path("fake-path") |
| 152 | + |
| 153 | + @properties.classproperty |
| 154 | + @classmethod |
| 155 | + def priority(cls) -> float: |
| 156 | + return True |
| 157 | + |
| 158 | + monkeypatch.setattr( |
| 159 | + CodespacesArtifactsHelperKeyringBackend, "_PROVIDER", MockProvider |
| 160 | + ) |
| 161 | + |
| 162 | + assert CodespacesArtifactsHelperKeyringBackend.priority == 10.0 |
| 163 | + assert CodespacesArtifactsHelperKeyringBackend().priority == 10.0 |
| 164 | + |
| 165 | + |
| 166 | +def test_priority_when_helper_not_installed(monkeypatch): |
| 167 | + class MockProvider(ArtifactsHelperCredentialProvider): |
| 168 | + @staticmethod |
| 169 | + def resolve_auth_helper_path(auth_helper_path): |
| 170 | + return None |
| 171 | + |
| 172 | + @properties.classproperty |
| 173 | + @classmethod |
| 174 | + def priority(cls) -> float: |
| 175 | + return False |
| 176 | + |
| 177 | + monkeypatch.setattr( |
| 178 | + CodespacesArtifactsHelperKeyringBackend, "_PROVIDER", MockProvider |
| 179 | + ) |
| 180 | + |
| 181 | + with pytest.raises(RuntimeError): |
| 182 | + assert not CodespacesArtifactsHelperKeyringBackend.priority |
| 183 | + |
| 184 | + with pytest.raises(RuntimeError): |
| 185 | + assert not CodespacesArtifactsHelperKeyringBackend().priority |
0 commit comments