Skip to content

Commit 8467d11

Browse files
committed
Implement feedback
1 parent 00560a5 commit 8467d11

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"type": "feature",
3-
"description": "Added support for minimal components required for SDK functional testing"
3+
"description": "Added `MockHTTPClient` for testing SDK clients without making real HTTP requests."
44
}

packages/smithy-http/src/smithy_http/testing/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from .mockhttp import MockHTTPClient, MockHTTPClientError
77
from .utils import create_test_request
88

9-
__version__ = "0.0.0"
10-
119
__all__ = (
1210
"MockHTTPClient",
1311
"MockHTTPClientError",

packages/smithy-http/src/smithy_http/testing/mockhttp.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from collections import deque
55
from copy import copy
6+
from typing import Any
67

78
from smithy_core.aio.utils import async_list
89

@@ -29,7 +30,7 @@ def __init__(
2930
client.
3031
"""
3132
self._client_config = client_config
32-
self._response_queue: deque[HTTPResponse] = deque()
33+
self._response_queue: deque[dict[str, Any]] = deque()
3334
self._captured_requests: list[HTTPRequest] = []
3435

3536
def add_response(
@@ -40,17 +41,17 @@ def add_response(
4041
) -> None:
4142
"""Queue a response for the next request.
4243
43-
:param status: HTTP status code (200, 404, 500, etc.)
44+
:param status: HTTP status code
4445
:param headers: HTTP response headers as list of (name, value) tuples
4546
:param body: Response body as bytes
4647
"""
47-
response = HTTPResponse(
48-
status=status,
49-
fields=tuples_to_fields(headers or []),
50-
body=async_list([body]),
51-
reason=None,
48+
self._response_queue.append(
49+
{
50+
"status": status,
51+
"headers": headers or [],
52+
"body": body,
53+
}
5254
)
53-
self._response_queue.append(response)
5455

5556
async def send(
5657
self,
@@ -69,7 +70,13 @@ async def send(
6970

7071
# Return next queued response or raise error
7172
if self._response_queue:
72-
return self._response_queue.popleft()
73+
response_data = self._response_queue.popleft()
74+
return HTTPResponse(
75+
status=response_data["status"],
76+
fields=tuples_to_fields(response_data["headers"]),
77+
body=async_list([response_data["body"]]),
78+
reason=None,
79+
)
7380
else:
7481
raise MockHTTPClientError(
7582
"No responses queued in MockHTTPClient. Use add_response() to queue responses."
@@ -85,6 +92,9 @@ def captured_requests(self) -> list[HTTPRequest]:
8592
"""The list of all requests captured by this client."""
8693
return self._captured_requests.copy()
8794

95+
def __deepcopy__(self, memo: Any) -> "MockHTTPClient":
96+
return self
97+
8898

8999
class MockHTTPClientError(Exception):
90100
"""Exception raised by MockHTTPClient for test setup issues."""

packages/smithy-http/tests/unit/testing/test_mockhttp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def test_queued_responses_fifo():
3333
assert mock_client.call_count == 2
3434

3535

36-
async def test_captures_requests():
36+
async def test_captured_requests():
3737
# Test all requests are captured for inspection
3838
mock_client = MockHTTPClient()
3939
mock_client.add_response()
@@ -76,6 +76,7 @@ async def test_response_headers():
7676
assert response.status == 201
7777
assert "Content-Type" in response.fields
7878
assert response.fields["Content-Type"].as_string() == "application/json"
79+
assert "X-Amz-Custom" in response.fields
7980
assert response.fields["X-Amz-Custom"].as_string() == "test"
8081

8182

0 commit comments

Comments
 (0)