44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""Unit tests for app.services.i18n."""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
|
|
def test_languages_contains_all_four_plus_english():
|
|
from app.services.i18n import LANGUAGES
|
|
assert set(LANGUAGES.keys()) == {"en", "it", "es", "fr", "de"}
|
|
assert LANGUAGES["en"] == "English"
|
|
assert LANGUAGES["it"] == "Italian"
|
|
assert LANGUAGES["es"] == "Spanish"
|
|
assert LANGUAGES["fr"] == "French"
|
|
assert LANGUAGES["de"] == "German"
|
|
|
|
|
|
def test_active_languages_is_en_and_it_only():
|
|
from app.services.i18n import ACTIVE_LANGUAGES
|
|
assert ACTIVE_LANGUAGES == {"en", "it"}
|
|
|
|
|
|
def test_respond_in_clause_empty_for_english():
|
|
from app.services.i18n import respond_in_clause
|
|
assert respond_in_clause("en") == ""
|
|
|
|
|
|
def test_respond_in_clause_empty_for_none_or_empty():
|
|
from app.services.i18n import respond_in_clause
|
|
assert respond_in_clause("") == ""
|
|
assert respond_in_clause(None) == ""
|
|
|
|
|
|
def test_respond_in_clause_italian():
|
|
from app.services.i18n import respond_in_clause
|
|
result = respond_in_clause("it")
|
|
assert "Italian" in result
|
|
assert result.startswith("\n\n")
|
|
|
|
|
|
def test_respond_in_clause_unknown_lang_falls_back_to_english():
|
|
"""Defensive: a raw POST or stale lang code should not crash the
|
|
prompt assembly. Unknown codes map to no-suffix (English default)."""
|
|
from app.services.i18n import respond_in_clause
|
|
assert respond_in_clause("xx") == ""
|