|
| 1 | +# Corrected imports at the top of the file |
1 | 2 | import os |
2 | 3 | import sys |
3 | 4 | import pytest |
4 | 5 | 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 | | -) |
30 | 6 |
|
31 | | -sys.modules['azure.monitor.events.extension'] = MagicMock() |
| 7 | +# Mock modules and environment variables |
| 8 | +sys.modules["azure.monitor.events.extension"] = MagicMock() |
32 | 9 |
|
33 | | -# Set environment variables to mock dependencies |
34 | 10 | os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint" |
35 | 11 | os.environ["COSMOSDB_KEY"] = "mock-key" |
36 | 12 | os.environ["COSMOSDB_DATABASE"] = "mock-database" |
|
39 | 15 | os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01" |
40 | 16 | os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint" |
41 | 17 |
|
42 | | - |
43 | | -# Import functions directly from product.py for testing |
| 18 | +# Import the required functions for testing |
44 | 19 | from src.backend.agents.product import ( |
45 | 20 | add_mobile_extras_pack, |
46 | 21 | get_product_info, |
|
49 | 24 | analyze_sales_data, |
50 | 25 | get_customer_feedback, |
51 | 26 | manage_promotions, |
52 | | - set_reorder_level, |
53 | 27 | check_inventory, |
54 | 28 | update_product_price, |
55 | 29 | provide_product_recommendations, |
|
66 | 40 | evaluate_product_performance, |
67 | 41 | ) |
68 | 42 |
|
69 | | - |
70 | 43 | # Test cases for existing functions |
71 | 44 | @pytest.mark.asyncio |
72 | 45 | async def test_add_mobile_extras_pack(): |
@@ -159,7 +132,6 @@ async def test_provide_product_recommendations(): |
159 | 132 | assert "High Performance" in result |
160 | 133 |
|
161 | 134 |
|
162 | | -# Additional Test Cases |
163 | 135 | @pytest.mark.asyncio |
164 | 136 | async def test_forecast_product_demand(): |
165 | 137 | result = await forecast_product_demand("Product A", "Next Month") |
@@ -213,292 +185,3 @@ async def test_evaluate_product_performance(): |
213 | 185 | result = await evaluate_product_performance("Product A", "Customer reviews and sales data") |
214 | 186 | assert "Performance of" in result |
215 | 187 | assert "evaluated based on" in result |
216 | | - |
217 | | - |
218 | | -# Additional Coverage Test |
219 | | -@pytest.mark.asyncio |
220 | | -async def test_manage_supply_chain_edge_case(): |
221 | | - result = await manage_supply_chain("Product B", "New Supplier") |
222 | | - assert "Supply chain for" in result |
223 | | - assert "New Supplier" in result |
224 | | - |
225 | | - |
226 | | -@pytest.mark.asyncio |
227 | | -async def test_optimize_product_page_with_special_chars(): |
228 | | - result = await optimize_product_page("Product A", "Optimize SEO & Speed 🚀") |
229 | | - assert "Product page for" in result |
230 | | - assert "Optimize SEO & Speed 🚀" in result |
231 | | - |
232 | | - |
233 | | -# Tests with valid inputs for uncovered functions |
234 | | -@pytest.mark.asyncio |
235 | | -async def test_set_reorder_level_valid(): |
236 | | - result = await set_reorder_level("Product A", 10) |
237 | | - assert "Reorder level for" in result |
238 | | - assert "Product A" in result |
239 | | - assert "10" in result |
240 | | - |
241 | | - |
242 | | -@pytest.mark.asyncio |
243 | | -async def test_add_mobile_extras_pack_valid(): |
244 | | - result = await add_mobile_extras_pack("Unlimited Data Pack", "2025-05-01") |
245 | | - assert "Unlimited Data Pack" in result |
246 | | - assert "2025-05-01" in result |
247 | | - |
248 | | - |
249 | | -@pytest.mark.asyncio |
250 | | -async def test_handle_product_recall_valid(): |
251 | | - result = await handle_product_recall("Product B", "Safety concerns") |
252 | | - assert "Product recall for" in result |
253 | | - assert "Product B" in result |
254 | | - assert "Safety concerns" in result |
255 | | - |
256 | | - |
257 | | -@pytest.mark.asyncio |
258 | | -async def test_update_inventory_with_zero_quantity(): |
259 | | - result = await update_inventory("Product A", 0) |
260 | | - assert "Inventory for" in result |
261 | | - assert "Product A" in result |
262 | | - assert "0" in result |
263 | | - |
264 | | - |
265 | | -@pytest.mark.asyncio |
266 | | -async def test_set_reorder_level_with_large_value(): |
267 | | - result = await set_reorder_level("Product B", 100000) |
268 | | - assert "Reorder level for" in result |
269 | | - assert "Product B" in result |
270 | | - assert "100000" in result |
271 | | - |
272 | | - |
273 | | -@pytest.mark.asyncio |
274 | | -async def test_analyze_sales_data_with_long_period(): |
275 | | - result = await analyze_sales_data("Product C", "Last 5 Years") |
276 | | - assert "Sales data for" in result |
277 | | - assert "Last 5 Years" in result |
278 | | - |
279 | | - |
280 | | -# Test `update_inventory` with negative quantity (boundary case) |
281 | | -@pytest.mark.asyncio |
282 | | -async def test_update_inventory_with_negative_quantity(): |
283 | | - result = await update_inventory("Product D", -10) |
284 | | - assert "Inventory for" in result |
285 | | - assert "Product D" in result |
286 | | - assert "-10" in result |
287 | | - |
288 | | - |
289 | | -# Test `update_product_price` with maximum valid price |
290 | | -@pytest.mark.asyncio |
291 | | -async def test_update_product_price_maximum(): |
292 | | - result = await update_product_price("Product I", 999999.99) |
293 | | - assert "Price for" in result |
294 | | - assert "$999999.99" in result |
295 | | - |
296 | | - |
297 | | -# Test `add_mobile_extras_pack` with a very long pack name |
298 | | -@pytest.mark.asyncio |
299 | | -async def test_add_mobile_extras_pack_long_name(): |
300 | | - long_pack_name = "Extra Pack" + " with extended features " * 50 |
301 | | - result = await add_mobile_extras_pack(long_pack_name, "2025-12-31") |
302 | | - assert long_pack_name in result |
303 | | - assert "2025-12-31" in result |
304 | | - |
305 | | - |
306 | | -# Test `schedule_product_launch` with invalid date format |
307 | | -@pytest.mark.asyncio |
308 | | -async def test_schedule_product_launch_invalid_date(): |
309 | | - result = await schedule_product_launch("Product J", "31-12-2025") |
310 | | - assert "launch scheduled on **31-12-2025**" in result |
311 | | - |
312 | | - |
313 | | -# Test `generate_product_report` with no report type |
314 | | -@pytest.mark.asyncio |
315 | | -async def test_generate_product_report_no_type(): |
316 | | - result = await generate_product_report("Product K", "") |
317 | | - assert "report for **'Product K'** generated." in result |
318 | | - |
319 | | - |
320 | | -# Test `forecast_product_demand` with extremely large period |
321 | | -@pytest.mark.asyncio |
322 | | -async def test_forecast_product_demand_large_period(): |
323 | | - result = await forecast_product_demand("Product L", "Next 100 Years") |
324 | | - assert "Demand for **'Product L'** forecasted for **Next 100 Years**." in result |
325 | | - |
326 | | - |
327 | | -# Test `evaluate_product_performance` with missing performance metrics |
328 | | -@pytest.mark.asyncio |
329 | | -async def test_evaluate_product_performance_no_metrics(): |
330 | | - result = await evaluate_product_performance("Product M", "") |
331 | | - assert "Performance of **'Product M'** evaluated" in result |
332 | | - |
333 | | - |
334 | | -# Test `set_reorder_level` with zero value |
335 | | -@pytest.mark.asyncio |
336 | | -async def test_set_reorder_level_zero(): |
337 | | - result = await set_reorder_level("Product N", 0) |
338 | | - assert "Reorder level for **'Product N'** set to **0** units." in result |
339 | | - |
340 | | - |
341 | | -# Test `update_inventory` with very large quantity |
342 | | -@pytest.mark.asyncio |
343 | | -async def test_update_inventory_large_quantity(): |
344 | | - result = await update_inventory("Product O", 100000000) |
345 | | - assert "Inventory for **'Product O'** updated by **100000000** units." in result |
346 | | - |
347 | | - |
348 | | -# Test `check_inventory` with product name containing special characters |
349 | | -@pytest.mark.asyncio |
350 | | -async def test_check_inventory_special_name(): |
351 | | - result = await check_inventory("@Product#1!") |
352 | | - assert "Inventory status for **'@Product#1!'** checked." in result |
353 | | - |
354 | | - |
355 | | -# Test `handle_product_recall` with empty reason |
356 | | -@pytest.mark.asyncio |
357 | | -async def test_handle_product_recall_no_reason(): |
358 | | - result = await handle_product_recall("Product P", "") |
359 | | - assert "Product recall for **'Product P'** initiated due to:" in result |
360 | | - |
361 | | - |
362 | | -# Test `manage_supply_chain` with empty supplier name |
363 | | -@pytest.mark.asyncio |
364 | | -async def test_manage_supply_chain_empty_supplier(): |
365 | | - result = await manage_supply_chain("Product Q", "") |
366 | | - assert "Supply chain for **'Product Q'** managed with supplier" in result |
367 | | - |
368 | | - |
369 | | -# Test `analyze_sales_data` with an invalid time period |
370 | | -@pytest.mark.asyncio |
371 | | -async def test_analyze_sales_data_invalid_period(): |
372 | | - result = await analyze_sales_data("Product R", "InvalidPeriod") |
373 | | - assert "Sales data for **'Product R'** over **InvalidPeriod** analyzed." in result |
374 | | - |
375 | | - |
376 | | -# Test `update_product_price` with zero price |
377 | | -@pytest.mark.asyncio |
378 | | -async def test_update_product_price_zero(): |
379 | | - result = await update_product_price("Product S", 0.0) |
380 | | - assert "Price for **'Product S'** updated to **$0.00**." in result |
381 | | - |
382 | | - |
383 | | -# Test `monitor_market_trends` with no trends data available |
384 | | -@pytest.mark.asyncio |
385 | | -async def test_monitor_market_trends_no_data(): |
386 | | - result = await monitor_market_trends() |
387 | | - assert "Market trends monitored and data updated." in result |
388 | | - |
389 | | - |
390 | | -# Test `generate_product_report` with special characters in report type |
391 | | -@pytest.mark.asyncio |
392 | | -async def test_generate_product_report_special_type(): |
393 | | - result = await generate_product_report("Product U", "Sales/Performance") |
394 | | - assert "report for **'Product U'** generated." in result |
395 | | - assert "Sales/Performance" in result |
396 | | - |
397 | | - |
398 | | -# Test `evaluate_product_performance` with multiple metrics |
399 | | -@pytest.mark.asyncio |
400 | | -async def test_evaluate_product_performance_multiple_metrics(): |
401 | | - result = await evaluate_product_performance("Product V", "Customer reviews, sales, and returns") |
402 | | - assert "Performance of **'Product V'** evaluated" in result |
403 | | - assert "Customer reviews, sales, and returns" in result |
404 | | - |
405 | | - |
406 | | -# Test `schedule_product_launch` with no product name |
407 | | -@pytest.mark.asyncio |
408 | | -async def test_schedule_product_launch_no_name(): |
409 | | - result = await schedule_product_launch("", "2025-12-01") |
410 | | - assert "launch scheduled on **2025-12-01**" in result |
411 | | - |
412 | | - |
413 | | -# Test `set_product_discount` with an unusually high discount |
414 | | -@pytest.mark.asyncio |
415 | | -async def test_set_product_discount_high_value(): |
416 | | - result = await set_product_discount("Product X", 95.0) |
417 | | - assert "Discount for **'Product X'**" in result |
418 | | - assert "95.0%" in result |
419 | | - |
420 | | - |
421 | | -# Test `monitor_market_trends` for a specific market |
422 | | -@pytest.mark.asyncio |
423 | | -async def test_monitor_market_trends_specific_market(): |
424 | | - result = await monitor_market_trends() |
425 | | - assert "Market trends monitored and data updated." in result |
426 | | - |
427 | | - |
428 | | -# Test `provide_product_recommendations` with multiple preferences |
429 | | -@pytest.mark.asyncio |
430 | | -async def test_provide_product_recommendations_multiple_preferences(): |
431 | | - result = await provide_product_recommendations("High Performance, Affordability, Durability") |
432 | | - assert "Product recommendations based on preferences" in result |
433 | | - assert "High Performance, Affordability, Durability" in result |
434 | | - |
435 | | - |
436 | | -# Test `handle_product_complaints` with extensive complaint details |
437 | | -@pytest.mark.asyncio |
438 | | -async def test_handle_product_complaints_detailed(): |
439 | | - detailed_complaint = ( |
440 | | - "The product arrived damaged, the packaging was insufficient, and the user manual was missing." |
441 | | - ) |
442 | | - result = await handle_product_complaints("Product Y", detailed_complaint) |
443 | | - assert "Complaint for **'Product Y'**" in result |
444 | | - assert detailed_complaint in result |
445 | | - |
446 | | - |
447 | | -# Test `update_product_price` with a very low price |
448 | | -@pytest.mark.asyncio |
449 | | -async def test_update_product_price_low_value(): |
450 | | - result = await update_product_price("Product Z", 0.01) |
451 | | - assert "Price for **'Product Z'** updated to **$0.01**." in result |
452 | | - |
453 | | - |
454 | | -# Test `develop_new_product_ideas` with highly detailed input |
455 | | -@pytest.mark.asyncio |
456 | | -async def test_develop_new_product_ideas_detailed(): |
457 | | - detailed_idea = "Smartphone Z with a foldable screen, AI camera, and integrated AR capabilities." |
458 | | - result = await develop_new_product_ideas(detailed_idea) |
459 | | - assert "New product idea developed" in result |
460 | | - assert detailed_idea in result |
461 | | - |
462 | | - |
463 | | -# Test `forecast_product_demand` with unusual input |
464 | | -@pytest.mark.asyncio |
465 | | -async def test_forecast_product_demand_unusual(): |
466 | | - result = await forecast_product_demand("Product AA", "Next 1000 Days") |
467 | | - assert "Demand for **'Product AA'** forecasted for **Next 1000 Days**." in result |
468 | | - |
469 | | - |
470 | | -# Test `set_reorder_level` with extremely high value |
471 | | -@pytest.mark.asyncio |
472 | | -async def test_set_reorder_level_high(): |
473 | | - result = await set_reorder_level("Product AB", 10000000) |
474 | | - assert "Reorder level for **'Product AB'** set to **10000000** units." in result |
475 | | - |
476 | | - |
477 | | -# Test `update_inventory` with fractional quantity |
478 | | -@pytest.mark.asyncio |
479 | | -async def test_update_inventory_fractional_quantity(): |
480 | | - result = await update_inventory("Product AD", 5.5) |
481 | | - assert "Inventory for **'Product AD'** updated by **5.5** units." in result |
482 | | - |
483 | | - |
484 | | -# Test `analyze_sales_data` with unusual product name |
485 | | -@pytest.mark.asyncio |
486 | | -async def test_analyze_sales_data_unusual_name(): |
487 | | - result = await analyze_sales_data("💡UniqueProduct✨", "Last Month") |
488 | | - assert "Sales data for **'💡UniqueProduct✨'**" in result |
489 | | - |
490 | | - |
491 | | -# Test `generate_product_report` with detailed report type |
492 | | -@pytest.mark.asyncio |
493 | | -async def test_generate_product_report_detailed_type(): |
494 | | - detailed_type = "Annual Sales Report with Profit Margin Analysis" |
495 | | - result = await generate_product_report("Product AE", detailed_type) |
496 | | - assert "report for **'Product AE'** generated" in result |
497 | | - assert detailed_type in result |
498 | | - |
499 | | - |
500 | | -# Test `update_product_price` with a very high precision value |
501 | | -@pytest.mark.asyncio |
502 | | -async def test_update_product_price_high_precision(): |
503 | | - result = await update_product_price("Product AG", 123.456789) |
504 | | - assert "Price for **'Product AG'** updated to **$123.46**." in result |
0 commit comments