Spaces:
Runtime error
Runtime error
Download tests/test_api_generator.py from DesarrolloTT/DataSuitePro: direct link, hf CLI and curl.
- Browser
- Download file 3.61 kB
-
https://huggingface.co/spaces/DesarrolloTT/DataSuitePro/resolve/main/tests/test_api_generator.py
- Command line
-
hf download hf://spaces/DesarrolloTT/DataSuitePro/tests/test_api_generator.py
-
curl -L -o test_api_generator.py https://huggingface.co/spaces/DesarrolloTT/DataSuitePro/resolve/main/tests/test_api_generator.py
3.61 kB
| # tests/test_api_generator.py | |
| import pytest | |
| import pandas as pd | |
| from pathlib import Path | |
| import tempfile | |
| import os | |
| from backend.api_generator.api_factory import APIFactory, APIConfig | |
| from engines.data_engine import DataEngine | |
| class TestAPIFactory: | |
| """Tests para el generador de APIs""" | |
| def setup_method(self): | |
| self.factory = APIFactory() | |
| self.data_engine = DataEngine() | |
| # Datos de prueba | |
| self.test_data = pd.DataFrame({ | |
| 'id': [1, 2, 3], | |
| 'name': ['Alice', 'Bob', 'Charlie'], | |
| 'age': [25, 30, 35], | |
| 'city': ['Madrid', 'Barcelona', 'Valencia'] | |
| }) | |
| def test_fastapi_generation(self): | |
| """Test generaci贸n de API FastAPI""" | |
| with tempfile.TemporaryDirectory() as temp_dir: | |
| # Crear archivo CSV de prueba | |
| csv_path = Path(temp_dir) / "test.csv" | |
| self.test_data.to_csv(csv_path, index=False) | |
| # Cargar datos en el motor | |
| self.data_engine.load_data(str(csv_path), 'csv') | |
| # Configuraci贸n de la API | |
| api_config = APIConfig( | |
| framework="fastapi", | |
| project_name="TestAPI", | |
| version="1.0.0", | |
| authentication=False, | |
| pagination=True, | |
| documentation=True, | |
| database="sqlite" | |
| ) | |
| # Generar API | |
| output_dir = Path(temp_dir) / "generated_api" | |
| result = self.factory.generate_fastapi( | |
| self.data_engine.data_profile, | |
| api_config, | |
| output_dir | |
| ) | |
| # Verificar resultados | |
| assert result["success"] == True | |
| assert output_dir.exists() | |
| # Verificar que se generaron archivos clave | |
| expected_files = [ | |
| output_dir / "app" / "main.py", | |
| output_dir / "requirements.txt" | |
| ] | |
| for file_path in expected_files: | |
| assert file_path.exists(), f"Archivo no generado: {file_path}" | |
| def test_endpoint_detection(self): | |
| """Test detecci贸n autom谩tica de endpoints""" | |
| with tempfile.TemporaryDirectory() as temp_dir: | |
| csv_path = Path(temp_dir) / "test.csv" | |
| self.test_data.to_csv(csv_path, index=False) | |
| self.data_engine.load_data(str(csv_path), 'csv') | |
| # Analizar datos para endpoints | |
| endpoints = self.factory._analyze_data_for_endpoints( | |
| self.data_engine.data_profile | |
| ) | |
| # Deber铆a detectar endpoints b谩sicos | |
| assert len(endpoints) > 0 | |
| # Verificar tipos de operaciones | |
| operations = [ep.operation for ep in endpoints] | |
| assert "list" in operations | |
| assert "read" in operations | |
| assert "create" in operations | |
| def test_entity_detection(self): | |
| """Test detecci贸n de entidades""" | |
| with tempfile.TemporaryDirectory() as temp_dir: | |
| csv_path = Path(temp_dir) / "test.csv" | |
| self.test_data.to_csv(csv_path, index=False) | |
| self.data_engine.load_data(str(csv_path), 'csv') | |
| entities = self.factory._detect_entities( | |
| self.data_engine.data_profile | |
| ) | |
| assert len(entities) > 0 | |
| assert "columns" in entities[0] | |
| assert "name" in entities[0] |