Skip to content

Commit 0557a66

Browse files
committed
Move testing utilities from smithy-testing to smithy-http package
1 parent 34f556a commit 0557a66

File tree

16 files changed

+47
-118
lines changed

16 files changed

+47
-118
lines changed

packages/smithy-http/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
11
# smithy-http
22

33
This package provides primitives and interfaces for http functionality in tooling generated by Smithy.
4+
5+
---
6+
7+
## Testing
8+
9+
The `smithy_http.testing` module provides shared utilities for testing HTTP functionality in smithy-python clients.
10+
11+
### MockHTTPClient
12+
13+
The `MockHTTPClient` allows you to test smithy-python clients without making actual network calls. It implements the `HTTPClient` interface and provides configurable responses for functional testing.
14+
15+
#### Basic Usage
16+
17+
```python
18+
from smithy_http.testing import MockHTTPClient
19+
20+
# Create mock client and configure responses
21+
mock_client = MockHTTPClient()
22+
mock_client.add_response(
23+
status=200,
24+
headers=[("Content-Type", "application/json")],
25+
body=b'{"message": "success"}'
26+
)
27+
28+
# Use with your smithy-python client
29+
config = Config(transport=mock_client)
30+
client = TestSmithyServiceClient(config=config)
31+
32+
# Test your client logic
33+
result = await client.some_operation({"input": "data"})
34+
35+
# Inspect what requests were made
36+
assert mock_client.call_count == 1
37+
captured_request = mock_client.captured_requests[0]
38+
assert result.message == "success"
39+
```
40+
41+
### Utilities
42+
43+
- `create_test_request()`: Helper for creating test HTTPRequest objects
44+
- `MockHTTPClientError`: Exception raised when no responses are queued

packages/smithy-testing/src/smithy_testing/__init__.py renamed to packages/smithy-http/src/smithy_http/testing/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
"""Shared testing utilities for smithy-python functional tests."""
4+
"""Shared utilities for smithy-python functional tests."""
55

6-
from .http import MockHTTPClient, MockHTTPClientError
6+
from .mockhttp import MockHTTPClient, MockHTTPClientError
77
from .utils import create_test_request
88

99
__version__ = "0.0.0"

packages/smithy-testing/src/smithy_testing/http.py renamed to packages/smithy-http/src/smithy_http/testing/mockhttp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from copy import copy
66

77
from smithy_core.aio.utils import async_list
8+
89
from smithy_http import tuples_to_fields
910
from smithy_http.aio import HTTPResponse
1011
from smithy_http.aio.interfaces import HTTPClient, HTTPRequest

packages/smithy-testing/src/smithy_testing/utils.py renamed to packages/smithy-http/src/smithy_http/testing/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
from smithy_core import URI
5+
56
from smithy_http import tuples_to_fields
67
from smithy_http.aio import HTTPRequest
78

packages/smithy-testing/tests/unit/test_mock_http_client.py renamed to packages/smithy-http/tests/unit/testing/test_mockhttp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
import pytest
5-
from smithy_testing import MockHTTPClient, MockHTTPClientError, create_test_request
5+
from smithy_http.testing import MockHTTPClient, MockHTTPClientError, create_test_request
66

77

88
async def test_default_response():

packages/smithy-testing/tests/unit/test_utils.py renamed to packages/smithy-http/tests/unit/testing/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
from smithy_testing import create_test_request
4+
from smithy_http.testing import create_test_request
55

66

77
def test_create_test_request_defaults():

packages/smithy-testing/NOTICE

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/smithy-testing/README.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/smithy-testing/pyproject.toml

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)