mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 00:09:04 +00:00
Add vault stats command and API endpoint
This commit is contained in:
13
src/tests/test_api_profile_stats.py
Normal file
13
src/tests/test_api_profile_stats.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from test_api import client
|
||||
|
||||
|
||||
def test_profile_stats_endpoint(client):
|
||||
cl, token = client
|
||||
stats = {"total_entries": 1}
|
||||
# monkeypatch set _pm.get_profile_stats after client fixture started
|
||||
import seedpass.api as api
|
||||
|
||||
api._pm.get_profile_stats = lambda: stats
|
||||
res = cl.get("/api/v1/stats", headers={"Authorization": f"Bearer {token}"})
|
||||
assert res.status_code == 200
|
||||
assert res.json() == stats
|
25
src/tests/test_cli_vault_stats.py
Normal file
25
src/tests/test_cli_vault_stats.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from seedpass.cli import app
|
||||
from seedpass import cli
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def test_vault_stats_command(monkeypatch):
|
||||
stats = {
|
||||
"total_entries": 2,
|
||||
"entries": {"password": 1, "totp": 1},
|
||||
}
|
||||
pm = SimpleNamespace(
|
||||
get_profile_stats=lambda: stats, select_fingerprint=lambda fp: None
|
||||
)
|
||||
monkeypatch.setattr(cli, "PasswordManager", lambda: pm)
|
||||
result = runner.invoke(app, ["vault", "stats"])
|
||||
assert result.exit_code == 0
|
||||
out = result.stdout
|
||||
# Output should be pretty JSON with the expected values
|
||||
data = json.loads(out)
|
||||
assert data == stats
|
Reference in New Issue
Block a user