Skip to content

Commit 0710856

Browse files
Testcases
1 parent f0c0590 commit 0710856

File tree

3 files changed

+755
-97
lines changed

3 files changed

+755
-97
lines changed

src/backend/tests/agents/test_product.py

Lines changed: 107 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import os
22
import sys
33
from unittest.mock import MagicMock
4-
import pytest
54

6-
# Mock Azure SDK dependencies
5+
# --- Fake missing Azure modules ---
6+
sys.modules["azure.monitor.events"] = MagicMock()
77
sys.modules["azure.monitor.events.extension"] = MagicMock()
88

9-
# Set up environment variables
9+
import time
10+
import asyncio
11+
import pytest
12+
from datetime import datetime
13+
14+
# Adjust sys.path so that the project root is found.
15+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../")))
16+
17+
# Set required environment variables before importing modules that depend on them.
1018
os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint"
1119
os.environ["COSMOSDB_KEY"] = "mock-key"
1220
os.environ["COSMOSDB_DATABASE"] = "mock-database"
@@ -15,12 +23,13 @@
1523
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01"
1624
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint"
1725

18-
19-
# Import the required functions for testing
26+
# Import product functions and classes.
2027
from src.backend.agents.product import (
2128
add_mobile_extras_pack,
2229
get_product_info,
30+
get_billing_date,
2331
update_inventory,
32+
add_new_product,
2433
schedule_product_launch,
2534
analyze_sales_data,
2635
get_customer_feedback,
@@ -39,27 +48,64 @@
3948
optimize_product_page,
4049
track_product_shipment,
4150
evaluate_product_performance,
51+
coordinate_with_marketing,
52+
review_product_quality,
53+
collaborate_with_tech_team,
54+
update_product_description,
55+
manage_product_returns,
56+
conduct_product_survey,
57+
update_product_specifications,
58+
organize_product_photoshoot,
59+
manage_product_listing,
60+
set_product_availability,
61+
coordinate_with_logistics,
62+
calculate_product_margin,
63+
update_product_category,
64+
manage_product_bundles,
65+
monitor_product_performance,
66+
handle_product_pricing,
67+
develop_product_training_material,
68+
update_product_labels,
69+
manage_product_warranty,
70+
handle_product_licensing,
71+
manage_product_packaging,
72+
set_product_safety_standards,
73+
develop_product_features,
74+
evaluate_product_performance,
75+
manage_custom_product_orders,
76+
update_product_images,
77+
handle_product_obsolescence,
78+
manage_product_sku,
79+
provide_product_training,
80+
get_product_tools,
4281
)
4382

83+
from src.backend.agents.product import ProductAgent
84+
from autogen_core.components.models import AzureOpenAIChatCompletionClient
85+
from autogen_core.base import AgentId
86+
from autogen_core.components.tools import FunctionTool, Tool
87+
from src.backend.context.cosmos_memory import CosmosBufferedChatCompletionContext
88+
from src.backend.agents.base_agent import BaseAgent
89+
90+
# --- Tests for Product Functions ---
4491

