AnsysLink/test/test_api_basic.py

58 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""
Basic API test without external requests
"""
import sys
from pathlib import Path
# Add project root to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from app import create_app
import json
def test_api_routes():
"""Test API routes using Flask test client"""
app = create_app()
with app.test_client() as client:
# Test health check
print("Testing health check...")
response = client.get('/api/health')
print(f"Health check: {response.status_code}")
print(f"Response: {response.get_json()}")
# Test mesh status
print("\nTesting mesh status...")
response = client.get('/api/mesh/status')
print(f"Mesh status: {response.status_code}")
print(f"Response: {response.get_json()}")
# Test get current file (should return 404)
print("\nTesting get current file (no file uploaded)...")
response = client.get('/api/files/current')
print(f"Current file: {response.status_code}")
print(f"Response: {response.get_json()}")
# Test file upload with blade.step if it exists
blade_file = Path("resource/blade.step")
if blade_file.exists():
print(f"\nTesting file upload with {blade_file}...")
with open(blade_file, 'rb') as f:
data = {'file': (f, blade_file.name)}
response = client.post('/api/upload', data=data, content_type='multipart/form-data')
print(f"Upload: {response.status_code}")
print(f"Response: {response.get_json()}")
# Test get current file after upload
print("\nTesting get current file after upload...")
response = client.get('/api/files/current')
print(f"Current file: {response.status_code}")
print(f"Response: {response.get_json()}")
else:
print(f"\nTest file {blade_file} not found, skipping upload test")
if __name__ == '__main__':
print("CAE Mesh Generator API Basic Test")
print("=" * 50)
test_api_routes()