Skip to content

Commit 5d686cc

Browse files
committed
style: fix AWS MCP integration tests formatting
1 parent ae9ca47 commit 5d686cc

File tree

3 files changed

+80
-78
lines changed

3 files changed

+80
-78
lines changed

tests/integ/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ def _build_endpoint_environment_remote_configuration():
9292
)
9393

9494

95-
@pytest_asyncio.fixture(loop_scope="module", scope="module")
95+
@pytest_asyncio.fixture(loop_scope='module', scope='module')
9696
async def aws_mcp_client():
9797
"""Create MCP Client for AWS MCP Server."""
9898
client = build_mcp_client(
99-
endpoint="https://aws-mcp.us-east-1.api.aws/mcp",
100-
region_name="us-east-1",
99+
endpoint='https://aws-mcp.us-east-1.api.aws/mcp',
100+
region_name='us-east-1',
101101
)
102102

103103
async with client:
104-
yield client
104+
yield client
Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
"""Happy path integration tests for AWS MCP Server at https://aws-mcp.us-east-1.api.aws/mcp."""
22

33
import fastmcp
4+
import json
45
import logging
56
import pytest
67
from fastmcp.client.client import CallToolResult
7-
88
from tests.integ.test_proxy_simple_mcp_server import get_text_content
9-
import json
109

1110

1211
logger = logging.getLogger(__name__)
1312

1413

15-
@pytest.mark.asyncio(loop_scope="module")
14+
@pytest.mark.asyncio(loop_scope='module')
1615
async def test_aws_mcp_ping(aws_mcp_client: fastmcp.Client):
1716
"""Test ping to AWS MCP Server."""
1817
await aws_mcp_client.ping()
1918

20-
@pytest.mark.asyncio(loop_scope="module")
19+
20+
@pytest.mark.asyncio(loop_scope='module')
2121
async def test_aws_mcp_list_tools(aws_mcp_client: fastmcp.Client):
2222
"""Test list tools from AWS MCP Server."""
2323
tools = await aws_mcp_client.list_tools()
2424

25-
assert len(tools) > 0, f"AWS MCP Server should have tools (got {len(tools)})"
25+
assert len(tools) > 0, f'AWS MCP Server should have tools (got {len(tools)})'
2626

2727

2828
def verify_response_content(response: CallToolResult):
@@ -37,16 +37,17 @@ def verify_response_content(response: CallToolResult):
3737
Raises:
3838
AssertionError: If response indicates an error or has empty content
3939
"""
40-
assert (
41-
response.is_error is False
42-
), f"is_error returned true. Returned response body: {response}."
43-
assert len(response.content) > 0, f"Empty result list in response. Response: {response}"
40+
assert response.is_error is False, (
41+
f'is_error returned true. Returned response body: {response}.'
42+
)
43+
assert len(response.content) > 0, f'Empty result list in response. Response: {response}'
4444

4545
response_text = get_text_content(response)
46-
assert len(response_text) > 0, f"Empty response text. Response: {response}"
46+
assert len(response_text) > 0, f'Empty response text. Response: {response}'
4747

4848
return response_text
4949

50+
5051
def verify_json_response(response: CallToolResult):
5152
"""Verify that a tool call response is successful and contains valid JSON data.
5253
@@ -63,76 +64,77 @@ def verify_json_response(response: CallToolResult):
6364
try:
6465
response_data = json.loads(response_text)
6566
except json.JSONDecodeError:
66-
raise AssertionError(f"Response text is not valid JSON. Response text: {response_text}")
67+
raise AssertionError(f'Response text is not valid JSON. Response text: {response_text}')
6768

68-
assert len(response_data) > 0, f"Empty JSON content in response. Response: {response}"
69+
assert len(response_data) > 0, f'Empty JSON content in response. Response: {response}'
6970

7071

