261 lines
No EOL
8.5 KiB
Python
261 lines
No EOL
8.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script de test pour valider les validations du wrapper AtmoDataClient
|
|
"""
|
|
|
|
from atmo_data_wrapper import AtmoDataClient
|
|
|
|
def test_validations():
|
|
"""Test des validations des paramètres"""
|
|
client = AtmoDataClient()
|
|
|
|
print("=== Test des validations ===\n")
|
|
|
|
# Test format invalide
|
|
try:
|
|
client._validate_format("xml")
|
|
print("❌ Format invalide non détecté")
|
|
except ValueError as e:
|
|
print(f"✅ Format invalide détecté: {e}")
|
|
|
|
# Test format valide
|
|
try:
|
|
client._validate_format("geojson")
|
|
print("✅ Format valide accepté")
|
|
except ValueError as e:
|
|
print(f"❌ Format valide rejeté: {e}")
|
|
|
|
# Test AASQA invalide
|
|
try:
|
|
client._validate_aasqa("99")
|
|
print("❌ Code AASQA invalide non détecté")
|
|
except ValueError as e:
|
|
print(f"✅ Code AASQA invalide détecté: {e}")
|
|
|
|
# Test AASQA valide
|
|
try:
|
|
client._validate_aasqa("11")
|
|
print("✅ Code AASQA valide accepté")
|
|
except ValueError as e:
|
|
print(f"❌ Code AASQA valide rejeté: {e}")
|
|
|
|
# Test polluant invalide
|
|
try:
|
|
client._validate_polluant("CO")
|
|
print("❌ Polluant invalide non détecté")
|
|
except ValueError as e:
|
|
print(f"✅ Polluant invalide détecté: {e}")
|
|
|
|
# Test polluant valide
|
|
try:
|
|
client._validate_polluant("PM10")
|
|
print("✅ Polluant valide accepté")
|
|
except ValueError as e:
|
|
print(f"❌ Polluant valide rejeté: {e}")
|
|
|
|
# Test date invalide (format)
|
|
try:
|
|
client._validate_date("2024/06/08")
|
|
print("❌ Format de date invalide non détecté")
|
|
except ValueError as e:
|
|
print(f"✅ Format de date invalide détecté: {e}")
|
|
|
|
# Test date invalide (date inexistante)
|
|
try:
|
|
client._validate_date("2024-02-30")
|
|
print("❌ Date inexistante non détectée")
|
|
except ValueError as e:
|
|
print(f"✅ Date inexistante détectée: {e}")
|
|
|
|
# Test date valide
|
|
try:
|
|
client._validate_date("2024-06-08")
|
|
print("✅ Date valide acceptée")
|
|
except ValueError as e:
|
|
print(f"❌ Date valide rejetée: {e}")
|
|
|
|
# Test code qualificatif ATMO invalide
|
|
try:
|
|
client._validate_code_qualificatif_atmo("8")
|
|
print("❌ Code qualificatif ATMO invalide non détecté")
|
|
except ValueError as e:
|
|
print(f"✅ Code qualificatif ATMO invalide détecté: {e}")
|
|
|
|
# Test code qualificatif ATMO valide
|
|
try:
|
|
client._validate_code_qualificatif_atmo("3")
|
|
print("✅ Code qualificatif ATMO valide accepté")
|
|
except ValueError as e:
|
|
print(f"❌ Code qualificatif ATMO valide rejeté: {e}")
|
|
|
|
# Test code qualificatif pollen invalide
|
|
try:
|
|
client._validate_code_qualificatif_pollen("7")
|
|
print("❌ Code qualificatif pollen invalide non détecté")
|
|
except ValueError as e:
|
|
print(f"✅ Code qualificatif pollen invalide détecté: {e}")
|
|
|
|
# Test code qualificatif pollen valide
|
|
try:
|
|
client._validate_code_qualificatif_pollen("4")
|
|
print("✅ Code qualificatif pollen valide accepté")
|
|
except ValueError as e:
|
|
print(f"❌ Code qualificatif pollen valide rejeté: {e}")
|
|
|
|
# Test type épisode invalide
|
|
try:
|
|
client._validate_type_episode("CRITIQUE")
|
|
print("❌ Type épisode invalide non détecté")
|
|
except ValueError as e:
|
|
print(f"✅ Type épisode invalide détecté: {e}")
|
|
|
|
# Test type épisode valide
|
|
try:
|
|
client._validate_type_episode("ALERTE")
|
|
print("✅ Type épisode valide accepté")
|
|
except ValueError as e:
|
|
print(f"❌ Type épisode valide rejeté: {e}")
|
|
|
|
# Test échéance invalide
|
|
try:
|
|
client._validate_echeance("2")
|
|
print("❌ Échéance invalide non détectée")
|
|
except ValueError as e:
|
|
print(f"✅ Échéance invalide détectée: {e}")
|
|
|
|
# Test échéance valide
|
|
try:
|
|
client._validate_echeance("-1")
|
|
print("✅ Échéance valide acceptée")
|
|
except ValueError as e:
|
|
print(f"❌ Échéance valide rejetée: {e}")
|
|
|
|
# Test échelle invalide
|
|
try:
|
|
client._validate_echelle("commune")
|
|
print("❌ Échelle invalide non détectée")
|
|
except ValueError as e:
|
|
print(f"✅ Échelle invalide détectée: {e}")
|
|
|
|
# Test échelle valide
|
|
try:
|
|
client._validate_echelle("epci")
|
|
print("✅ Échelle valide acceptée")
|
|
except ValueError as e:
|
|
print(f"❌ Échelle valide rejetée: {e}")
|
|
|
|
# Test secteur invalide
|
|
try:
|
|
client._validate_secteur("99")
|
|
print("❌ Secteur invalide non détecté")
|
|
except ValueError as e:
|
|
print(f"✅ Secteur invalide détecté: {e}")
|
|
|
|
# Test secteur valide
|
|
try:
|
|
client._validate_secteur("5")
|
|
print("✅ Secteur valide accepté")
|
|
except ValueError as e:
|
|
print(f"❌ Secteur valide rejeté: {e}")
|
|
|
|
# Test bounding box invalide (format)
|
|
try:
|
|
client._validate_bounding_box("2.2 48.8 2.4")
|
|
print("❌ Format bounding box invalide non détecté")
|
|
except ValueError as e:
|
|
print(f"✅ Format bounding box invalide détecté: {e}")
|
|
|
|
# Test bounding box invalide (coordonnées)
|
|
try:
|
|
client._validate_bounding_box("2.4 48.8 2.2 48.9")
|
|
print("❌ Coordonnées bounding box invalides non détectées")
|
|
except ValueError as e:
|
|
print(f"✅ Coordonnées bounding box invalides détectées: {e}")
|
|
|
|
# Test bounding box valide
|
|
try:
|
|
client._validate_bounding_box("2.2 48.8 2.4 48.9")
|
|
print("✅ Bounding box valide acceptée")
|
|
except ValueError as e:
|
|
print(f"❌ Bounding box valide rejetée: {e}")
|
|
|
|
print("\n=== Test des méthodes avec validations ===\n")
|
|
|
|
# Test méthode avec paramètres invalides
|
|
try:
|
|
client.get_indices_atmo(format="xml")
|
|
print("❌ Méthode avec format invalide non bloquée")
|
|
except ValueError as e:
|
|
print(f"✅ Méthode avec format invalide bloquée: {e}")
|
|
|
|
try:
|
|
client.get_episodes_3jours(aasqa="99")
|
|
print("❌ Méthode avec AASQA invalide non bloquée")
|
|
except ValueError as e:
|
|
print(f"✅ Méthode avec AASQA invalide bloquée: {e}")
|
|
|
|
try:
|
|
client.get_episodes_historique(date="2024/06/08")
|
|
print("❌ Méthode avec date invalide non bloquée")
|
|
except ValueError as e:
|
|
print(f"✅ Méthode avec date invalide bloquée: {e}")
|
|
|
|
try:
|
|
client.get_emissions(echelle="commune")
|
|
print("❌ Méthode avec échelle invalide non bloquée")
|
|
except ValueError as e:
|
|
print(f"✅ Méthode avec échelle invalide bloquée: {e}")
|
|
|
|
try:
|
|
client.get_indices_pollens(code_qualificatif="7")
|
|
print("❌ Méthode avec code qualificatif pollen invalide non bloquée")
|
|
except ValueError as e:
|
|
print(f"✅ Méthode avec code qualificatif pollen invalide bloquée: {e}")
|
|
|
|
print("\n=== Tests terminés ===")
|
|
|
|
|
|
def test_integration_examples():
|
|
"""Test d'intégration avec des exemples réalistes"""
|
|
print("\n=== Test d'intégration ===\n")
|
|
|
|
client = AtmoDataClient()
|
|
|
|
# Test avec paramètres valides (sans authentification)
|
|
try:
|
|
# Ces appels échoueront sur l'authentification mais les validations passeront
|
|
client.get_indices_atmo(
|
|
format="geojson",
|
|
date="2024-06-08",
|
|
aasqa="11",
|
|
code_qualificatif="3"
|
|
)
|
|
print("❌ Appel réussi sans authentification")
|
|
except ValueError as e:
|
|
print(f"❌ Validation échouée avec paramètres valides: {e}")
|
|
except Exception as e:
|
|
if "Token non disponible" in str(e):
|
|
print("✅ Validations réussies, échec sur l'authentification comme attendu")
|
|
else:
|
|
print(f"❌ Erreur inattendue: {e}")
|
|
|
|
try:
|
|
client.get_episodes_3jours(
|
|
format="csv",
|
|
polluant="PM10",
|
|
type_episode="ALERTE",
|
|
echeance="0"
|
|
)
|
|
print("❌ Appel réussi sans authentification")
|
|
except ValueError as e:
|
|
print(f"❌ Validation échouée avec paramètres valides: {e}")
|
|
except Exception as e:
|
|
if "Token non disponible" in str(e):
|
|
print("✅ Validations réussies, échec sur l'authentification comme attendu")
|
|
else:
|
|
print(f"❌ Erreur inattendue: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_validations()
|
|
test_integration_examples() |