feat: toggle all-certs view with A key (load_all_certs, Action.TOGGLE_ALL)

This commit is contained in:
Vlad Doloman
2026-06-24 02:36:32 +03:00
parent 629095e0d8
commit 1222fb46a4
3 changed files with 100 additions and 8 deletions

View File

@@ -282,3 +282,44 @@ def test_empty_cert_list_quit():
keys = [ord("q")]
result = _run(keys, certs=[])
assert result.action == Action.EXIT
# ---------------------------------------------------------------------------
# A / a → TOGGLE_ALL
# ---------------------------------------------------------------------------
def test_a_lowercase_returns_toggle_all():
result = _run([ord("a")])
assert result.action == Action.TOGGLE_ALL
def test_A_uppercase_returns_toggle_all():
result = _run([ord("A")])
assert result.action == Action.TOGGLE_ALL
def test_toggle_all_with_no_certs():
"""A works even when the cert list is empty."""
result = _run([ord("a")], certs=[])
assert result.action == Action.TOGGLE_ALL
def test_show_all_flag_passed_through_to_header():
"""show_all=True causes 'ALL certs' to appear in the header addstr call."""
stdscr = _make_stdscr()
stdscr.getch.side_effect = [ord("q")]
with patch("openvpncertupdate.init_colors"):
show_main_screen(stdscr, _CERTS, show_all=True)
# The header addstr call (row 0) should contain 'ALL certs'
calls = [str(c) for c in stdscr.addstr.call_args_list]
assert any("ALL certs" in c for c in calls)
def test_show_all_false_header_shows_expiring():
"""show_all=False (default) shows 'expiring/expired' in the header."""
stdscr = _make_stdscr()
stdscr.getch.side_effect = [ord("q")]
with patch("openvpncertupdate.init_colors"):
show_main_screen(stdscr, _CERTS)
calls = [str(c) for c in stdscr.addstr.call_args_list]
assert any("expiring/expired" in c for c in calls)

View File

@@ -1,7 +1,7 @@
import textwrap
import pytest
from datetime import datetime, timezone, timedelta
from openvpncertupdate import load_expiring_certs, CertInfo, _parse_index_line
from openvpncertupdate import load_all_certs, load_expiring_certs, CertInfo, _parse_index_line
def _fmt(dt: datetime) -> str:
@@ -57,3 +57,22 @@ def test_parse_4digit_year():
cn, dt = result
assert cn == "future"
assert dt.year == 2025
def test_load_all_certs_includes_all_valid(tmp_path):
now = datetime.now(tz=timezone.utc)
pki = make_pki(tmp_path, now)
certs = load_all_certs(pki)
cns = {c.cn for c in certs}
# All V-status entries included regardless of expiry window
assert cns == {"soon", "later", "past15", "past40"}
# Revoked entry excluded
assert "revoked" not in cns
def test_load_all_certs_sorted_ascending(tmp_path):
now = datetime.now(tz=timezone.utc)
pki = make_pki(tmp_path, now)
certs = load_all_certs(pki)
dates = [c.expires for c in certs]
assert dates == sorted(dates)