|
| 1 | +"""Test cases for ProcurementTools class.""" |
| 2 | +import pytest |
| 3 | +from src.backend.kernel_tools.procurement_tools import ProcurementTools |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.asyncio |
| 7 | +async def test_order_hardware(): |
| 8 | + """Test order_hardware method.""" |
| 9 | + result = await ProcurementTools.order_hardware("Laptop", 5) |
| 10 | + assert "Hardware Order Placed" in result |
| 11 | + assert "**Item:** Laptop" in result |
| 12 | + assert "**Quantity:** 5" in result |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.asyncio |
| 16 | +async def test_order_software_license(): |
| 17 | + """Test order_software_license method.""" |
| 18 | + result = await ProcurementTools.order_software_license("Microsoft Office", "Enterprise", 10) |
| 19 | + assert "Software License Ordered" in result |
| 20 | + assert "**Software:** Microsoft Office" in result |
| 21 | + assert "**License Type:** Enterprise" in result |
| 22 | + assert "**Quantity:** 10" in result |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.asyncio |
| 26 | +async def test_check_inventory(): |
| 27 | + """Test check_inventory method.""" |
| 28 | + result = await ProcurementTools.check_inventory("Laptop") |
| 29 | + assert "Inventory Status" in result |
| 30 | + assert "**Item:** Laptop" in result |
| 31 | + assert "**Status:** In Stock" in result |
| 32 | + |
| 33 | + |
| 34 | +@pytest.mark.asyncio |
| 35 | +async def test_process_purchase_order(): |
| 36 | + """Test process_purchase_order method.""" |
| 37 | + result = await ProcurementTools.process_purchase_order("PO12345") |
| 38 | + assert "Purchase Order Processed" in result |
| 39 | + assert "**PO Number:** PO12345" in result |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.asyncio |
| 43 | +async def test_initiate_contract_negotiation(): |
| 44 | + """Test initiate_contract_negotiation method.""" |
| 45 | + result = await ProcurementTools.initiate_contract_negotiation("Vendor A", "Contract Details") |
| 46 | + assert "Contract Negotiation Initiated" in result |
| 47 | + assert "**Vendor:** Vendor A" in result |
| 48 | + assert "**Contract Details:** Contract Details" in result |
| 49 | + |
| 50 | + |
| 51 | +@pytest.mark.asyncio |
| 52 | +async def test_approve_invoice(): |
| 53 | + """Test approve_invoice method.""" |
| 54 | + result = await ProcurementTools.approve_invoice("INV12345") |
| 55 | + assert "Invoice Approved" in result |
| 56 | + assert "**Invoice Number:** INV12345" in result |
| 57 | + |
| 58 | + |
| 59 | +@pytest.mark.asyncio |
| 60 | +async def test_track_order(): |
| 61 | + """Test track_order method.""" |
| 62 | + result = await ProcurementTools.track_order("ORD12345") |
| 63 | + assert "Order Tracking" in result |
| 64 | + assert "**Order Number:** ORD12345" in result |
| 65 | + assert "**Status:** In Transit" in result |
| 66 | + |
| 67 | + |
| 68 | +@pytest.mark.asyncio |
| 69 | +async def test_manage_vendor_relationship(): |
| 70 | + """Test manage_vendor_relationship method.""" |
| 71 | + result = await ProcurementTools.manage_vendor_relationship("Vendor A", "updated") |
| 72 | + assert "Vendor Relationship Update" in result |
| 73 | + assert "**Vendor:** Vendor A" in result |
| 74 | + assert "**Action:** updated" in result |
| 75 | + |
| 76 | + |
| 77 | +@pytest.mark.asyncio |
| 78 | +async def test_update_procurement_policy(): |
| 79 | + """Test update_procurement_policy method.""" |
| 80 | + result = await ProcurementTools.update_procurement_policy("Policy A", "New Policy Content") |
| 81 | + assert "Procurement Policy Updated" in result |
| 82 | + assert "**Policy:** Policy A" in result |
| 83 | + |
| 84 | + |
| 85 | +def test_get_all_kernel_functions(): |
| 86 | + """Test get_all_kernel_functions method.""" |
| 87 | + kernel_functions = ProcurementTools.get_all_kernel_functions() |
| 88 | + assert "order_hardware" in kernel_functions |
| 89 | + assert "order_software_license" in kernel_functions |
| 90 | + assert callable(kernel_functions["order_hardware"]) |
| 91 | + |
| 92 | + |
| 93 | +def test_generate_tools_json_doc(): |
| 94 | + """Test generate_tools_json_doc method.""" |
| 95 | + tools_json = ProcurementTools.generate_tools_json_doc() |
| 96 | + assert "order_hardware" in tools_json |
| 97 | + assert "order_software_license" in tools_json |
| 98 | + assert "arguments" in tools_json |
| 99 | + |
| 100 | + |
| 101 | +@pytest.mark.asyncio |
| 102 | +async def test_order_hardware_invalid_quantity(): |
| 103 | + """Test order_hardware with invalid quantity.""" |
| 104 | + result = await ProcurementTools.order_hardware("Laptop", 0) |
| 105 | + assert "Hardware Order Placed" in result |
| 106 | + assert "**Quantity:** 0" in result |
| 107 | + |
| 108 | + |
| 109 | +@pytest.mark.asyncio |
| 110 | +async def test_order_software_license_invalid_quantity(): |
| 111 | + """Test order_software_license with invalid quantity.""" |
| 112 | + result = await ProcurementTools.order_software_license("Microsoft Office", "Enterprise", -1) |
| 113 | + assert "Software License Ordered" in result |
| 114 | + assert "**Quantity:** -1" in result |
| 115 | + |
| 116 | + |
| 117 | +# @pytest.mark.asyncio |
| 118 | +# async def test_check_inventory_item_not_found(): |
| 119 | +# """Test check_inventory with an item not found.""" |
| 120 | +# result = await ProcurementTools.check_inventory("NonExistentItem") |
| 121 | +# assert "Inventory Status" in result |
| 122 | +# assert "**Item:** NonExistentItem" in result |
| 123 | +# assert "**Status:** Not Found" in result |
| 124 | + |
| 125 | + |
| 126 | +@pytest.mark.asyncio |
| 127 | +async def test_process_purchase_order_invalid_po(): |
| 128 | + """Test process_purchase_order with an invalid PO number.""" |
| 129 | + result = await ProcurementTools.process_purchase_order("") |
| 130 | + assert "Purchase Order Processed" in result |
| 131 | + assert "**PO Number:** " in result |
| 132 | + |
| 133 | + |
| 134 | +@pytest.mark.asyncio |
| 135 | +async def test_initiate_contract_negotiation_empty_details(): |
| 136 | + """Test initiate_contract_negotiation with empty contract details.""" |
| 137 | + result = await ProcurementTools.initiate_contract_negotiation("Vendor A", "") |
| 138 | + assert "Contract Negotiation Initiated" in result |
| 139 | + assert "**Vendor:** Vendor A" in result |
| 140 | + assert "**Contract Details:** " in result |
0 commit comments