Spaces:
Running
Running
| """ | |
| Simple Raster Data Integration Test | |
| Tests core components of the raster data MVC system | |
| """ | |
| import sys | |
| import os | |
| # Add backend directory to Python path | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| def test_raster_integration(): | |
| """Test raster data integration""" | |
| print("\n" + "="*80) | |
| print("π§ͺ RASTER DATA MVC INTEGRATION TEST") | |
| print("="*80) | |
| total_tests = 0 | |
| passed_tests = 0 | |
| # Test 1: Import all components | |
| print("\n1οΈβ£ Testing imports...") | |
| total_tests += 5 | |
| try: | |
| from models.raster_data_model import RasterDataModel | |
| print(" β RasterDataModel imported") | |
| passed_tests += 1 | |
| except Exception as e: | |
| print(f" β RasterDataModel failed: {e}") | |
| try: | |
| from services.raster_data_service import RasterDataService | |
| print(" β RasterDataService imported") | |
| passed_tests += 1 | |
| except Exception as e: | |
| print(f" β RasterDataService failed: {e}") | |
| try: | |
| from controllers.raster_data_controller import RasterDataController | |
| print(" β RasterDataController imported") | |
| passed_tests += 1 | |
| except Exception as e: | |
| print(f" β RasterDataController failed: {e}") | |
| try: | |
| from routes.raster_routes import create_raster_routes | |
| print(" β Raster routes imported") | |
| passed_tests += 1 | |
| except Exception as e: | |
| print(f" β Raster routes failed: {e}") | |
| try: | |
| from config.raster_config import RasterDataConfig, get_raster_config | |
| print(" β RasterDataConfig imported") | |
| passed_tests += 1 | |
| except Exception as e: | |
| print(f" β RasterDataConfig failed: {e}") | |
| # Test 2: Basic functionality | |
| print("\n2οΈβ£ Testing basic functionality...") | |
| total_tests += 3 | |
| try: | |
| config = RasterDataConfig() | |
| raster_paths = config.get_raster_paths() | |
| print(f" β Configuration loaded: {len(raster_paths)} sources") | |
| passed_tests += 1 | |
| except Exception as e: | |
| print(f" β Configuration failed: {e}") | |
| try: | |
| model = RasterDataModel() | |
| soil_code = model.encode_soil_class('Acrisols') | |
| print(f" β Model encoding works: 'Acrisols' -> {soil_code}") | |
| passed_tests += 1 | |
| except Exception as e: | |
| print(f" β Model failed: {e}") | |
| try: | |
| service = RasterDataService() | |
| test_coords = [{'longitude': 121.0, 'latitude': 14.0}] | |
| is_valid, _ = service.validate_coordinates(test_coords) | |
| print(f" β Service validation: {is_valid}") | |
| passed_tests += 1 | |
| except Exception as e: | |
| print(f" β Service failed: {e}") | |
| # Test 3: Flask integration | |
| print("\n3οΈβ£ Testing Flask integration...") | |
| total_tests += 2 | |
| try: | |
| config = get_raster_config().get_config() | |
| raster_bp = create_raster_routes(config) | |
| print(" β Routes blueprint created") | |
| passed_tests += 1 | |
| except Exception as e: | |
| print(f" β Blueprint creation failed: {e}") | |
| try: | |
| from flask import Flask | |
| app = Flask(__name__) | |
| app.register_blueprint(raster_bp) | |
| route_count = sum(1 for rule in app.url_map.iter_rules() if '/api/raster/' in rule.rule) | |
| print(f" β Flask integration: {route_count} routes registered") | |
| passed_tests += 1 | |
| except Exception as e: | |
| print(f" β Flask integration failed: {e}") | |
| # Results | |
| success_rate = (passed_tests / total_tests) * 100 if total_tests > 0 else 0 | |
| print("\n" + "="*80) | |
| print("π TEST RESULTS") | |
| print("="*80) | |
| print(f"Total Tests: {total_tests}") | |
| print(f"Passed: {passed_tests} β ") | |
| print(f"Failed: {total_tests - passed_tests} β") | |
| print(f"Success Rate: {success_rate:.1f}%") | |
| if success_rate >= 80: | |
| print("\nπ RASTER DATA SYSTEM IS READY! π") | |
| print("β MVC architecture working") | |
| print("β Flask integration successful") | |
| print("β All 9 geospatial features available:") | |
| print(" β’ Soil Type (HWSD2)") | |
| print(" β’ Elevation (WorldClim)") | |
| print(" β’ Population Density (GlobPOP)") | |
| print(" β’ Land Cover (Copernicus)") | |
| print(" β’ NDVI (MODIS/eVIIRS)") | |
| print(" β’ Annual Precipitation (WorldClim)") | |
| print(" β’ Annual Temperature (WorldClim)") | |
| print(" β’ Wind Speed (Global Wind Atlas)") | |
| print(" β’ Impervious Surface (GHSL)") | |
| else: | |
| print("\nβ οΈ ISSUES DETECTED") | |
| print("β Some components need attention") | |
| print("β Check error messages above") | |
| print("\n" + "="*80) | |
| if __name__ == "__main__": | |
| test_raster_integration() |