11import os
2+ import sys
23import pytest
34from 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
197from src .backend .agents .procurement import (
208 order_hardware ,
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
7169async 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
9595async 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
337339async 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-
0 commit comments