File size: 7,417 Bytes
7466735
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""

Final System Test - Verify Everything Works

"""
from backend.database_api import DatabaseAPI, transform_parking_lots_for_ai
from datetime import datetime, timedelta
import json

def print_header(title):
    print("\n" + "="*70)
    print(f"πŸ§ͺ {title}")
    print("="*70)

def main():
    print("""

╔══════════════════════════════════════════════════════════════════╗

β•‘                   SMART PARKING SYSTEM                            β•‘

β•‘                   FINAL SYSTEM TEST                               β•‘

β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

""")
    
    api = DatabaseAPI()
    results = {}
    
    # Test 1: Get Available Slots
    print_header("TEST 1: Get Available Parking Slots")
    try:
        result = api.get_all_available_slots()
        if result['status'] == 'success' and result.get('data'):
            slots = result['data']
            print(f"βœ… PASSED - Found {len(slots)} available slot(s)")
            print(f"   Sample: {slots[0].get('lot_name')}-{slots[0].get('slot_number')}")
            results['Get Slots'] = True
        else:
            print(f"❌ FAILED - No slots found")
            results['Get Slots'] = False
    except Exception as e:
        print(f"❌ FAILED - {e}")
        results['Get Slots'] = False
    
    # Test 2: AI Data Transformation
    print_header("TEST 2: AI Data Transformation")
    try:
        slots_result = api.get_all_available_slots()
        if slots_result['status'] == 'success':
            transformed = transform_parking_lots_for_ai(slots_result['data'])
            if transformed:
                print(f"βœ… PASSED - Transformed {len(transformed)} slot(s) for AI")
                sample = transformed[0]
                print(f"   Slot ID: {sample['slot_id']}")
                print(f"   Coordinates: ({sample['latitude']}, {sample['longitude']})")
                print(f"   Price: β‚Ή{sample['price_per_hour']}/hr")
                results['AI Transform'] = True
            else:
                print(f"❌ FAILED - No transformed data")
                results['AI Transform'] = False
    except Exception as e:
        print(f"❌ FAILED - {e}")
        results['AI Transform'] = False
    
    # Test 3: User Registration
    print_header("TEST 3: User Registration")
    try:
        result = api.register_user(
            name="System Test User",
            phone="+919876543210",
            email="systest@parking.com"
        )
        if result['status'] == 'success':
            print(f"βœ… PASSED - {result.get('message')}")
            results['User Registration'] = True
        else:
            print(f"❌ FAILED - {result.get('message')}")
            results['User Registration'] = False
    except Exception as e:
        print(f"❌ FAILED - {e}")
        results['User Registration'] = False
    
    # Test 4: Create Booking
    print_header("TEST 4: Create Booking")
    booking_uid = None
    try:
        start_time = datetime.now()
        end_time = start_time + timedelta(hours=2)
        
        result = api.book_slot(
            user_id=9,  # Known existing user
            slot_id=1,  # Known existing slot
            start_time=start_time.strftime("%Y-%m-%d %H:%M:%S"),
            end_time=end_time.strftime("%Y-%m-%d %H:%M:%S"),
            total_amount=120.0
        )
        
        if result['status'] == 'success':
            booking_uid = result.get('booking_uid')
            print(f"βœ… PASSED - Booking created")
            print(f"   Booking UID: {booking_uid}")
            results['Create Booking'] = True
        else:
            print(f"❌ FAILED - {result.get('message')}")
            results['Create Booking'] = False
    except Exception as e:
        print(f"❌ FAILED - {e}")
        results['Create Booking'] = False
    
    # Test 5: Get Booking Status
    if booking_uid:
        print_header("TEST 5: Get Booking Status")
        try:
            result = api.get_booking_status(booking_uid)
            if result['status'] == 'success' and result.get('data'):
                booking = result['data']
                print(f"βœ… PASSED - Booking retrieved")
                print(f"   Status: {booking.get('status')}")
                print(f"   Payment: {booking.get('payment_status')}")
                print(f"   Amount: β‚Ή{booking.get('total_amount')}")
                results['Get Booking'] = True
            else:
                print(f"❌ FAILED - Booking not found")
                results['Get Booking'] = False
        except Exception as e:
            print(f"❌ FAILED - {e}")
            results['Get Booking'] = False
    else:
        print_header("TEST 5: Get Booking Status")
        print("⏭️  SKIPPED - No booking created")
        results['Get Booking'] = None
    
    # Test 6: Update Payment
    if booking_uid:
        print_header("TEST 6: Update Payment Status")
        try:
            result = api.update_payment(
                booking_uid=booking_uid,
                payment_status='Paid',
                transaction_id=f'txn_test_{booking_uid}',
                amount=120.0
            )
            if result['status'] == 'success':
                print(f"βœ… PASSED - Payment updated to Paid")
                results['Update Payment'] = True
            else:
                print(f"❌ FAILED - {result.get('message')}")
                results['Update Payment'] = False
        except Exception as e:
            print(f"❌ FAILED - {e}")
            results['Update Payment'] = False
    else:
        print_header("TEST 6: Update Payment Status")
        print("⏭️  SKIPPED - No booking created")
        results['Update Payment'] = None
    
    # Summary
    print("\n" + "="*70)
    print("πŸ“Š TEST SUMMARY")
    print("="*70)
    
    passed = sum(1 for v in results.values() if v is True)
    failed = sum(1 for v in results.values() if v is False)
    skipped = sum(1 for v in results.values() if v is None)
    total = passed + failed
    
    for test_name, result in results.items():
        if result is True:
            print(f"βœ… PASSED: {test_name}")
        elif result is False:
            print(f"❌ FAILED: {test_name}")
        else:
            print(f"⏭️  SKIPPED: {test_name}")
    
    print("\n" + "="*70)
    print(f"Total: {passed}/{total} tests passed")
    if skipped:
        print(f"Skipped: {skipped} test(s)")
    
    if passed == total and total > 0:
        print("\nπŸŽ‰ ALL TESTS PASSED! System is ready!")
    elif passed >= total * 0.8:
        print("\nβœ… Most tests passed! System is functional!")
    else:
        print("\n⚠️  Some tests failed. Check the output above.")
    
    print("\nπŸ’‘ To start the API server:")
    print("   python backend/main.py")
    print("\nπŸ“– For more info, see:")
    print("   - SUCCESS_SUMMARY.md")
    print("   - TESTING_GUIDE.md")
    print("="*70)

if __name__ == "__main__":
    main()