File size: 3,274 Bytes
5b558e5 |
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 |
"""
Quick test to verify route directions are being stored
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from chat.tools import (
handle_create_order,
handle_create_driver,
handle_create_assignment,
handle_get_assignment_details
)
print("=" * 70)
print("Testing Route Directions Storage")
print("=" * 70)
# Create test order
print("\n[1] Creating test order...")
order_result = handle_create_order({
"customer_name": "Direction Test Customer",
"customer_phone": "+8801712345678",
"delivery_address": "Tejgaon College, Dhaka",
"delivery_lat": 23.7549,
"delivery_lng": 90.3909,
"priority": "standard",
"weight_kg": 5.0
})
if not order_result.get("success"):
print(f"FAILED: {order_result.get('error')}")
sys.exit(1)
order_id = order_result["order_id"]
print(f"SUCCESS: Order created: {order_id}")
# Create test driver
print("\n[2] Creating test driver...")
driver_result = handle_create_driver({
"name": "Direction Test Driver",
"phone": "+8801812345678",
"vehicle_type": "motorcycle",
"current_lat": 23.7808,
"current_lng": 90.4130
})
if not driver_result.get("success"):
print(f"FAILED: {driver_result.get('error')}")
sys.exit(1)
driver_id = driver_result["driver_id"]
print(f"SUCCESS: Driver created: {driver_id}")
# Create assignment (this should now store directions)
print("\n[3] Creating assignment with route directions...")
assignment_result = handle_create_assignment({
"order_id": order_id,
"driver_id": driver_id
})
if not assignment_result.get("success"):
print(f"FAILED: {assignment_result.get('error')}")
sys.exit(1)
assignment_id = assignment_result["assignment_id"]
print(f"SUCCESS: Assignment created: {assignment_id}")
# Get assignment details to verify directions are stored
print("\n[4] Retrieving assignment details to check directions...")
details_result = handle_get_assignment_details({
"assignment_id": assignment_id
})
if not details_result.get("success"):
print(f"FAILED: {details_result.get('error')}")
sys.exit(1)
assignment = details_result.get("assignment", {})
route = assignment.get("route", {})
directions = route.get("directions")
if directions:
print(f"SUCCESS: Route directions are stored!")
print(f" Number of steps: {len(directions)}")
print(f"\n First 3 steps:")
for i, step in enumerate(directions[:3], 1):
instruction = step.get("instruction", "N/A")
# Distance might be int (meters) or dict with text
distance_val = step.get("distance", 0)
if isinstance(distance_val, dict):
distance = distance_val.get("text", "N/A")
else:
distance = f"{distance_val}m"
print(f" {i}. {instruction} ({distance})")
else:
print("WARNING: No directions found in assignment")
print(f" This might mean the Routes API didn't return step-by-step directions")
print("\n" + "=" * 70)
print("Test Complete!")
print("=" * 70)
# Cleanup
print("\nCleaning up test data...")
from chat.tools import handle_delete_order, handle_delete_driver
handle_delete_order({"order_id": order_id, "confirm": True})
handle_delete_driver({"driver_id": driver_id, "confirm": True})
print("Cleanup complete!")
|