|
| 1 | +import pytest |
| 2 | +from permit_fastmcp.middleware.utils import generate_action_from_tool_name |
| 3 | + |
| 4 | + |
| 5 | +def test_generate_action_from_tool_name_basic(): |
| 6 | + """Test basic tool name conversion.""" |
| 7 | + assert generate_action_from_tool_name("test_tool") == "test-tool" |
| 8 | + assert generate_action_from_tool_name("my.tool") == "my-tool" |
| 9 | + assert generate_action_from_tool_name("path/to/tool") == "path-to-tool" |
| 10 | + |
| 11 | + |
| 12 | +def test_generate_action_from_tool_name_multiple_replacements(): |
| 13 | + """Test tool names with multiple special characters.""" |
| 14 | + assert generate_action_from_tool_name("test.tool_name") == "test-tool-name" |
| 15 | + assert generate_action_from_tool_name("path/to/my_tool") == "path-to-my-tool" |
| 16 | + assert ( |
| 17 | + generate_action_from_tool_name("com.example.tool_name") |
| 18 | + == "com-example-tool-name" |
| 19 | + ) |
| 20 | + |
| 21 | + |
| 22 | +def test_generate_action_from_tool_name_edge_cases(): |
| 23 | + """Test edge cases for tool name conversion.""" |
| 24 | + # Empty string |
| 25 | + assert generate_action_from_tool_name("") == "unknown-tool" |
| 26 | + |
| 27 | + # None value |
| 28 | + assert generate_action_from_tool_name(None) == "unknown-tool" |
| 29 | + |
| 30 | + # Only special characters |
| 31 | + assert generate_action_from_tool_name("...") == "---" |
| 32 | + assert generate_action_from_tool_name("///") == "---" |
| 33 | + assert generate_action_from_tool_name("___") == "---" |
| 34 | + |
| 35 | + # Mixed special characters |
| 36 | + assert ( |
| 37 | + generate_action_from_tool_name("test.tool_name/path") == "test-tool-name-path" |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +def test_generate_action_from_tool_name_no_changes(): |
| 42 | + """Test tool names that don't need any replacements.""" |
| 43 | + assert generate_action_from_tool_name("simpletool") == "simpletool" |
| 44 | + assert generate_action_from_tool_name("tool-name") == "tool-name" |
| 45 | + assert generate_action_from_tool_name("toolname") == "toolname" |
0 commit comments