mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 15:58:48 +00:00
Update CLI commands and add unit tests
This commit is contained in:
@@ -139,7 +139,12 @@ def vault_export(
|
|||||||
@nostr_app.command("sync")
|
@nostr_app.command("sync")
|
||||||
def nostr_sync(ctx: typer.Context) -> None:
|
def nostr_sync(ctx: typer.Context) -> None:
|
||||||
"""Sync with configured Nostr relays."""
|
"""Sync with configured Nostr relays."""
|
||||||
typer.echo(f"Syncing vault for fingerprint: {ctx.obj.get('fingerprint')}")
|
pm = _get_pm(ctx)
|
||||||
|
event_id = pm.sync_vault()
|
||||||
|
if event_id:
|
||||||
|
typer.echo(event_id)
|
||||||
|
else:
|
||||||
|
typer.echo("Error: Failed to sync vault")
|
||||||
|
|
||||||
|
|
||||||
@nostr_app.command("get-pubkey")
|
@nostr_app.command("get-pubkey")
|
||||||
@@ -172,7 +177,9 @@ def fingerprint_list(ctx: typer.Context) -> None:
|
|||||||
@util_app.command("generate-password")
|
@util_app.command("generate-password")
|
||||||
def generate_password(ctx: typer.Context, length: int = 24) -> None:
|
def generate_password(ctx: typer.Context, length: int = 24) -> None:
|
||||||
"""Generate a strong password."""
|
"""Generate a strong password."""
|
||||||
typer.echo(f"Generate password of length {length} for {ctx.obj.get('fingerprint')}")
|
pm = _get_pm(ctx)
|
||||||
|
password = pm.password_generator.generate_password(length)
|
||||||
|
typer.echo(password)
|
||||||
|
|
||||||
|
|
||||||
@api_app.command("start")
|
@api_app.command("start")
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
|
import sys
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||||
|
|
||||||
from typer.testing import CliRunner
|
from typer.testing import CliRunner
|
||||||
|
|
||||||
from seedpass.cli import app, PasswordManager
|
from seedpass.cli import app, PasswordManager
|
||||||
@@ -113,3 +116,36 @@ def test_config_get(monkeypatch):
|
|||||||
result = runner.invoke(app, ["config", "get", "x"])
|
result = runner.invoke(app, ["config", "get", "x"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert "1" in result.stdout
|
assert "1" in result.stdout
|
||||||
|
|
||||||
|
|
||||||
|
def test_nostr_sync(monkeypatch):
|
||||||
|
called = {}
|
||||||
|
|
||||||
|
def sync_vault():
|
||||||
|
called["called"] = True
|
||||||
|
return "evt123"
|
||||||
|
|
||||||
|
pm = SimpleNamespace(sync_vault=sync_vault, select_fingerprint=lambda fp: None)
|
||||||
|
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
|
||||||
|
result = runner.invoke(app, ["nostr", "sync"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert called.get("called") is True
|
||||||
|
assert "evt123" in result.stdout
|
||||||
|
|
||||||
|
|
||||||
|
def test_generate_password(monkeypatch):
|
||||||
|
called = {}
|
||||||
|
|
||||||
|
def gen_pw(length):
|
||||||
|
called["length"] = length
|
||||||
|
return "secretpw"
|
||||||
|
|
||||||
|
pm = SimpleNamespace(
|
||||||
|
password_generator=SimpleNamespace(generate_password=gen_pw),
|
||||||
|
select_fingerprint=lambda fp: None,
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
|
||||||
|
result = runner.invoke(app, ["util", "generate-password", "--length", "12"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert called.get("length") == 12
|
||||||
|
assert "secretpw" in result.stdout
|
||||||
|
Reference in New Issue
Block a user