86 lines
3.3 KiB
Python
86 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test state management functionality
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
import json
|
|
|
|
# Add project root to path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from app import create_app
|
|
|
|
def test_state_management():
|
|
"""Test state management functionality"""
|
|
app = create_app()
|
|
|
|
with app.test_client() as client:
|
|
print("Testing state management functionality...")
|
|
|
|
# Test 1: Initial system state
|
|
print("\n1. Testing initial system state...")
|
|
response = client.get('/api/system/state')
|
|
print(f"System state: {response.status_code}")
|
|
state = response.get_json()
|
|
print(f"Initial state: {json.dumps(state, indent=2)}")
|
|
|
|
# Test 2: Health check with system status
|
|
print("\n2. Testing enhanced health check...")
|
|
response = client.get('/api/health')
|
|
print(f"Health check: {response.status_code}")
|
|
health = response.get_json()
|
|
print(f"Health info: {json.dumps(health, indent=2)}")
|
|
|
|
# Test 3: Check mesh readiness (should be false initially)
|
|
print("\n3. Testing mesh readiness check...")
|
|
response = client.get('/api/mesh/ready')
|
|
print(f"Mesh ready: {response.status_code}")
|
|
ready = response.get_json()
|
|
print(f"Ready status: {json.dumps(ready, indent=2)}")
|
|
|
|
# Test 4: Upload file and check state changes
|
|
blade_file = Path("resource/blade.step")
|
|
if blade_file.exists():
|
|
print(f"\n4. Testing file upload and state changes...")
|
|
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}")
|
|
|
|
# Check system state after upload
|
|
response = client.get('/api/system/state')
|
|
state = response.get_json()
|
|
print(f"State after upload: {json.dumps(state['state'], indent=2)}")
|
|
|
|
# Check mesh readiness after upload
|
|
response = client.get('/api/mesh/ready')
|
|
ready = response.get_json()
|
|
print(f"Ready after upload: {ready}")
|
|
|
|
# Test 5: Test mesh result (should be empty)
|
|
print("\n5. Testing mesh result retrieval...")
|
|
response = client.get('/api/mesh/result')
|
|
print(f"Mesh result: {response.status_code}")
|
|
if response.status_code == 404:
|
|
print("No mesh result available (expected)")
|
|
else:
|
|
result = response.get_json()
|
|
print(f"Result: {json.dumps(result, indent=2)}")
|
|
|
|
# Test 6: Test system reset
|
|
print("\n6. Testing system reset...")
|
|
response = client.post('/api/system/reset')
|
|
print(f"Reset: {response.status_code}")
|
|
reset_result = response.get_json()
|
|
print(f"Reset result: {reset_result}")
|
|
|
|
# Check state after reset
|
|
response = client.get('/api/system/state')
|
|
state = response.get_json()
|
|
print(f"State after reset: {json.dumps(state['state'], indent=2)}")
|
|
|
|
if __name__ == '__main__':
|
|
print("CAE Mesh Generator State Management Test")
|
|
print("=" * 50)
|
|
test_state_management() |