186 lines
6.3 KiB
Python
186 lines
6.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Integration test script for CAE Mesh Generator
|
|
"""
|
|
import requests
|
|
import json
|
|
import time
|
|
import os
|
|
from pathlib import Path
|
|
|
|
class IntegrationTester:
|
|
def __init__(self, base_url='http://localhost:5000'):
|
|
self.base_url = base_url
|
|
self.session = requests.Session()
|
|
|
|
def test_frontend_loading(self):
|
|
"""Test if frontend loads correctly"""
|
|
print("Testing frontend loading...")
|
|
try:
|
|
response = self.session.get(self.base_url)
|
|
if response.status_code == 200 and 'CAE网格生成助手' in response.text:
|
|
print("✓ Frontend loads successfully")
|
|
return True
|
|
else:
|
|
print(f"✗ Frontend loading failed: {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"✗ Frontend loading error: {e}")
|
|
return False
|
|
|
|
def test_static_files(self):
|
|
"""Test if static files are served correctly"""
|
|
print("Testing static files...")
|
|
static_files = [
|
|
'/static/css/main.css',
|
|
'/static/js/main.js'
|
|
]
|
|
|
|
all_passed = True
|
|
for file_path in static_files:
|
|
try:
|
|
response = self.session.get(f"{self.base_url}{file_path}")
|
|
if response.status_code == 200:
|
|
print(f"✓ {file_path} loads successfully")
|
|
else:
|
|
print(f"✗ {file_path} failed: {response.status_code}")
|
|
all_passed = False
|
|
except Exception as e:
|
|
print(f"✗ {file_path} error: {e}")
|
|
all_passed = False
|
|
|
|
return all_passed
|
|
|
|
def test_api_endpoints(self):
|
|
"""Test API endpoints"""
|
|
print("Testing API endpoints...")
|
|
|
|
# Test status endpoint
|
|
try:
|
|
response = self.session.get(f"{self.base_url}/api/mesh/status")
|
|
if response.status_code == 200:
|
|
print("✓ Status API endpoint working")
|
|
else:
|
|
print(f"✗ Status API failed: {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"✗ Status API error: {e}")
|
|
return False
|
|
|
|
# Test upload endpoint (without file)
|
|
try:
|
|
response = self.session.post(f"{self.base_url}/api/upload")
|
|
# Should return 400 for missing file
|
|
if response.status_code == 400:
|
|
print("✓ Upload API endpoint working (correctly rejects empty request)")
|
|
else:
|
|
print(f"✗ Upload API unexpected response: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"✗ Upload API error: {e}")
|
|
return False
|
|
|
|
return True
|
|
|
|
def test_file_upload_simulation(self):
|
|
"""Simulate file upload test"""
|
|
print("Testing file upload simulation...")
|
|
|
|
# Create a dummy STEP file for testing
|
|
test_file_content = """ISO-10303-21;
|
|
HEADER;
|
|
FILE_DESCRIPTION(('Test STEP file for CAE Mesh Generator'),'2;1');
|
|
FILE_NAME('test_blade.step','2025-01-01T00:00:00',('Test'),('Test'),'','','');
|
|
FILE_SCHEMA(('AUTOMOTIVE_DESIGN'));
|
|
ENDSEC;
|
|
DATA;
|
|
#1 = CARTESIAN_POINT('Origin',(0.0,0.0,0.0));
|
|
ENDSEC;
|
|
END-ISO-10303-21;"""
|
|
|
|
test_file_path = Path('temp/test_blade.step')
|
|
test_file_path.parent.mkdir(exist_ok=True)
|
|
|
|
try:
|
|
with open(test_file_path, 'w') as f:
|
|
f.write(test_file_content)
|
|
|
|
with open(test_file_path, 'rb') as f:
|
|
files = {'file': ('test_blade.step', f, 'application/step')}
|
|
response = self.session.post(f"{self.base_url}/api/upload", files=files)
|
|
|
|
if response.status_code == 200:
|
|
print("✓ File upload simulation successful")
|
|
return True
|
|
else:
|
|
print(f"✗ File upload failed: {response.status_code}")
|
|
if response.headers.get('content-type', '').startswith('application/json'):
|
|
print(f"Error details: {response.json()}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"✗ File upload simulation error: {e}")
|
|
return False
|
|
finally:
|
|
# Clean up test file
|
|
if test_file_path.exists():
|
|
test_file_path.unlink()
|
|
|
|
def run_all_tests(self):
|
|
"""Run all integration tests"""
|
|
print("=" * 60)
|
|
print("CAE Mesh Generator - Integration Tests")
|
|
print("=" * 60)
|
|
|
|
tests = [
|
|
("Frontend Loading", self.test_frontend_loading),
|
|
("Static Files", self.test_static_files),
|
|
("API Endpoints", self.test_api_endpoints),
|
|
("File Upload Simulation", self.test_file_upload_simulation)
|
|
]
|
|
|
|
results = []
|
|
for test_name, test_func in tests:
|
|
print(f"\n--- {test_name} ---")
|
|
result = test_func()
|
|
results.append((test_name, result))
|
|
|
|
print("\n" + "=" * 60)
|
|
print("Test Results Summary:")
|
|
print("=" * 60)
|
|
|
|
passed = 0
|
|
for test_name, result in results:
|
|
status = "PASS" if result else "FAIL"
|
|
print(f"{test_name:<25} {status}")
|
|
if result:
|
|
passed += 1
|
|
|
|
print(f"\nTotal: {passed}/{len(results)} tests passed")
|
|
|
|
if passed == len(results):
|
|
print("🎉 All integration tests passed!")
|
|
return True
|
|
else:
|
|
print("❌ Some tests failed. Please check the application setup.")
|
|
return False
|
|
|
|
def main():
|
|
"""Main test runner"""
|
|
print("Starting integration tests...")
|
|
print("Make sure the application is running on http://localhost:5000")
|
|
|
|
# Wait a moment for user to start the application
|
|
input("Press Enter when the application is running...")
|
|
|
|
tester = IntegrationTester()
|
|
success = tester.run_all_tests()
|
|
|
|
if success:
|
|
print("\n✅ Integration testing completed successfully!")
|
|
else:
|
|
print("\n❌ Integration testing failed!")
|
|
return 1
|
|
|
|
return 0
|
|
|
|
if __name__ == '__main__':
|
|
exit(main()) |