-
Notifications
You must be signed in to change notification settings - Fork 24
Add testing utilities to smithy-http #588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add testing utilities to smithy-http #588
Conversation
arandito
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Alessandra! This looks great. Just left some minor comments about simplification and other nits.
| client_config: HTTPClientConfiguration | None = None, | ||
| ) -> None: | ||
| """ | ||
| :param client_config: Configuration that applies to all requests made with this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, I think we'll be using Google style docstrings moving forward (see #564). I think for now that would cause the CI to fail so this is more of a heads up.
| def add_response( | ||
| self, | ||
| status: int = 200, | ||
| headers: list[tuple[str, str]] | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In line 49 we set fields to headers if it exists or to an empty list if it doesn't exist. Can we simplify this by defaulting headers to an empty list instead of making it an optional parameter with a default of None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! I would prefer to keep the current pattern to stay consistent with the existing ResponseTestHTTPClient implementation in the generated protocol tests (see example here). This also avoids the mutable default argument issue in Python.
packages/smithy-http/.changes/next-release/smithy-http-feature-20251024135122.json
Outdated
Show resolved
Hide resolved
| self._response_queue: deque[HTTPResponse] = deque() | ||
| self._captured_requests: list[HTTPRequest] = [] | ||
|
|
||
| def add_response( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential idea for a helper function: it's pretty common in tests that we add multiple responses and test subsequent calls. It may be nice to have a helper function that sets a default response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chatted offline and will look into this, but we'll consider adding these convenience methods as we see need for this use case.
0557a66 to
8467d11
Compare
Co-authored-by: Nate Prewitt <[email protected]>
nateprewitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alexgromero!
The base branch was changed.
Issue #, if available:
Description of changes:
MockHTTPClientto test generated clients without hitting live endpoints.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.