File size: 1,246 Bytes
1fbc47b
ee1a8a3
1fbc47b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee1a8a3
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
"""API integration tests for the inference endpoint."""

from __future__ import annotations

from fastapi.testclient import TestClient

from src.api.app import create_app
from src.api.dependencies import get_pipeline
from src.inference.pipeline import EmotionPrediction, TopicPrediction


class StubPipeline:
    def batch_predict(self, texts):  # pragma: no cover - simple stub
        return {
            "summaries": [f"summary:{text}" for text in texts],
            "emotion": [EmotionPrediction(labels=["joy"], scores=[0.9]) for _ in texts],
            "topic": [TopicPrediction(label="news", confidence=0.8) for _ in texts],
        }


def test_summarize_route_returns_pipeline_outputs() -> None:
    app = create_app()
    app.dependency_overrides[get_pipeline] = lambda: StubPipeline()
    client = TestClient(app)

    try:
        response = client.post("/summarize", json={"text": "hello world"})
        assert response.status_code == 200
        payload = response.json()
        assert payload["summary"] == "summary:hello world"
        assert payload["emotion_labels"] == ["joy"]
        assert payload["topic"] == "news"
        assert payload["topic_confidence"] == 0.8
    finally:
        app.dependency_overrides.clear()