diff options
| author | Danilo M. <danix@danix.xyz> | 2026-05-05 10:51:56 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-05-05 10:51:56 +0200 |
| commit | 54ad3e37c6e9d2242f932c192119dd6de64966cf (patch) | |
| tree | 84c7018152825a63c2f6b009f18634a8585d996a /tests | |
| parent | 48b84da95d0736124f8be6849aa32df31bdb29aa (diff) | |
| download | publisher-54ad3e37c6e9d2242f932c192119dd6de64966cf.tar.gz publisher-54ad3e37c6e9d2242f932c192119dd6de64966cf.zip | |
feat: check OLLAMA_HOST reachability before starting translationv1.6
Non-blocking QThread check hits /api/tags on the resolved ollama host
before launching TranslationWorker. Shows QMessageBox.warning() if
unreachable; proceeds silently if reachable. Adds ollama_host field to
Config with env-var fallback to http://localhost:11434.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_config.py | 27 | ||||
| -rw-r--r-- | tests/test_ollama_check_worker.py | 11 |
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index f19bfdd..f46a224 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -23,3 +23,30 @@ def test_config_is_complete_false_when_blog_repo_empty(tmp_path): 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" diff --git a/tests/test_ollama_check_worker.py b/tests/test_ollama_check_worker.py new file mode 100644 index 0000000..3c575db --- /dev/null +++ b/tests/test_ollama_check_worker.py @@ -0,0 +1,11 @@ +from workers.ollama_check_worker import OllamaCheckWorker + + +def test_worker_appends_api_tags_path(): + w = OllamaCheckWorker("http://localhost:11434") + assert w._url == "http://localhost:11434/api/tags" + + +def test_worker_strips_trailing_slash(): + w = OllamaCheckWorker("http://localhost:11434/") + assert w._url == "http://localhost:11434/api/tags" |
