feat: add SQL/SQLite, AppSec, Capstone incident-tracker, Gitea Actions CI and spaced repetition
Test and Lint / quality (push) Successful in 34s
Test and Lint / quality (push) Successful in 34s
This commit is contained in:
1 parent
0ac80d60d4
commit
9430a194c3
18 files changed
+422
-7
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from tracker import (
|
||||
IncidentNotFoundError,
|
||||
IncidentStore,
|
||||
InvalidIncidentError,
|
||||
build_cli,
|
||||
)
|
||||
from typer.testing import CliRunner
|
||||
|
||||
|
||||
def test_incident_store_sqlite_lifecycle(tmp_path: Path) -> None:
|
||||
store = IncidentStore(tmp_path / "incidents.db")
|
||||
store.init_schema()
|
||||
|
||||
with pytest.raises(InvalidIncidentError):
|
||||
store.add(" ", "high")
|
||||
with pytest.raises(InvalidIncidentError):
|
||||
store.add("DB down", "urgent")
|
||||
|
||||
inc1 = store.add("K8s node NotReady", "critical")
|
||||
inc2 = store.add("High disk usage", "medium")
|
||||
assert inc1.status == "open"
|
||||
assert len(store.list_incidents()) == 2
|
||||
assert [i.id for i in store.list_incidents(severity="critical")] == [inc1.id]
|
||||
|
||||
resolved = store.resolve(inc1.id)
|
||||
assert resolved.status == "resolved"
|
||||
assert store.stats() == {"open": 1, "resolved": 1}
|
||||
|
||||
with pytest.raises(IncidentNotFoundError):
|
||||
store.resolve(9999)
|
||||
assert inc2.id != inc1.id
|
||||
|
||||
|
||||
def test_incident_cli_end_to_end(tmp_path: Path) -> None:
|
||||
db_path = tmp_path / "cli.db"
|
||||
app = build_cli(db_path)
|
||||
runner = CliRunner()
|
||||
|
||||
res_add = runner.invoke(app, ["add", "API 502 spike", "--severity", "high"])
|
||||
assert res_add.exit_code == 0
|
||||
created = json.loads(res_add.stdout)
|
||||
assert created["severity"] == "high"
|
||||
|
||||
res_stats = runner.invoke(app, ["stats"])
|
||||
assert res_stats.exit_code == 0
|
||||
assert json.loads(res_stats.stdout) == {"open": 1, "resolved": 0}
|
||||
Reference in new issue
Block a user