Spaces:
Sleeping
Sleeping
File size: 2,191 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 |
"""
Test booking with valid user_id
"""
import requests
import json
from datetime import datetime, timedelta
base_url = "https://aadarshsenapati.in/api/api.php"
print("=" * 70)
print("TESTING BOOKING WITH DIFFERENT USER IDs")
print("=" * 70)
# Prepare booking data
start_time = datetime.now()
end_time = start_time + timedelta(hours=2)
# Try different user IDs
user_ids_to_try = [1, 9, 10]
for user_id in user_ids_to_try:
print(f"\n{'='*70}")
print(f"π§ͺ Testing with user_id: {user_id}")
print('='*70)
booking_data = {
"user_id": user_id,
"slot_id": 1,
"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
}
try:
response = requests.post(
f"{base_url}?action=book_slot",
json=booking_data,
headers={'Content-Type': 'application/json'},
timeout=10
)
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
try:
result = response.json()
print(f"β
SUCCESS!")
print(f"Response: {json.dumps(result, indent=2)}")
if result.get('status') == 'success':
print(f"\nπ Booking created successfully!")
print(f" Booking UID: {result.get('booking_uid')}")
print(f" User ID: {user_id} β
WORKS!")
break # Stop after first success
except:
print(f"β οΈ Response is not JSON: {response.text[:200]}")
else:
print(f"β FAILED with user_id: {user_id}")
except Exception as e:
print(f"β Error: {e}")
print("\n" + "=" * 70)
print("π‘ RECOMMENDATION:")
print("=" * 70)
print("""
The booking endpoint works, but specific user_ids may not exist.
Solutions:
1. Use user_id that exists (like 9 from your manual test)
2. Create user_id = 1 in database
3. Update Python code to use existing user_id
""")
|