7172
@pytest.mark.parametrize(
72-
"tool_name,params",
73+
'tool_name,params',
7374
[
74-
("aws___list_regions", {}),
75-
("aws___suggest_aws_commands", {"query": "how to list my lambda functions"}),
76-
("aws___search_documentation", {"search_phrase": "S3 bucket versioning"}),
75+
('aws___list_regions', {}),
76+
('aws___suggest_aws_commands', {'query': 'how to list my lambda functions'}),
77+
('aws___search_documentation', {'search_phrase': 'S3 bucket versioning'}),
7778
(
78-
"aws___recommend",
79-
{"url": "https://docs.aws.amazon.com/lambda/latest/dg/lambda-invocation.html"},
79+
'aws___recommend',
80+
{'url': 'https://docs.aws.amazon.com/lambda/latest/dg/lambda-invocation.html'},
8081
),
8182
(
82-
"aws___read_documentation",
83-
{"url": "https://docs.aws.amazon.com/lambda/latest/dg/lambda-invocation.html"},
83+
'aws___read_documentation',
84+
{'url': 'https://docs.aws.amazon.com/lambda/latest/dg/lambda-invocation.html'},
8485
),
8586
(
86-
"aws___get_regional_availability",
87-
{"resource_type": "cfn", "region": "us-east-1"},
87+
'aws___get_regional_availability',
88+
{'resource_type': 'cfn', 'region': 'us-east-1'},
8889
),
89-
("aws___call_aws", {"cli_command": "aws s3 ls", "max_results": 10}),
90+
('aws___call_aws', {'cli_command': 'aws s3 ls', 'max_results': 10}),
9091
],
9192
ids=[
92-
"list_regions",
93-
"suggest_aws_commands",
94-
"search_documentation",
95-
"recommend",
96-
"read_documentation",
97-
"get_regional_availability",
98-
"call_aws",
93+
'list_regions',
94+
'suggest_aws_commands',
95+
'search_documentation',
96+
'recommend',
97+
'read_documentation',
98+
'get_regional_availability',
99+
'call_aws',
99100
],
100101
)
101-
@pytest.mark.asyncio(loop_scope="module")
102+
@pytest.mark.asyncio(loop_scope='module')
102103
async def test_aws_mcp_tools(aws_mcp_client: fastmcp.Client, tool_name: str, params: dict):
103104
"""Test AWS MCP tools with minimal valid params."""
104105
response = await aws_mcp_client.call_tool(tool_name, params)
105106
verify_json_response(response)
106107

107108

108-
@pytest.mark.asyncio(loop_scope="module")
109+
@pytest.mark.asyncio(loop_scope='module')
109110
async def test_aws_mcp_tools_retrieve_agent_sop(aws_mcp_client: fastmcp.Client):
110111
"""Test aws___retrieve_agent_sop by retrieving the list of available SOPs."""
111-
112112
# Step 1: Call retrieve_agent_sop with empty params to get list of available SOPs
113-
list_sops_response = await aws_mcp_client.call_tool("aws___retrieve_agent_sop")
113+
list_sops_response = await aws_mcp_client.call_tool('aws___retrieve_agent_sop')
114114

115115
list_sops_response_text = verify_response_content(list_sops_response)
116116

117117
# Parse SOP names from text (format: "* sop_name : description")
118118
sop_names = []
119-
for line in list_sops_response_text.split("\n"):
119+
for line in list_sops_response_text.split('\n'):
120120
line = line.strip()
121-
if line.startswith("*") and ":" in line:
121+
if line.startswith('*') and ':' in line:
122122
# Extract the SOP name between '*' and ':'
123-
sop_name = line.split("*", 1)[1].split(":", 1)[0].strip()
123+
sop_name = line.split('*', 1)[1].split(':', 1)[0].strip()
124124
if sop_name:
125125
sop_names.append(sop_name)
126126

127-
assert (
128-
len(sop_names) > 0
129-
), f"No SOPs found in response. Response: {list_sops_response_text[:200]}..."
130-
logger.info(f"Found {len(sop_names)} SOPs: {sop_names}")
127+
assert len(sop_names) > 0, (
128+
f'No SOPs found in response. Response: {list_sops_response_text[:200]}...'
129+
)
130+
logger.info('Found %d SOPs: %s', len(sop_names), sop_names)
131131

132132
# Step 2: Test retrieving the first SOP
133133
test_script = sop_names[0]
134-
logger.info(f"Testing with SOP: {test_script}")
134+
logger.info('Testing with SOP: %s', test_script)
135135

136-
response = await aws_mcp_client.call_tool("aws___retrieve_agent_sop", {"sop_name": test_script})
136+
response = await aws_mcp_client.call_tool(
137+
'aws___retrieve_agent_sop', {'sop_name': test_script}
138+
)
137139

138140
verify_response_content(response)
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
"""Negative integration tests for AWS MCP Server at https://aws-mcp.us-east-1.api.aws/mcp."""
22

