You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.9 KiB
111 lines
3.9 KiB
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
|
|
|
|
error = response.json()
|
|
assert "error" in error
|
|
assert error["error"]["code"] == "INVALID_INPUT"
|
|
|
|
def test_error_empty_text(self, api_client):
|
|
"""Test error when the text is empty"""
|
|
payload = {
|
|
"text": "",
|
|
"threshold": 0.5
|
|
}
|
|
response = api_client.post(f"{BASE_URL}/summarization", json=payload)
|
|
assert response.status_code == 400
|
|
|
|
error = response.json()
|
|
assert "error" in error
|
|
assert error["error"]["code"] == "INVALID_INPUT"
|
|
|
|
def test_error_texts_has_empty_value(self, api_client):
|
|
"""Test error when texts has an empty value"""
|
|
payload = {
|
|
"texts": [
|
|
"Python is a high-level programming language. It's known for its simplicity and readability.",
|
|
"",
|
|
"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 == 400
|
|
|
|
error = response.json()
|
|
assert "error" in error
|
|
assert error["error"]["code"] == "INVALID_INPUT"
|
|
|
|
def test_error_texts_has_empty_values(self, api_client):
|
|
"""Test error when texts has empty values"""
|
|
payload = {
|
|
"texts": [
|
|
"",
|
|
"",
|
|
""
|
|
],
|
|
"threshold": 0.3
|
|
}
|
|
response = api_client.post(f"{BASE_URL}/summarization", json=payload)
|
|
assert response.status_code == 400
|
|
|
|
error = response.json()
|
|
assert "error" in error
|
|
assert error["error"]["code"] == "INVALID_INPUT"
|