|
9 | 9 |
|
10 | 10 | logger = logging.getLogger(__name__) |
11 | 11 |
|
12 | | - |
13 | | -@pytest.mark.asyncio(loop_scope="module") |
14 | | -async def test_nonexistent_tool(aws_mcp_client: fastmcp.Client): |
15 | | - """Test that calling a nonexistent tool raises an exception. |
16 | | -
|
17 | | - This test will: |
18 | | - - PASS when calling a nonexistent tool raises an exception |
19 | | - - FAIL if the nonexistent tool somehow succeeds |
20 | | - """ |
21 | | - exception_raised = False |
22 | | - exception_message = None |
23 | | - |
24 | | - try: |
25 | | - response = await aws_mcp_client.call_tool("aws___nonexistent_tool_12345", {}) |
26 | | - logger.info(f"Unexpected success, response: {response}") |
27 | | - except Exception as e: |
28 | | - exception_raised = True |
29 | | - exception_message = str(e) |
30 | | - logger.info(f"Exception raised as expected: {type(e).__name__}: {exception_message}") |
31 | | - |
32 | | - # Assert that an exception was raised |
33 | | - assert exception_raised, ( |
34 | | - f"Expected exception when calling nonexistent tool 'aws___nonexistent_tool_12345', " |
35 | | - f"but call succeeded unexpectedly." |
36 | | - ) |
37 | | - |
38 | | - # Verify the exception mentions the tool not being found |
39 | | - error_message_lower = exception_message.lower() |
40 | | - tool_error_patterns = [ |
41 | | - "not found", |
42 | | - "unknown", |
43 | | - "does not exist", |
44 | | - "invalid tool", |
45 | | - "tool", |
46 | | - "unknown tool", |
47 | | - ] |
48 | | - |
49 | | - assert any(pattern in error_message_lower for pattern in tool_error_patterns), ( |
50 | | - f"Exception was raised but doesn't appear to be about a missing tool. " |
51 | | - f"Expected one of {tool_error_patterns}, but got: {exception_message[:200]}" |
52 | | - ) |
53 | | - |
54 | | - logger.info(f"Test passed: Nonexistent tool correctly raised exception") |
55 | | - |
56 | | - |
57 | 12 | @pytest.mark.asyncio(loop_scope="module") |
58 | 13 | async def test_expired_credentials(): |
59 | 14 | """Test that expired credentials are properly rejected. |
|
0 commit comments