3+
import boto3
34
import fastmcp
45
import logging
56
import pytest
6-
import boto3
77
from fastmcp.client import StdioTransport
8-
from datetime import datetime, timedelta
8+
99

1010
logger = logging.getLogger(__name__)
1111

12-
@pytest.mark.asyncio(loop_scope="module")
12+
13+
@pytest.mark.asyncio(loop_scope='module')
1314
async def test_expired_credentials():
1415
"""Test that expired credentials are properly rejected.
1516
@@ -20,68 +21,67 @@ async def test_expired_credentials():
2021
- PASS when expired credentials are rejected with appropriate error
2122
- FAIL if the modified credentials somehow work
2223
"""
23-
2424
# Get real credentials from boto3
2525
session = boto3.Session()
2626
creds = session.get_credentials()
2727

2828
# Use real access key and secret, but modify the token to simulate expiration by changing a few characters
29-
expired_token = creds.token[:-20] + "EXPIRED_TOKEN_12345"
29+
expired_token = 'EXPIRED_TOKEN_12345'
3030

3131
expired_client = fastmcp.Client(
3232
StdioTransport(
33-
command="mcp-proxy-for-aws",
33+
command='mcp-proxy-for-aws',
3434
args=[
35-
"https://aws-mcp.us-east-1.api.aws/mcp",
36-
"--log-level",
37-
"DEBUG",
38-
"--region",
39-
"us-east-1",
35+
'https://aws-mcp.us-east-1.api.aws/mcp',
36+
'--log-level',
37+
'DEBUG',
38+
'--region',
39+
'us-east-1',
4040
],
4141
env={
42-
"AWS_REGION": "us-east-1",
43-
"AWS_ACCESS_KEY_ID": creds.access_key,
44-
"AWS_SECRET_ACCESS_KEY": creds.secret_key,
45-
"AWS_SESSION_TOKEN": expired_token,
42+
'AWS_REGION': 'us-east-1',
43+
'AWS_ACCESS_KEY_ID': creds.access_key,
44+
'AWS_SECRET_ACCESS_KEY': creds.secret_key,
45+
'AWS_SESSION_TOKEN': expired_token,
4646
},
4747
),
4848
timeout=30.0,
4949
)
5050

5151
exception_raised = False
52-
exception_message = None
52+
exception_message = ''
5353

5454
try:
5555
async with expired_client:
56-
response = await expired_client.call_tool("aws___list_regions")
57-
logger.info(f"Tool call completed without exception: is_error={response.is_error}")
56+
response = await expired_client.call_tool('aws___list_regions')
57+
logger.info('Tool call completed without exception. Response: %s', response)
5858
except Exception as e:
5959
exception_raised = True
6060
exception_message = str(e)
61-
logger.info(f"Exception raised as expected: {type(e).__name__}: {exception_message}")
61+
logger.info('Exception raised as expected: %s: %s', type(e).__name__, exception_message)
6262

6363
# Assert that an exception was raised (credentials are invalid)
6464
assert exception_raised, (
65-
f"Expected authentication exception with invalid credentials, " f"but tool call succeeded."
65+
'Expected authentication exception with invalid credentials, but tool call succeeded.'
6666
)
6767

6868
# Verify the exception is related to authentication/credentials
6969
error_message_lower = exception_message.lower()
7070
auth_error_patterns = [
71-
"credential",
72-
"authentication",
73-
"authorization",
74-
"access denied",
75-
"unauthorized",
76-
"invalid",
77-
"expired",
78-
"signature",
79-
"401",
71+
'credential',
72+
'authentication',
73+
'authorization',
74+
'access denied',
75+
'unauthorized',
76+
'invalid',
77+
'expired',
78+
'signature',
79+
'401',
8080
]
8181

8282
assert any(pattern in error_message_lower for pattern in auth_error_patterns), (
8383
f"Exception was raised but doesn't appear to be authentication-related. "
84-
f"Expected one of {auth_error_patterns}, but got: {exception_message[:200]}"
84+
f'Expected one of {auth_error_patterns}, but got: {exception_message[:200]}'
8585
)
8686

87-
logger.info(f"Test passed: Invalid credentials correctly rejected")
87+
logger.info('Test passed: Invalid credentials correctly rejected')

0 commit comments

Comments
 (0)