#!/usr/bin/env python
import os
import sys
import django

# Setup Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'branch_system.settings')
django.setup()

from django.test import RequestFactory
from django.contrib.auth import get_user_model
from reports.views import reports_dashboard

def test_dashboard():
    print("=== Testing Dashboard View ===")
    
    # Create a mock request
    factory = RequestFactory()
    request = factory.get('/reports/')
    
    # Create a mock user
    User = get_user_model()
    user = User.objects.first()
    if not user:
        print("No users found in database")
        return
    
    request.user = user
    request.session = {}
    
    try:
        # Call the dashboard view
        response = reports_dashboard(request)
        print(f"Dashboard view returned status: {response.status_code}")
        
        if response.status_code == 200:
            print("Dashboard view executed successfully!")
        else:
            print(f"Dashboard view returned error status: {response.status_code}")
            
    except Exception as e:
        print(f"Error calling dashboard view: {e}")
        import traceback
        traceback.print_exc()

if __name__ == '__main__':
    test_dashboard()