Spaces:
Sleeping
Sleeping
File size: 5,052 Bytes
6bd3e57 | 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 | """
Test script for the quote generation tool.
"""
import sys
import os
# Add the src directory to the path so we can import from sales_assistant
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
from sales_assistant.agent_tools.create_quote import create_quote, create_sample_quote
def test_basic_quote():
"""Test basic quote creation functionality."""
print("=== Testing Basic Quote Creation ===")
# Test data
sample_items = [
{
"product_name": "Samsung Galaxy S24 Ultra",
"description": "Samsung Galaxy S24 Ultra 512GB, Titanium Black, 5G smartphone with S Pen",
"quantity": 1,
"unit_price": 1399.99,
"currency": "EUR"
},
{
"product_name": "Apple MacBook Pro 14\"",
"description": "MacBook Pro 14-inch, M3 Pro chip, 18GB RAM, 512GB SSD, Space Black",
"quantity": 2,
"unit_price": 2499.00,
"currency": "EUR"
}
]
# Invoke the tool
result = create_quote.invoke({
"customer_name": "Alice Johnson",
"customer_email": "alice.johnson@company.com",
"customer_company": "Innovation Labs Inc.",
"customer_address": "456 Tech Street, Silicon Valley, CA 94000",
"customer_phone": "+1 (555) 987-6543",
"items": sample_items,
"target_currency": "EUR",
"tax_rate": 0.21, # 21% VAT
"notes": "Corporate discount applied"
})
print("Result:")
print(result)
return result
def test_currency_conversion():
"""Test quote creation with currency conversion."""
print("\n=== Testing Currency Conversion ===")
# Items in different currencies
mixed_currency_items = [
{
"product_name": "Dell XPS 15",
"description": "Dell XPS 15 laptop, Intel i7, 16GB RAM, 1TB SSD",
"quantity": 1,
"unit_price": 1899.99,
"currency": "USD" # Will be converted to EUR
},
{
"product_name": "Sony Camera",
"description": "Sony Alpha 7R V mirrorless camera with 61MP sensor",
"quantity": 1,
"unit_price": 3899.00,
"currency": "EUR" # Already in target currency
}
]
result = create_quote.invoke({
"customer_name": "Bob Wilson",
"customer_email": "bob@techstudio.com",
"customer_company": "TechStudio Photography",
"items": mixed_currency_items,
"target_currency": "EUR"
})
print("Result:")
print(result)
return result
def test_single_item_quote():
"""Test quote with single item."""
print("\n=== Testing Single Item Quote ===")
single_item = [{
"product_name": "iPad Pro 12.9\"",
"description": "iPad Pro 12.9-inch (6th generation) with M2 chip, 128GB, WiFi",
"quantity": 3,
"unit_price": 1199.00,
"currency": "EUR"
}]
result = create_quote.invoke({
"customer_name": "Carol Davis",
"customer_email": "carol@school.edu",
"customer_company": "Mountain View School District",
"items": single_item,
"target_currency": "EUR",
"tax_rate": 0.0, # Tax-exempt organization
"notes": "Educational institution - tax exempt"
})
print("Result:")
print(result)
return result
def test_error_handling():
"""Test error handling in quote creation."""
print("\n=== Testing Error Handling ===")
# Test missing customer name
print("Test 1: Missing customer name")
result1 = create_quote.invoke({
"customer_name": "",
"items": [{"product_name": "Test", "description": "Test", "quantity": 1, "unit_price": 100}]
})
print("Result:", result1)
# Test empty items
print("\nTest 2: Empty items list")
result2 = create_quote.invoke({
"customer_name": "Test Customer",
"items": []
})
print("Result:", result2)
# Test invalid item data
print("\nTest 3: Invalid item data")
result3 = create_quote.invoke({
"customer_name": "Test Customer",
"items": [{"product_name": "Test", "quantity": "invalid", "unit_price": "invalid"}]
})
print("Result:", result3)
def test_sample_quote_function():
"""Test the sample quote creation function."""
print("\n=== Testing Sample Quote Function ===")
result = create_sample_quote()
print("Sample quote result:")
print(result)
return result
if __name__ == "__main__":
print("🧪 Starting Quote Generation Tool Tests\n")
try:
# Run all tests
test_basic_quote()
test_currency_conversion()
test_single_item_quote()
test_sample_quote_function()
test_error_handling()
print("\n✅ All tests completed!")
except Exception as e:
print(f"\n❌ Test failed with error: {e}")
import traceback
traceback.print_exc()
|