Add tests for sumarization endpoint.

main
KKlochko 1 month ago
parent ac34ef0740
commit 295b9368f9
Signed by: KKlochko
GPG Key ID: 572ECCD219BBA91B

@ -0,0 +1,59 @@
import pytest
import requests
from typing import Dict, Any
from .conftest import BASE_URL
class TestSummarizationEndpoint:
"""Tests the /summarization endpoint"""
def test_single_text(self, api_client):
"""Test with a single text"""
payload = {
"text": (
"Artificial intelligence is revolutionizing industries worldwide. "
"Machine learning enables computers to learn from data without explicit programming. "
"Deep learning uses neural networks with multiple layers to solve complex problems."
),
"threshold": 0.3
}
response = api_client.post(f"{BASE_URL}/summarization", json=payload)
assert response.status_code == 200
data = response.json()
assert "outputs" in data
assert isinstance(data["outputs"], list)
def test_batch_texts(self, api_client):
"""Test with a batch of texts"""
payload = {
"texts": [
"Python is a high-level programming language. It's known for its simplicity and readability.",
"JavaScript is essential for web development. It runs in browsers and on servers.",
"Rust is a systems programming language. It focuses on safety and performance."
],
"threshold": 0.3
}
response = api_client.post(f"{BASE_URL}/summarization", json=payload)
assert response.status_code == 200
data = response.json()
assert len(data["outputs"]) == 3
def test_with_optional_prompt(self, api_client):
"""Test with an optional prompt"""
payload = {
"text": "Climate change affects global weather patterns.",
"prompt": "Summarize the key points",
"threshold": 0.3
}
response = api_client.post(f"{BASE_URL}/summarization", json=payload)
assert response.status_code == 200
def test_error_no_text(self, api_client):
"""Test error when no text is provided"""
payload = {
"threshold": 0.5
}
response = api_client.post(f"{BASE_URL}/summarization", json=payload)
assert response.status_code == 400
Loading…
Cancel
Save