"""test_webapp.py - Basic tests for webapp"""

import sys
from pathlib import Path

PROJECT_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(PROJECT_ROOT))

def test_webapp_import():
    """Test that webapp can be imported"""
    print("\n=== Test: webapp import ===")
    try:
        import webapp
        print("PASS: webapp imported successfully")
        return True
    except Exception as e:
        print(f"FAIL: {e}")
        return False

def test_models_loaded():
    """Test that models.yaml is loaded"""
    print("\n=== Test: models loaded ===")
    try:
        import webapp
        if len(webapp.MODELS_CONFIG.get('models', [])) > 0:
            print("PASS: Models loaded from models.yaml")
            return True
        print("FAIL: No models loaded")
        return False
    except Exception as e:
        print(f"FAIL: {e}")
        return False

def test_html_template():
    """Test that HTML template exists"""
    print("\n=== Test: HTML template ===")
    try:
        import webapp
        if len(webapp.HTML_TEMPLATE) > 100:
            print("PASS: HTML template exists")
            return True
        print("FAIL: HTML template too short")
        return False
    except Exception as e:
        print(f"FAIL: {e}")
        return False

if __name__ == '__main__':
    print("=" * 60)
    print("Webapp Tests")
    print("=" * 60)
    
    tests = [test_webapp_import, test_models_loaded, test_html_template]
    results = []
    
    for test in tests:
        try:
            results.append(test())
        except Exception as e:
            print(f"ERROR: {e}")
            results.append(False)
    
    print("\n" + "=" * 60)
    print(f"Results: {sum(results)}/{len(results)} passed")
    print("=" * 60)
    
    sys.exit(0 if all(results) else 1)
