-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
117 lines (86 loc) · 3.89 KB
/
test_cli.py
File metadata and controls
117 lines (86 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""Tests for the vault CLI tool."""
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
if TYPE_CHECKING:
from pathlib import Path
try:
from typer.testing import CliRunner
from qp_vault.cli.main import app
HAS_TYPER = True
except ImportError:
HAS_TYPER = False
pytestmark = pytest.mark.skipif(not HAS_TYPER, reason="typer not installed")
@pytest.fixture
def runner():
return CliRunner()
@pytest.fixture
def vault_dir(tmp_path: Path) -> Path:
return tmp_path / "cli-vault"
class TestCLIInit:
def test_init_creates_vault(self, runner, vault_dir):
result = runner.invoke(app, ["init", str(vault_dir)])
assert result.exit_code == 0
assert "initialized" in result.output.lower() or "Vault" in result.output
assert (vault_dir / "vault.db").exists()
def test_init_already_exists(self, runner, vault_dir):
runner.invoke(app, ["init", str(vault_dir)])
result = runner.invoke(app, ["init", str(vault_dir)])
assert result.exit_code == 0
assert "already exists" in result.output.lower()
class TestCLIAdd:
def test_add_text(self, runner, vault_dir, tmp_path):
runner.invoke(app, ["init", str(vault_dir)])
# Create a test file
test_file = tmp_path / "doc.md"
test_file.write_text("Test document content for CLI testing.")
result = runner.invoke(app, ["add", str(test_file), "--path", str(vault_dir)])
assert result.exit_code == 0
assert "Added" in result.output or "doc.md" in result.output
def test_add_with_trust(self, runner, vault_dir, tmp_path):
runner.invoke(app, ["init", str(vault_dir)])
test_file = tmp_path / "sop.md"
test_file.write_text("Standard operating procedure.")
result = runner.invoke(app, [
"add", str(test_file),
"--trust", "canonical",
"--path", str(vault_dir),
])
assert result.exit_code == 0
assert "canonical" in result.output.lower()
class TestCLISearch:
def test_search(self, runner, vault_dir, tmp_path):
runner.invoke(app, ["init", str(vault_dir)])
test_file = tmp_path / "searchable.md"
test_file.write_text("Incident response procedure for critical outages.")
runner.invoke(app, ["add", str(test_file), "--path", str(vault_dir)])
result = runner.invoke(app, ["search", "incident response", "--path", str(vault_dir)])
assert result.exit_code == 0
def test_search_no_results(self, runner, vault_dir):
runner.invoke(app, ["init", str(vault_dir)])
result = runner.invoke(app, ["search", "nonexistent_xyz", "--path", str(vault_dir)])
assert result.exit_code == 0
assert "No results" in result.output
class TestCLIStatus:
def test_status_empty(self, runner, vault_dir):
runner.invoke(app, ["init", str(vault_dir)])
result = runner.invoke(app, ["status", "--path", str(vault_dir)])
assert result.exit_code == 0
assert "0" in result.output
def test_status_with_resources(self, runner, vault_dir, tmp_path):
runner.invoke(app, ["init", str(vault_dir)])
test_file = tmp_path / "doc.md"
test_file.write_text("Some content.")
runner.invoke(app, ["add", str(test_file), "--path", str(vault_dir)])
result = runner.invoke(app, ["status", "--path", str(vault_dir)])
assert result.exit_code == 0
assert "1" in result.output
class TestCLIVerify:
def test_verify_all(self, runner, vault_dir, tmp_path):
runner.invoke(app, ["init", str(vault_dir)])
test_file = tmp_path / "doc.md"
test_file.write_text("Verify this content.")
runner.invoke(app, ["add", str(test_file), "--path", str(vault_dir)])
result = runner.invoke(app, ["verify", "--path", str(vault_dir)])
assert result.exit_code == 0
assert "PASS" in result.output