File size: 1,130 Bytes
fa85955
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e21075
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
"""
Tests for error handling and request id propagation.
"""
import pytest
from unittest.mock import patch
from starlette.testclient import TestClient
from app.main import app

from tests.test_services import StubAsyncClient


client = TestClient(app)


@pytest.mark.integration
def test_httpx_error_returns_502():
    """Test that httpx errors return 502 status."""
    # This will fail to connect to Ollama, triggering httpx.HTTPError
    resp = client.post("/api/v1/summarize/", json={"text": "hi"})
    assert resp.status_code == 502
    data = resp.json()
    assert "Summarization failed" in data["detail"]


def test_request_id_header_propagated(sample_text, mock_ollama_response):
    """Verify X-Request-ID appears in response headers."""
    from tests.test_services import StubAsyncResponse

    stub_response = StubAsyncResponse(json_data=mock_ollama_response)
    with patch('httpx.AsyncClient', return_value=StubAsyncClient(post_result=stub_response)):
        resp = client.post("/api/v1/summarize/", json={"text": sample_text})
        assert resp.status_code == 200
        assert resp.headers.get("X-Request-ID")