File size: 1,809 Bytes
495526b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
from fastapi.testclient import TestClient

from backend.app.main import app

client = TestClient(app)


def test_health() -> None:
    response = client.get("/health")
    assert response.status_code == 200
    payload = response.json()
    assert payload["status"] == "ok"


def test_chat_endpoint() -> None:
    response = client.post(
        "/v1/chat",
        json={
            "messages": [{"role": "user", "content": "What is the first step during flood evacuation?"}],
            "language": "English",
            "region": "global",
        },
    )
    assert response.status_code == 200
    assert "answer" in response.json()


def test_chat_nepali_language() -> None:
    """Verify Nepali language requests return a Nepali-language answer."""
    response = client.post(
        "/v1/chat",
        json={
            "messages": [{"role": "user", "content": "भूकम्पको बेला के गर्ने?"}],
            "language": "Nepali",
            "region": "Nepal",
        },
    )
    assert response.status_code == 200
    data = response.json()
    assert "answer" in data
    # Response should contain Devanagari characters for Nepali output
    assert any("\u0900" <= ch <= "\u097F" for ch in data["answer"]), (
        "Expected Devanagari script in Nepali response"
    )


def test_chat_nepali_confidence_range() -> None:
    """Nepali response confidence must be in valid [0, 1] range."""
    response = client.post(
        "/v1/chat",
        json={
            "messages": [{"role": "user", "content": "बाढीको बेला के गर्ने?"}],
            "language": "Nepali",
            "region": "Nepal",
        },
    )
    assert response.status_code == 200
    data = response.json()
    assert 0.0 <= data["confidence"] <= 1.0