45-
# Parameterized tests for repetitive cases
4692
@pytest.mark.asyncio
4793
@pytest.mark.parametrize(
4894
"function, args, expected_substrings",
4995
[
50-
(add_mobile_extras_pack, ("Roaming Pack", "2025-01-01"), ["Roaming Pack", "2025-01-01"]),
96+
(add_mobile_extras_pack, ("Roaming Pack", "2025-01-01"), ["Roaming Pack", "2025-01-01", "AGENT SUMMARY:"]),
5197
(get_product_info, (), ["Simulated Phone Plans", "Plan A"]),
5298
(update_inventory, ("Product A", 50), ["Inventory for", "Product A"]),
5399
(schedule_product_launch, ("New Product", "2025-02-01"), ["New Product", "2025-02-01"]),
54100
(analyze_sales_data, ("Product B", "Last Quarter"), ["Sales data for", "Product B"]),
55101
(get_customer_feedback, ("Product C",), ["Customer feedback for", "Product C"]),
56102
(manage_promotions, ("Product A", "10% off for summer"), ["Promotion for", "Product A"]),
57-
(handle_product_recall, ("Product A", "Defective batch"), ["Product recall for", "Defective batch"]),
58-
(set_product_discount, ("Product A", 15.0), ["Discount for", "15.0%"]),
59-
(manage_supply_chain, ("Product A", "Supplier X"), ["Supply chain for", "Supplier X"]),
60103
(check_inventory, ("Product A",), ["Inventory status for", "Product A"]),
61104
(update_product_price, ("Product A", 99.99), ["Price for", "$99.99"]),
62105
(provide_product_recommendations, ("High Performance",), ["Product recommendations", "High Performance"]),
106+
(handle_product_recall, ("Product A", "Defective batch"), ["Product recall for", "Defective batch"]),
107+
(set_product_discount, ("Product A", 15.0), ["Discount for", "15.0%"]),
108+
(manage_supply_chain, ("Product A", "Supplier X"), ["Supply chain for", "Supplier X"]),
63109
(forecast_product_demand, ("Product A", "Next Month"), ["Demand for", "Next Month"]),
64110
(handle_product_complaints, ("Product A", "Complaint about quality"), ["Complaint for", "Product A"]),
65111
(generate_product_report, ("Product A", "Sales"), ["Sales report for", "Product A"]),
@@ -74,9 +120,55 @@ async def test_product_functions(function, args, expected_substrings):
74120
for substring in expected_substrings:
75121
assert substring in result
76122

77-
78-
# Specific test for monitoring market trends
123+
# --- Extra parameterized tests for remaining functions ---
79124
@pytest.mark.asyncio
80-
async def test_monitor_market_trends():
81-
result = await monitor_market_trends()
82-
assert "Market trends monitored" in result
125+
@pytest.mark.parametrize(
126+
"function, args, expected_substrings",
127+
[
128+
(get_billing_date, (), ["Billing Date"]),
129+
(add_new_product, ("New smartwatch with health tracking.",), ["New Product Added", "New smartwatch"]),
130+
(coordinate_with_marketing, ("Smartphone", "Campaign XYZ"), ["Marketing Coordination", "Campaign XYZ"]),
131+
(review_product_quality, ("Monitor",), ["Quality review", "Monitor"]),
132+
(collaborate_with_tech_team, ("Drone", "Improve battery efficiency"), ["Tech Team Collaboration", "Improve battery"]),
133+
(update_product_description, ("Smartwatch", "Sleek design"), ["Product Description Updated", "Sleek design"]),
134+
(manage_product_returns, ("Printer", "Paper jam"), ["Product Return Managed", "Paper jam"]),
135+
(conduct_product_survey, ("Monitor", "Online survey"), ["Product Survey Conducted", "Online survey"]),
136+
(update_product_specifications, ("TV", "1080p, 60Hz"), ["Product Specifications Updated", "1080p, 60Hz"]),
137+
(organize_product_photoshoot, ("Camera", "2023-06-01"), ["Photoshoot Organized", "2023-06-01"]),
138+
(manage_product_listing, ("Tablet", "Listed on Amazon"), ["Product Listing Managed", "Amazon"]),
139+
(set_product_availability, ("Laptop", True), ["available"]),
140+
(set_product_availability, ("Laptop", False), ["unavailable"]),
141+
(coordinate_with_logistics, ("Speaker", "Pickup scheduled"), ["Logistics Coordination", "Pickup scheduled"]),
142+
(calculate_product_margin, ("Laptop", 500, 1000), ["Profit margin", "50.00%"]),
143+
(update_product_category, ("Phone", "Electronics"), ["Product Category Updated", "Electronics"]),
144+
(manage_product_bundles, ("Bundle1", ["Phone", "Charger"]), ["Product Bundle Managed", "Phone", "Charger"]),
145+
(monitor_product_performance, ("Camera",), ["Product Performance Monitored", "Camera"]),
146+
(handle_product_pricing, ("TV", "Dynamic pricing"), ["Pricing Strategy Set", "Dynamic pricing"]),
147+
(develop_product_training_material, ("Router", "Video tutorial"), ["Training Material Developed", "Video tutorial"]),
148+
(update_product_labels, ("Smartphone", "New, Hot"), ["Product Labels Updated", "New, Hot"]),
149+
(manage_product_warranty, ("Laptop", "2-year warranty"), ["Product Warranty Managed", "2-year warranty"]),
150+
(handle_product_licensing, ("Software", "GPL License"), ["Product Licensing Handled", "GPL License"]),
151+
(manage_product_packaging, ("Laptop", "Eco-friendly packaging"), ["Product Packaging Managed", "Eco-friendly packaging"]),
152+
(set_product_safety_standards, ("Refrigerator", "ISO 9001"), ["Safety standards", "ISO 9001"]),
153+
(develop_product_features, ("Smart TV", "Voice control, facial recognition"), ["New Features Developed", "Voice control"]),
154+
(manage_custom_product_orders, ("Custom engraving required",), ["Custom Product Order Managed", "Custom engraving"]),
155+
(update_product_images, ("Camera", ["http://example.com/img1.jpg", "http://example.com/img2.jpg"]), ["Product Images Updated", "img1.jpg", "img2.jpg"]),
156+
(handle_product_obsolescence, ("DVD Player",), ["Product Obsolescence Handled", "DVD Player"]),
157+
(manage_product_sku, ("Phone", "SKU12345"), ["SKU Managed", "SKU12345"]),
158+
(provide_product_training, ("Tablet", "In-person training session"), ["Product Training Provided", "In-person training session"]),
159+
],
160+
)
161+
async def test_product_functions_extra(function, args, expected_substrings):
162+
result = await function(*args)
163+
for substring in expected_substrings:
164+
assert substring in result
165+
166+
167+
# --- Test get_product_tools ---
168+
def test_get_product_tools():
169+
tools = get_product_tools()
170+
assert isinstance(tools, list)
171+
from autogen_core.components.tools import FunctionTool
172+
assert any(isinstance(tool, FunctionTool) for tool in tools)
173+
names = [tool.name for tool in tools]
174+
assert "add_mobile_extras_pack" in names or "get_product_info" in names

0 commit comments

Comments
 (0)