From 295b9368f9cf0f9bf35c3672a908ca585a323579 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Fri, 14 Nov 2025 18:43:46 +0200 Subject: [PATCH] Add tests for sumarization endpoint. --- tests/test_summarization_endpoint.py | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/test_summarization_endpoint.py diff --git a/tests/test_summarization_endpoint.py b/tests/test_summarization_endpoint.py new file mode 100644 index 0000000..3b7af15 --- /dev/null +++ b/tests/test_summarization_endpoint.py @@ -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