Files
docker-images/linkki-tiedotus/tests/test_cli.py
T
ajp_anton 8ec3cde4f2
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8 context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; } name:ph… (push) Successful in 48s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18 POSTGIS_VERSION=3 VCHORD_VERSION=0.5.3 context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 55s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3 context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; } name:python-tools oci_labels:org.opencontainers.ima… (push) Successful in 54s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; } name:linkki-tiedotus oci_labels:… (push) Successful in 39s
Add Linkki broadcast image
2026-08-19 20:51:26 +00:00

54 lines
1.9 KiB
Python

from pathlib import Path
from linkki_poster.cli import apply_language_order, load_config, load_config_strict
from linkki_poster.models import Language, LanguageAssets
def test_load_config_strict_reads_required_fields(tmp_path: Path) -> None:
config_path = tmp_path / "telegram_config.json"
config_path.write_text('{"bot_token":"token","chat_id":"-100123"}', encoding="utf-8")
config = load_config_strict(tmp_path)
assert config.bot_token == "token"
assert config.chat_id == "-100123"
assert config.channel_username == ""
def test_load_config_strict_fails_when_missing(tmp_path: Path) -> None:
try:
load_config_strict(tmp_path)
except FileNotFoundError:
return
raise AssertionError("Expected FileNotFoundError")
def test_load_config_strict_fails_when_required_field_missing(tmp_path: Path) -> None:
config_path = tmp_path / "telegram_config.json"
config_path.write_text('{"bot_token":"token"}', encoding="utf-8")
try:
load_config_strict(tmp_path)
except ValueError:
return
raise AssertionError("Expected ValueError")
def test_apply_language_order_uses_requested_prefix_and_keeps_rest(tmp_path: Path) -> None:
fi = LanguageAssets(Language.FI, tmp_path / "fi.md", "fi", [])
sv = LanguageAssets(Language.SV, tmp_path / "sv.md", "sv", [])
en = LanguageAssets(Language.EN, tmp_path / "en.md", "en", [])
ordered = apply_language_order([fi, sv, en], "en,fi")
assert [item.language for item in ordered] == [Language.EN, Language.FI, Language.SV]
def test_load_config_interactive_prompts_missing_values(tmp_path: Path) -> None:
answers = iter(["token_from_prompt", "-100123", "publicname"])
config = load_config(tmp_path, non_interactive=False, input_fn=lambda _: next(answers))
assert config.bot_token == "token_from_prompt"
assert config.chat_id == "-100123"
assert config.channel_username == "publicname"