============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-9.2.0, pluggy-1.7.0 -- /root/telegram-saas/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /root/telegram-saas
configfile: pyproject.toml
plugins: anyio-4.16.0, asyncio-1.5.0
asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
collecting ... collected 6 items                                                              

tests/integration/test_i18n_api.py::test_get_locales_list PASSED         [ 16%]
tests/integration/test_i18n_api.py::test_get_translation_bundle PASSED   [ 33%]
tests/integration/test_i18n_api.py::test_update_user_locale PASSED       [ 50%]
tests/integration/test_i18n_api.py::test_save_custom_translation_override PASSED [ 66%]
tests/integration/test_i18n_api.py::test_audit_translations_and_missing_keys FAILED [ 83%]
tests/integration/test_i18n_api.py::test_ai_translation_and_human_approval_workflow FAILED [100%]

=================================== FAILURES ===================================
___________________ test_audit_translations_and_missing_keys ___________________

async_client = <httpx.AsyncClient object at 0x7f5bc44ef710>

    @pytest.mark.asyncio
    async def test_audit_translations_and_missing_keys(async_client: AsyncClient):
        # 1. Audit all 16 locales
        audit_resp = await async_client.get("/api/v1/i18n/audit")
        assert audit_resp.status_code == 200
        summary = audit_resp.json()["data"]
        assert summary["total_locales"] == 16
>       assert summary["overall_coverage"] == 100.0
E       assert 97.41 == 100.0

tests/integration/test_i18n_api.py:88: AssertionError
_______________ test_ai_translation_and_human_approval_workflow ________________

async_client = <httpx.AsyncClient object at 0x7f5bc44321b0>

    @pytest.mark.asyncio
    async def test_ai_translation_and_human_approval_workflow(async_client: AsyncClient):
        email = f"reviewer_{uuid.uuid4().hex[:6]}@example.com"
        reg_resp = await async_client.post(
            "/api/v1/auth/register",
            json={"email": email, "password": "Password123!", "full_name": "Reviewer Pro"},
        )
        token = reg_resp.json()["data"]["access_token"]
        headers = {"Authorization": f"Bearer {token}"}
    
        # 1. Request AI translation suggestion
        ai_req = {
            "key": "order_confirmed",
            "source_text": "Your order #{order_id} has been confirmed!",
            "source_locale": "en",
            "target_locale": "hi",
            "namespace": "bot",
            "auto_save_as_pending": True,
        }
        ai_resp = await async_client.post("/api/v1/i18n/ai/translate", headers=headers, json=ai_req)
        assert ai_resp.status_code == 200
        ai_data = ai_resp.json()["data"]
        assert ai_data["is_approved"] is False
        assert "{order_id}" in ai_data["suggested_translation"]
        trans_id = ai_data["translation_id"]
        assert trans_id is not None
    
        # 2. List pending translations
        pending_resp = await async_client.get("/api/v1/i18n/translations/pending", headers=headers)
        assert pending_resp.status_code == 200
        pending_list = pending_resp.json()["data"]
>       pending_ids = [p["id"] for p in pending_list]
                       ^^^^^^^
E       TypeError: string indices must be integers, not 'str'

tests/integration/test_i18n_api.py:134: TypeError
----------------------------- Captured stdout call -----------------------------
2026-11-18 08:26:52 [info     ] dispatching_domain_event       event_id=5f9ce265-bc38-4150-9a9d-cd5694288e4c event_type=UserRegisteredEvent handlers_count=0
=========================== short test summary info ============================
FAILED tests/integration/test_i18n_api.py::test_audit_translations_and_missing_keys
FAILED tests/integration/test_i18n_api.py::test_ai_translation_and_human_approval_workflow
========================= 2 failed, 4 passed in 0.69s ==========================
