feat: --send-email / --no-send-email flag for CLI mode

This commit is contained in:
Vlad Doloman
2026-06-24 02:54:48 +03:00
parent ceaf24414a
commit 996000c5ae
2 changed files with 37 additions and 10 deletions

View File

@@ -165,7 +165,7 @@ def test_main_dispatches_create(monkeypatch):
runner = MagicMock()
monkeypatch.setattr("openvpncertupdate.CliRunner", lambda: runner)
main()
runner.create.assert_called_once_with("alice", "a@b.com")
runner.create.assert_called_once_with("alice", "a@b.com", send_email_flag=True)
def test_main_dispatches_reissue(monkeypatch):
@@ -173,7 +173,7 @@ def test_main_dispatches_reissue(monkeypatch):
runner = MagicMock()
monkeypatch.setattr("openvpncertupdate.CliRunner", lambda: runner)
main()
runner.reissue.assert_called_once_with("bob", "")
runner.reissue.assert_called_once_with("bob", "", send_email_flag=True)
def test_main_dispatches_revoke(monkeypatch):
@@ -198,3 +198,25 @@ def test_main_no_args_launches_tui(monkeypatch):
monkeypatch.setattr("openvpncertupdate.CursesApp", lambda: app)
main()
app.run.assert_called_once_with()
# ---------------------------------------------------------------------------
# --send-email / --no-send-email
# ---------------------------------------------------------------------------
def test_no_send_email_skips_delivery(monkeypatch, capsys):
mocks = _patch_issue(monkeypatch)
monkeypatch.setattr("openvpncertupdate.get_email", MagicMock(return_value=""))
CliRunner().create("alice", "alice@example.com", send_email_flag=False)
mocks["send_email"].assert_not_called()
out = capsys.readouterr().out
assert "config:" in out
def test_main_no_send_email_flag(monkeypatch):
monkeypatch.setattr(sys, "argv",
["prog", "--reissue", "bob", "--no-send-email"])
runner = MagicMock()
monkeypatch.setattr("openvpncertupdate.CliRunner", lambda: runner)
main()
runner.reissue.assert_called_once_with("bob", "", send_email_flag=False)