mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 00:09:04 +00:00
Support listing all entry types
This commit is contained in:
@@ -16,7 +16,7 @@ from seedpass.core.entry_types import EntryType
|
||||
class DummyPM:
|
||||
def __init__(self):
|
||||
self.entry_manager = SimpleNamespace(
|
||||
list_entries=lambda sort_by="index", filter_kind=None, include_archived=False: [
|
||||
list_entries=lambda sort_by="index", filter_kinds=None, include_archived=False: [
|
||||
(1, "Label", "user", "url", False)
|
||||
],
|
||||
search_entries=lambda q, kinds=None: [
|
||||
|
@@ -30,8 +30,8 @@ class DummyEntries:
|
||||
self.data = [(1, "Example", None, None, False)]
|
||||
self.code = "111111"
|
||||
|
||||
def list_entries(self, sort_by="index", filter_kind=None, include_archived=False):
|
||||
if filter_kind:
|
||||
def list_entries(self, sort_by="index", filter_kinds=None, include_archived=False):
|
||||
if filter_kinds:
|
||||
return [(idx, label, None, None, False) for idx, label, *_ in self.data]
|
||||
return self.data
|
||||
|
||||
|
@@ -9,7 +9,7 @@ from seedpass_gui.app import MainWindow
|
||||
|
||||
|
||||
class DummyEntries:
|
||||
def list_entries(self, sort_by="index", filter_kind=None, include_archived=False):
|
||||
def list_entries(self, sort_by="index", filter_kinds=None, include_archived=False):
|
||||
return []
|
||||
|
||||
def search_entries(self, q):
|
||||
|
85
src/tests/test_list_entries_all_types.py
Normal file
85
src/tests/test_list_entries_all_types.py
Normal file
@@ -0,0 +1,85 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from types import SimpleNamespace
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from seedpass.cli import app as cli_app
|
||||
from seedpass.cli import entry as entry_cli
|
||||
from helpers import create_vault, TEST_SEED, TEST_PASSWORD
|
||||
from seedpass.core.backup import BackupManager
|
||||
from seedpass.core.config_manager import ConfigManager
|
||||
from seedpass.core.entry_management import EntryManager
|
||||
from seedpass.core.manager import PasswordManager, EncryptionMode
|
||||
|
||||
|
||||
def _setup_manager(tmp_path: Path) -> tuple[PasswordManager, EntryManager]:
|
||||
vault, enc_mgr = create_vault(tmp_path, TEST_SEED, TEST_PASSWORD)
|
||||
cfg_mgr = ConfigManager(vault, tmp_path)
|
||||
backup_mgr = BackupManager(tmp_path, cfg_mgr)
|
||||
entry_mgr = EntryManager(vault, backup_mgr)
|
||||
|
||||
pm = PasswordManager.__new__(PasswordManager)
|
||||
pm.encryption_mode = EncryptionMode.SEED_ONLY
|
||||
pm.encryption_manager = enc_mgr
|
||||
pm.vault = vault
|
||||
pm.entry_manager = entry_mgr
|
||||
pm.backup_manager = backup_mgr
|
||||
pm.parent_seed = TEST_SEED
|
||||
pm.nostr_client = SimpleNamespace()
|
||||
pm.fingerprint_dir = tmp_path
|
||||
pm.secret_mode_enabled = False
|
||||
return pm, entry_mgr
|
||||
|
||||
|
||||
def _create_all_entries(em: EntryManager) -> None:
|
||||
em.add_entry("pw", 8)
|
||||
em.add_totp("totp", TEST_SEED)
|
||||
em.add_ssh_key("ssh", TEST_SEED)
|
||||
em.add_seed("seed", TEST_SEED, words_num=12)
|
||||
em.add_nostr_key("nostr", TEST_SEED)
|
||||
em.add_pgp_key("pgp", TEST_SEED)
|
||||
em.add_key_value("kv", "k", "v")
|
||||
em.add_managed_account("acct", TEST_SEED)
|
||||
|
||||
|
||||
def test_cli_list_all_types(monkeypatch):
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
tmp_path = Path(tmpdir)
|
||||
pm, em = _setup_manager(tmp_path)
|
||||
_create_all_entries(em)
|
||||
|
||||
def fake_get_entry_service(_ctx):
|
||||
return SimpleNamespace(
|
||||
list_entries=lambda sort_by, filter_kinds, include_archived: pm.entry_manager.list_entries(
|
||||
sort_by=sort_by,
|
||||
filter_kinds=filter_kinds,
|
||||
include_archived=include_archived,
|
||||
)
|
||||
)
|
||||
|
||||
monkeypatch.setattr(entry_cli, "_get_entry_service", fake_get_entry_service)
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli_app, ["entry", "list"])
|
||||
assert result.exit_code == 0
|
||||
out = result.stdout
|
||||
for label in ["pw", "totp", "ssh", "seed", "nostr", "pgp", "kv", "acct"]:
|
||||
assert label in out
|
||||
|
||||
|
||||
def test_menu_list_all_types(monkeypatch, capsys):
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
tmp_path = Path(tmpdir)
|
||||
pm, em = _setup_manager(tmp_path)
|
||||
_create_all_entries(em)
|
||||
|
||||
inputs = iter(["1", "", ""]) # choose All then exit
|
||||
monkeypatch.setattr("builtins.input", lambda *_: next(inputs))
|
||||
|
||||
pm.handle_list_entries()
|
||||
out = capsys.readouterr().out
|
||||
for label in ["pw", "totp", "ssh", "seed", "nostr", "pgp", "kv", "acct"]:
|
||||
assert label in out
|
@@ -57,5 +57,5 @@ def test_filter_by_type():
|
||||
em = setup_entry_manager(tmp_path)
|
||||
em.add_entry("site", 8, "user")
|
||||
em.add_totp("Example", TEST_SEED)
|
||||
result = em.list_entries(filter_kind=EntryType.TOTP.value)
|
||||
result = em.list_entries(filter_kinds=[EntryType.TOTP.value])
|
||||
assert result == [(1, "Example", None, None, False)]
|
||||
|
@@ -18,8 +18,8 @@ runner = CliRunner()
|
||||
def test_entry_list(monkeypatch):
|
||||
called = {}
|
||||
|
||||
def list_entries(sort_by="index", filter_kind=None, include_archived=False):
|
||||
called["args"] = (sort_by, filter_kind, include_archived)
|
||||
def list_entries(sort_by="index", filter_kinds=None, include_archived=False):
|
||||
called["args"] = (sort_by, filter_kinds, include_archived)
|
||||
return [(0, "Site", "user", "", False)]
|
||||
|
||||
pm = SimpleNamespace(
|
||||
|
Reference in New Issue
Block a user