fleetmind-dispatch-ai / test_directions.py
mashrur950's picture
Implement migrations for assignments management and testing framework
5b558e5
raw
history blame
3.27 kB
"""
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!")