Skip to content

Commit ab92475

Browse files
Testcases
1 parent 39b1f53 commit ab92475

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
lines changed

src/backend/tests/agents/test_procurement.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
import os
2+
import sys
23
import pytest
34
from unittest.mock import MagicMock
45

5-
# Mock modules and environment variables
6-
import sys
7-
sys.modules['azure.monitor.events.extension'] = MagicMock()
8-
9-
os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint"
10-
os.environ["COSMOSDB_KEY"] = "mock-key"
11-
os.environ["COSMOSDB_DATABASE"] = "mock-database"
12-
os.environ["COSMOSDB_CONTAINER"] = "mock-container"
13-
os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"] = "mock-deployment-name"
14-
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01"
15-
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint"
16-
17-
186
# Import the procurement tools for testing
197
from src.backend.agents.procurement import (
208
order_hardware,
@@ -41,6 +29,16 @@
4129
track_procurement_metrics,
4230
)
4331

32+
sys.modules["azure.monitor.events.extension"] = MagicMock()
33+
34+
os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint"
35+
os.environ["COSMOSDB_KEY"] = "mock-key"
36+
os.environ["COSMOSDB_DATABASE"] = "mock-database"
37+
os.environ["COSMOSDB_CONTAINER"] = "mock-container"
38+
os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"] = "mock-deployment-name"
39+
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01"
40+
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint"
41+
4442

4543
# Test cases for the async functions
4644
@pytest.mark.asyncio
@@ -70,7 +68,9 @@ async def test_process_purchase_order():
7068
@pytest.mark.asyncio
7169
async def test_initiate_contract_negotiation():
7270
result = await initiate_contract_negotiation("VendorX", "Exclusive deal for 2025")
73-
assert "Contract negotiation initiated with VendorX: Exclusive deal for 2025" in result
71+
assert (
72+
"Contract negotiation initiated with VendorX: Exclusive deal for 2025" in result
73+
)
7474

7575

7676
@pytest.mark.asyncio
@@ -93,7 +93,9 @@ async def test_manage_vendor_relationship():
9393

9494
@pytest.mark.asyncio
9595
async def test_update_procurement_policy():
96-
result = await update_procurement_policy("Policy2025", "Updated terms and conditions")
96+
result = await update_procurement_policy(
97+
"Policy2025", "Updated terms and conditions"
98+
)
9799
assert "Procurement policy 'Policy2025' updated." in result
98100

99101

@@ -335,7 +337,9 @@ async def test_track_order_invalid_number():
335337

336338
@pytest.mark.asyncio
337339
async def test_initiate_contract_negotiation_long_details():
338-
long_details = "This is a very long contract negotiation detail for testing purposes. " * 10
340+
long_details = (
341+
"This is a very long contract negotiation detail for testing purposes. " * 10
342+
)
339343
result = await initiate_contract_negotiation("VendorY", long_details)
340344
assert "Contract negotiation initiated with VendorY" in result
341345
assert long_details in result
@@ -513,7 +517,9 @@ async def test_handle_return_negative_and_zero_quantity():
513517
result_negative = await handle_return("Laptop", -5, "Damaged")
514518
result_zero = await handle_return("Laptop", 0, "Packaging Issue")
515519
assert "Processed return of -5 units of Laptop due to Damaged." in result_negative
516-
assert "Processed return of 0 units of Laptop due to Packaging Issue." in result_zero
520+
assert (
521+
"Processed return of 0 units of Laptop due to Packaging Issue." in result_zero
522+
)
517523

518524

519525
@pytest.mark.asyncio
@@ -666,4 +672,3 @@ async def test_order_software_license_invalid_cases():
666672
result_zero_quantity = await order_software_license("Photoshop", "Single User", 0)
667673
assert "Ordered 5 licenses of Photoshop." in result_empty_type
668674
assert "Ordered 0 Single User licenses of Photoshop." in result_zero_quantity
669-

src/backend/tests/agents/test_product.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
import os
2+
import sys
23
import pytest
34
from unittest.mock import MagicMock
5+
# Import functions directly from product.py for testing
6+
from src.backend.agents.product import (
7+
add_mobile_extras_pack,
8+
get_product_info,
9+
update_inventory,
10+
schedule_product_launch,
11+
analyze_sales_data,
12+
get_customer_feedback,
13+
manage_promotions,
14+
set_reorder_level,
15+
check_inventory,
16+
update_product_price,
17+
provide_product_recommendations,
18+
handle_product_recall,
19+
set_product_discount,
20+
manage_supply_chain,
21+
forecast_product_demand,
22+
handle_product_complaints,
23+
monitor_market_trends,
24+
generate_product_report,
25+
develop_new_product_ideas,
26+
optimize_product_page,
27+
track_product_shipment,
28+
evaluate_product_performance,
29+
)
430

5-
# Mock the azure.monitor.events.extension module globally
6-
import sys
731
sys.modules['azure.monitor.events.extension'] = MagicMock()
832

933
# Set environment variables to mock dependencies
@@ -15,6 +39,7 @@
1539
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01"
1640
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint"
1741

42+
1843
# Import functions directly from product.py for testing
1944
from src.backend.agents.product import (
2045
add_mobile_extras_pack,
@@ -39,7 +64,6 @@
3964
optimize_product_page,
4065
track_product_shipment,
4166
evaluate_product_performance,
42-
4367
)
4468

4569

@@ -227,7 +251,7 @@ async def test_handle_product_recall_valid():
227251
result = await handle_product_recall("Product B", "Safety concerns")
228252
assert "Product recall for" in result
229253
assert "Product B" in result
230-
assert "Safety concerns" in result
254+
assert "Safety concerns" in result
231255

232256

233257
@pytest.mark.asyncio
@@ -346,7 +370,7 @@ async def test_manage_supply_chain_empty_supplier():
346370
@pytest.mark.asyncio
347371
async def test_analyze_sales_data_invalid_period():
348372
result = await analyze_sales_data("Product R", "InvalidPeriod")
349-
assert "Sales data for **'Product R'** over **InvalidPeriod** analyzed." in result
373+
assert "Sales data for **'Product R'** over **InvalidPeriod** analyzed." in result
350374

351375

352376
# Test `update_product_price` with zero price
@@ -478,4 +502,3 @@ async def test_generate_product_report_detailed_type():
478502
async def test_update_product_price_high_precision():
479503
result = await update_product_price("Product AG", 123.456789)
480504
assert "Price for **'Product AG'** updated to **$123.46**." in result
481-

0 commit comments

Comments
 (0)