krinya's picture
Refactor code structure and remove redundant sections for improved readability and maintainability
6bd3e57
Raw
History Blame Contribute Delete
5.05 kB
"""
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()