Malek1ab/ndvi-api
0
1#!/usr/bin/env python32"""3Exemple de script pour tester l'API des indices de végétation4"""5 6import requests7import json8import base649import os10from PIL import Image11from io import BytesIO12 13# Configuration14API_BASE_URL = "http://localhost:8000"15 16def test_health_check():17 """Test du point de contrôle de santé"""18 print("🔍 Test du point de contrôle de santé...")19 response = requests.get(f"{API_BASE_URL}/")20 21 if response.status_code == 200:22 print("✅ API en fonctionnement")23 print(f" Réponse: {response.json()}")24 else:25 print(f"❌ Erreur: {response.status_code}")26 print()27 28def test_api_info():29 """Test du point d'information de l'API"""30 print("🔍 Test des informations de l'API...")31 response = requests.get(f"{API_BASE_URL}/info")32 33 if response.status_code == 200:34 data = response.json()35 print("✅ Informations récupérées avec succès")36 print(f" Indices supportés: {list(data['indices_supportes'].keys())}")37 print(f" Données satellite: {data['donnees_satellite']}")38 else:39 print(f"❌ Erreur: {response.status_code}")40 print()41 42def create_sample_geojson():43 """Crée un exemple de fichier GeoJSON pour les tests"""44 sample_geojson = {45 "type": "FeatureCollection",46 "features": [47 {48 "type": "Feature",49 "geometry": {50 "type": "Polygon",51 "coordinates": [[52 [10.0, 36.0], # Tunisie - zone agricole53 [10.1, 36.0],54 [10.1, 36.1],55 [10.0, 36.1],56 [10.0, 36.0]57 ]]58 },59 "properties": {60 "name": "Zone de test Tunisie"61 }62 }63 ]64 }65 66 filename = "test_zone.geojson"67 with open(filename, 'w') as f: