Skip to content

Commit b909288

Browse files
committed
test: Add tests to exercise keyring backend priority
1 parent 176d24d commit b909288

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/artifacts-helper/codespaces_artifacts_helper_keyring/tests/test_keyring_backend.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
import keyring
24
import keyring.backend
35
import keyring.backends.chainer
@@ -7,6 +9,7 @@
79
ArtifactsHelperCredentialProvider,
810
CodespacesArtifactsHelperKeyringBackend,
911
)
12+
from jaraco.classes import properties
1013

1114
# Shouldn't be accessed by tests, but needs to be able
1215
# to get past the quick check.
@@ -139,3 +142,44 @@ def test_cannot_delete_password(passwords, fake_provider):
139142

140143
with pytest.raises(keyring.errors.PasswordDeleteError):
141144
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

Comments
 (0)