|
1 | | -"""Test cases for ProcurementTools class.""" |
| 1 | +import os |
2 | 2 | import sys |
3 | 3 | import types |
4 | 4 | import pytest |
5 | | -from src.backend.kernel_tools.hr_tools import HrTools |
6 | 5 |
|
7 | | -sk = types.ModuleType("semantic_kernel") |
8 | | -ka = types.ModuleType("semantic_kernel.functions") |
9 | | - |
10 | | -sys.modules["semantic_kernel"] = sk |
11 | | -sys.modules["semantic_kernel.functions"] = ka |
| 6 | +# --- Stub out semantic_kernel.functions --- |
| 7 | +sk_pkg = types.ModuleType("semantic_kernel") |
| 8 | +sk_pkg.__path__ = [] |
| 9 | +sk_funcs = types.ModuleType("semantic_kernel.functions") |
| 10 | + |
| 11 | +def kernel_function(name=None, description=None): |
| 12 | + class DummyKernelFunction: |
| 13 | + def __init__(self, description): |
| 14 | + self.description = description |
| 15 | + |
| 16 | + def decorator(func): |
| 17 | + setattr(func, "__kernel_name__", name or func.__name__) |
| 18 | + setattr(func, "__kernel_function__", DummyKernelFunction(description)) |
| 19 | + return func |
| 20 | + return decorator |
| 21 | + |
| 22 | +sk_funcs.kernel_function = kernel_function |
| 23 | +sys.modules["semantic_kernel"] = sk_pkg |
| 24 | +sys.modules["semantic_kernel.functions"] = sk_funcs |
| 25 | + |
| 26 | +# --- Stub out models.messages_kernel.AgentType --- |
| 27 | +models_pkg = types.ModuleType("models") |
| 28 | +msgs_mod = types.ModuleType("models.messages_kernel") |
| 29 | +from enum import Enum |
| 30 | +class AgentType(Enum): |
| 31 | + HR = 'hr_agent' |
| 32 | + PROCUREMENT = 'procurement_agent' |
| 33 | + MARKETING = 'marketing_agent' |
| 34 | + PRODUCT = 'product_agent' |
| 35 | + TECH_SUPPORT = 'tech_support_agent' |
| 36 | +msgs_mod.AgentType = AgentType |
| 37 | +models_pkg.messages_kernel = msgs_mod |
| 38 | +sys.modules['models'] = models_pkg |
| 39 | +sys.modules['models.messages_kernel'] = msgs_mod |
| 40 | + |
| 41 | +# Ensure 'src' is on sys.path |
| 42 | +PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')) |
| 43 | +SRC_PATH = os.path.join(PROJECT_ROOT, 'src') |
| 44 | +if SRC_PATH not in sys.path: |
| 45 | + sys.path.insert(0, SRC_PATH) |
| 46 | + |
| 47 | +from backend.kernel_tools.hr_tools import HrTools |
12 | 48 |
|
13 | 49 | @pytest.mark.asyncio |
14 | 50 | async def test_schedule_orientation_session(): |
15 | | - """Test schedule_orientation_session method.""" |
16 | 51 | result = await HrTools.schedule_orientation_session("John Doe", "2025-05-20") |
17 | 52 | assert "Orientation Session Scheduled" in result |
18 | 53 | assert "**Employee Name:** John Doe" in result |
19 | 54 | assert "**Date:** 2025-05-20" in result |
20 | 55 |
|
21 | | - |
22 | 56 | @pytest.mark.asyncio |
23 | 57 | async def test_assign_mentor(): |
24 | | - """Test assign_mentor method.""" |
25 | 58 | result = await HrTools.assign_mentor("Jane Doe") |
26 | 59 | assert "Mentor Assigned" in result |
27 | 60 | assert "**Employee Name:** Jane Doe" in result |
28 | 61 |
|
29 | | - |
30 | 62 | @pytest.mark.asyncio |
31 | 63 | async def test_register_for_benefits(): |
32 | | - """Test register_for_benefits method.""" |
33 | 64 | result = await HrTools.register_for_benefits("John Doe") |
34 | 65 | assert "Benefits Registration" in result |
35 | 66 | assert "**Employee Name:** John Doe" in result |
36 | 67 |
|
37 | | - |
38 | 68 | @pytest.mark.asyncio |
39 | 69 | async def test_enroll_in_training_program(): |
40 | | - """Test enroll_in_training_program method.""" |
41 | 70 | result = await HrTools.enroll_in_training_program("John Doe", "Leadership Training") |
42 | 71 | assert "Training Program Enrollment" in result |
43 | 72 | assert "**Employee Name:** John Doe" in result |
44 | 73 | assert "**Program Name:** Leadership Training" in result |
45 | 74 |
|
| 75 | +@pytest.mark.asyncio |
| 76 | +async def test_process_leave_request(): |
| 77 | + result = await HrTools.process_leave_request("John Doe", "Vacation", "2025-06-01", "2025-06-10") |
| 78 | + assert "Leave Request Processed" in result |
| 79 | + assert "**Leave Type:** Vacation" in result |
| 80 | + assert "**Start Date:** 2025-06-01" in result |
| 81 | + assert "**End Date:** 2025-06-10" in result |
| 82 | + |
| 83 | +# Additional positive and negative test cases for 100% coverage |
46 | 84 |
|
47 | 85 | @pytest.mark.asyncio |
48 | | -async def test_provide_employee_handbook(): |
49 | | - """Test provide_employee_handbook method.""" |
50 | | - result = await HrTools.provide_employee_handbook("Jane Doe") |
51 | | - assert "Employee Handbook Provided" in result |
52 | | - assert "**Employee Name:** Jane Doe" in result |
| 86 | +async def test_schedule_orientation_session_empty_name(): |
| 87 | + result = await HrTools.schedule_orientation_session("", "2025-05-20") |
| 88 | + assert "Orientation Session Scheduled" in result |
| 89 | + assert "**Employee Name:** " in result |
53 | 90 |
|
| 91 | +@pytest.mark.asyncio |
| 92 | +async def test_assign_mentor_empty_name(): |
| 93 | + result = await HrTools.assign_mentor("") |
| 94 | + assert "Mentor Assigned" in result |
| 95 | + assert "**Employee Name:** " in result |
54 | 96 |
|
55 | 97 | @pytest.mark.asyncio |
56 | | -async def test_update_employee_record(): |
57 | | - """Test update_employee_record method.""" |
58 | | - result = await HrTools.update_employee_record("John Doe", "Address", "123 Main St") |
59 | | - assert "Employee Record Updated" in result |
60 | | - assert "**Field Updated:** Address" in result |
61 | | - assert "**New Value:** 123 Main St" in result |
| 98 | +async def test_register_for_benefits_empty_name(): |
| 99 | + result = await HrTools.register_for_benefits("") |
| 100 | + assert "Benefits Registration" in result |
| 101 | + assert "**Employee Name:** " in result |
62 | 102 |
|
| 103 | +@pytest.mark.asyncio |
| 104 | +async def test_enroll_in_training_program_empty_program(): |
| 105 | + result = await HrTools.enroll_in_training_program("John Doe", "") |
| 106 | + assert "Training Program Enrollment" in result |
| 107 | + assert "**Program Name:** " in result |
63 | 108 |
|
64 | 109 | @pytest.mark.asyncio |
65 | | -async def test_request_id_card(): |
66 | | - """Test request_id_card method.""" |
67 | | - result = await HrTools.request_id_card("John Doe") |
68 | | - assert "ID Card Request" in result |
69 | | - assert "**Employee Name:** John Doe" in result |
| 110 | +async def test_process_leave_request_invalid_dates(): |
| 111 | + # End date before start date (negative scenario) |
| 112 | + result = await HrTools.process_leave_request("John Doe", "Sick", "2025-06-10", "2025-06-01") |
| 113 | + assert "Leave Request Processed" in result |
| 114 | + assert "**Start Date:** 2025-06-10" in result |
| 115 | + assert "**End Date:** 2025-06-01" in result |
| 116 | + |
| 117 | +@pytest.mark.asyncio |
| 118 | +async def test_process_leave_request_empty_fields(): |
| 119 | + result = await HrTools.process_leave_request("", "", "", "") |
| 120 | + assert "Leave Request Processed" in result |
| 121 | + assert "**Employee Name:** " in result |
| 122 | + assert "**Leave Type:** " in result |
| 123 | + assert "**Start Date:** " in result |
| 124 | + assert "**End Date:** " in result |
70 | 125 |
|
71 | 126 |
|
72 | 127 | @pytest.mark.asyncio |
73 | | -async def test_set_up_payroll(): |
74 | | - """Test set_up_payroll method.""" |
75 | | - result = await HrTools.set_up_payroll("Jane Doe") |
76 | | - assert "Payroll Setup" in result |
77 | | - assert "**Employee Name:** Jane Doe" in result |
| 128 | +async def test_send_company_announcement(): |
| 129 | + result = await HrTools.send_company_announcement("New Policy", "Please read the updated policy.") |
| 130 | + assert "Company Announcement" in result |
| 131 | + assert "**Subject:** New Policy" in result |
| 132 | + assert "Please read the updated policy." in result |
78 | 133 |
|
| 134 | +@pytest.mark.asyncio |
| 135 | +async def test_issue_bonus_valid_amount(): |
| 136 | + result = await HrTools.issue_bonus("John Doe", 1500.75) |
| 137 | + assert "Bonus Issued" in result |
| 138 | + assert "**Amount:** $1500.75" in result |
| 139 | + |
| 140 | +@pytest.mark.asyncio |
| 141 | +async def test_issue_bonus_zero_amount(): |
| 142 | + result = await HrTools.issue_bonus("John Doe", 0.0) |
| 143 | + assert "**Amount:** $0.00" in result |
79 | 144 |
|
80 | 145 | @pytest.mark.asyncio |
81 | 146 | async def test_add_emergency_contact(): |
82 | | - """Test add_emergency_contact method.""" |
83 | | - result = await HrTools.add_emergency_contact("John Doe", "Jane Smith", "555-1234") |
| 147 | + result = await HrTools.add_emergency_contact("John Doe", "Jane Doe", "123-456-7890") |
84 | 148 | assert "Emergency Contact Added" in result |
85 | | - assert "**Contact Name:** Jane Smith" in result |
86 | | - assert "**Contact Phone:** 555-1234" in result |
| 149 | + assert "**Contact Name:** Jane Doe" in result |
| 150 | + assert "**Contact Phone:** 123-456-7890" in result |
87 | 151 |
|
| 152 | +@pytest.mark.asyncio |
| 153 | +async def test_verify_employment(): |
| 154 | + result = await HrTools.verify_employment("Jane Doe") |
| 155 | + assert "Employment Verification" in result |
| 156 | + assert "**Employee Name:** Jane Doe" in result |
88 | 157 |
|
89 | 158 | @pytest.mark.asyncio |
90 | | -async def test_process_leave_request(): |
91 | | - """Test process_leave_request method.""" |
92 | | - result = await HrTools.process_leave_request("John Doe", "Vacation", "2025-06-01", "2025-06-10") |
93 | | - assert "Leave Request Processed" in result |
94 | | - assert "**Leave Type:** Vacation" in result |
95 | | - assert "**Start Date:** 2025-06-01" in result |
96 | | - assert "**End Date:** 2025-06-10" in result |
| 159 | +async def test_send_email_valid(): |
| 160 | + result = await HrTools. send_email( "[email protected]") |
| 161 | + assert "Welcome Email Sent" in result |
| 162 | + assert "**Email Address:** [email protected]" in result |
| 163 | + |
| 164 | +@pytest.mark.asyncio |
| 165 | +async def test_send_email_empty(): |
| 166 | + result = await HrTools.send_email("") |
| 167 | + assert "Welcome Email Sent" in result |
| 168 | + assert "**Email Address:** " in result |
| 169 | + |
97 | 170 |
|
98 | 171 |
|
99 | | -def test_get_all_kernel_functions(): |
100 | | - """Test get_all_kernel_functions method.""" |
101 | | - kernel_functions = HrTools.get_all_kernel_functions() |
102 | | - assert "schedule_orientation_session" in kernel_functions |
103 | | - assert "assign_mentor" in kernel_functions |
104 | | - assert callable(kernel_functions["schedule_orientation_session"]) |
| 172 | +def test_get_all_kernel_functions_includes_sample(): |
| 173 | + funcs = HrTools.get_all_kernel_functions() |
| 174 | + assert isinstance(funcs, dict) |
| 175 | + assert "schedule_orientation_session" in funcs |
105 | 176 |
|
| 177 | +def test_generate_tools_json_doc_returns_json(): |
| 178 | + json_doc = HrTools.generate_tools_json_doc() |
| 179 | + assert json_doc.startswith("[") |
| 180 | + assert '"function": "schedule_orientation_session"' in json_doc |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | +@pytest.mark.asyncio |
| 185 | +@pytest.mark.parametrize("name", ["", "Alice", "A" * 1000]) |
| 186 | +async def test_schedule_orientation_session_edge_cases(name): |
| 187 | + result = await HrTools.schedule_orientation_session(name, "2025-01-01") |
| 188 | + assert "Orientation Session Scheduled" in result |
| 189 | + assert f"**Employee Name:** {name}" in result |
106 | 190 |
|
107 | | -def test_generate_tools_json_doc(): |
108 | | - """Test generate_tools_json_doc method.""" |
109 | | - tools_json = HrTools.generate_tools_json_doc() |
110 | | - assert "schedule_orientation_session" in tools_json |
111 | | - assert "assign_mentor" in tools_json |
112 | | - assert "arguments" in tools_json |
|
0 commit comments