blob: f46a22457577cd029c8fb51923a4f27840d3fa05 (
plain)
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
|
from pathlib import Path
from core.config import Config, DEFAULT_CONFIG_PATH
def test_config_loads_defaults_when_missing(tmp_path):
path = tmp_path / "config.toml"
cfg = Config.load(path)
assert cfg.blog_repo == ""
assert cfg.transart_script == "/home/danix/bin/transart.py"
assert cfg.typora_bin == "typora"
def test_config_round_trips(tmp_path):
path = tmp_path / "config.toml"
cfg = Config(blog_repo="/some/path", transart_script="/bin/x", typora_bin="typora")
cfg.save(path)
loaded = Config.load(path)
assert loaded.blog_repo == "/some/path"
def test_config_is_complete_false_when_blog_repo_empty(tmp_path):
path = tmp_path / "config.toml"
cfg = Config.load(path)
assert cfg.is_complete() is False
def test_config_is_complete_true_when_all_set():
cfg = Config(blog_repo="/some/repo", transart_script="/bin/x", typora_bin="typora")
assert cfg.is_complete() is True
def test_config_ollama_host_default(tmp_path):
path = tmp_path / "config.toml"
cfg = Config.load(path)
assert cfg.ollama_host == ""
def test_config_ollama_host_round_trips(tmp_path):
path = tmp_path / "config.toml"
cfg = Config(blog_repo="/repo", ollama_host="http://1.2.3.4:11434")
cfg.save(path)
loaded = Config.load(path)
assert loaded.ollama_host == "http://1.2.3.4:11434"
def test_resolved_ollama_host_uses_env_when_field_empty(monkeypatch):
monkeypatch.setenv("OLLAMA_HOST", "http://env-host:11434")
cfg = Config(ollama_host="")
assert cfg.resolved_ollama_host() == "http://env-host:11434"
def test_resolved_ollama_host_prefers_field_over_env(monkeypatch):
monkeypatch.setenv("OLLAMA_HOST", "http://env-host:11434")
cfg = Config(ollama_host="http://config-host:11434")
assert cfg.resolved_ollama_host() == "http://config-host:11434"
def test_resolved_ollama_host_fallback_default(monkeypatch):
monkeypatch.delenv("OLLAMA_HOST", raising=False)
cfg = Config(ollama_host="")
assert cfg.resolved_ollama_host() == "http://localhost:11434"
|