#!/usr/bin/env python3 """ Egyszerű teszt a Gondos Gazda Index API végponthoz - import hibák elkerülésével. """ import asyncio import sys import os # Ideiglenes megoldás: mockoljuk a hiányzó importokat import unittest.mock as mock # Mock the missing imports before importing trust_engine sys.modules['app.models.asset'] = mock.Mock() sys.modules['app.models.service'] = mock.Mock() sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend')) from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.orm import sessionmaker from app.database import AsyncSessionLocal from app.services.trust_engine import TrustEngine from app.models.identity import User async def test_trust_engine(): """Teszteli a TrustEngine működését.""" print("TrustEngine teszt indítása...") # Adatbázis kapcsolat engine = create_async_engine( "postgresql+asyncpg://postgres:postgres@localhost:5432/service_finder", echo=False ) async_session = sessionmaker( engine, class_=AsyncSession, expire_on_commit=False ) async with async_session() as db: # Keressünk egy teszt felhasználót from sqlalchemy import select stmt = select(User).limit(1) result = await db.execute(stmt) user = result.scalar_one_or_none() if not user: print("Nincs felhasználó az adatbázisban, teszt felhasználó létrehozása...") # Egyszerűsítés: csak kiírjuk, hogy nincs felhasználó print("Nincs felhasználó, a teszt kihagyva.") return print(f"Teszt felhasználó: {user.email} (ID: {user.id})") # TrustEngine példányosítás trust_engine = TrustEngine() # Trust számítás (force_recalculate=True, hogy biztosan számoljon) try: trust_data = await trust_engine.calculate_user_trust(db, user.id, force_recalculate=True) print("\n=== Trust Score Eredmény ===") print(f"Trust Score: {trust_data['trust_score']}/100") print(f"Maintenance Score: {trust_data['maintenance_score']:.2f}") print(f"Quality Score: {trust_data['quality_score']:.2f}") print(f"Preventive Score: {trust_data['preventive_score']:.2f}") print(f"Last Calculated: {trust_data['last_calculated']}") if trust_data['weights']: print(f"\nSúlyozások:") for key, value in trust_data['weights'].items(): print(f" {key}: {value:.2f}") if trust_data['tolerance_km']: print(f"Tolerancia KM: {trust_data['tolerance_km']}") # Ellenőrizzük, hogy a UserTrustProfile létrejött-e from sqlalchemy import select from app.models.identity import UserTrustProfile stmt = select(UserTrustProfile).where(UserTrustProfile.user_id == user.id) result = await db.execute(stmt) profile = result.scalar_one_or_none() if profile: print(f"\nUserTrustProfile létrehozva:") print(f" Trust Score: {profile.trust_score}") print(f" Last Calculated: {profile.last_calculated}") else: print("\nFIGYELEM: UserTrustProfile nem jött létre!") print("\n✅ TrustEngine sikeresen működik!") except Exception as e: print(f"\n❌ Hiba történt: {e}") import traceback traceback.print_exc() if __name__ == "__main__": asyncio.run(test_trust_engine())