Skip to content

Commit

Permalink
Add test for get_credential with no username.
Browse files Browse the repository at this point in the history
Captures missed expectation reported in #694
  • Loading branch information
jaraco committed Sep 20, 2024
1 parent 0041050 commit 41892e7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from keyring import cli
from keyring import credentials

flatten = itertools.chain.from_iterable

Expand Down Expand Up @@ -36,6 +37,12 @@ def mocked_set():
yield set_password


@pytest.fixture
def mocked_get_credential():
with mock.patch('keyring.cli.get_credential') as get_credential:
yield get_credential


def test_set_interactive(monkeypatch, mocked_set):
tool = cli.CommandLineTool()
tool.service = 'svc'
Expand Down Expand Up @@ -64,3 +71,16 @@ def test_set_pipe_newline(monkeypatch, mocked_set):
monkeypatch.setattr(sys.stdin, 'read', lambda: 'foo123\n')
tool.do_set()
mocked_set.assert_called_once_with('svc', 'usr', 'foo123')


@pytest.mark.xfail(reason="#694")
@pytest.mark.parametrize('format', ['json', 'plain'])
def test_get_anonymous(monkeypatch, mocked_get_credential, format, capsys):
mocked_get_credential.return_value = credentials.AnonymousCredential('s3cret')
tool = cli.CommandLineTool()
tool.service = 'svc'
tool.username = None
tool.get_mode = 'creds'
tool.output_format = format
tool.do_get()
assert 's3cret' in capsys.readouterr().out

0 comments on commit 41892e7

Please sign in to comment.