Skip to content
Snippets Groups Projects
Commit a45f3a1a authored by Sebastian Mohr's avatar Sebastian Mohr
Browse files

Fixed a small issue with int parsing in cli

parent 9de4fd6c
Branches
No related tags found
No related merge requests found
Pipeline #512164 failed
......@@ -9,7 +9,7 @@ from .token import Token
def get_all_tokens(
keyring: Optional[keyring_store.KeyringBackend] = None,
files: Optional[file_store.Files] = None,
):
) -> tuple[list[Token], list[file_store.File]]:
"""
Get all tokens from all sources.
......
......@@ -93,7 +93,7 @@ def list():
for token, source in zip(tokens, sources):
table.add_row(
token.name,
token.book_id,
str(token.book_id),
token.deployment_url,
token.token,
str(source),
......
......@@ -117,7 +117,12 @@ def get_token(
The file or list of files to read the token from. Defaults to all default locations.
"""
raise NotImplementedError("Not implemented yet.")
tokens, sources = get_all_tokens(files)
for token, source in zip(tokens, sources):
if token.name == name:
log.debug(f"Found token '{name}' in file '{source}'.")
return token
return None
def token_exists(
......@@ -134,7 +139,7 @@ def token_exists(
The file or list of files to read the token from. Defaults to all default locations.
"""
raise NotImplementedError("Not implemented yet.")
return get_token(name, files) is not None
def __parse_files(
......
......@@ -35,12 +35,20 @@ def test_rm_token_nonexistent(monkeypatch, dummy_keyring, tokens):
assert "not found" in result.stdout
def test_list_tokens(monkeypatch, dummy_keyring, caplog):
def test_list_tokens(monkeypatch, dummy_keyring, caplog, tokens):
monkeypatch.setattr("snip.token.__main__.get_keyring", lambda: dummy_keyring)
result = runner.invoke(app, ["token", "list"])
assert result.exit_code == 0
assert "No tokens found!" in caplog.records[0].message
# Set some tokens
keyring_store.save_token(tokens[0], dummy_keyring)
result = runner.invoke(app, ["token", "list"])
assert result.exit_code == 0
assert "1" in result.stdout
assert "dep_1" in result.stdout
def test_list_no_keyring(monkeypatch, dummy_keyring, tokens):
monkeypatch.setattr("snip.token.__main__.get_keyring", lambda: None)
......
......@@ -45,6 +45,29 @@ class TestFileStore:
assert len(caplog.records) == 1
assert "Duplicate token names!" in caplog.records[0].message
def test_get_token(self, config_file):
config_file, compare_tokens = config_file
for token in compare_tokens:
t = file_store.get_token(token.name, [config_file])
assert t is not None
assert t.name == token.name
assert t.token == token.token
assert t.book_id == token.book_id
assert isinstance(t.deployment_url, str)
# Test not found
t = file_store.get_token("nonexistent", [config_file])
assert t is None
def test_exists(self, config_file):
config_file, compare_tokens = config_file
for token in compare_tokens:
assert file_store.token_exists(token.name, [config_file])
assert not file_store.token_exists("nonexistent", [config_file])
class TestKeyringStore:
def test_get_all_tokens(self, dummy_keyring, tokens):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment