Skip to content

Allow lowercase method strings in .add #80

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

Conversation

lbillinghamwrk
Copy link
Contributor

Fixes #76

MockTransport().add("get", ...) now works the same as MockTransport().add("GET", ...)

Laurence Billingham and others added 3 commits September 24, 2020 11:06

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@@ -226,7 +226,7 @@ def __init__(
self.pass_through = None
self._match_func = method
else:
self.method = method
self.method = method.upper()
Copy link
Contributor Author

@lbillinghamwrk lbillinghamwrk Sep 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a decent approach?
We could also make a top level constant respx.GET == "GET"
and encourage folk to use that instead of the string literals (think this is what they do in responses land)?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the correct place and way to solve the issue.

About the constants, I'd say we skip them to align with HTTPX. If HTTPX adds constants for the http methods in the future, then those can be uses with RESPX.

@lbillinghamwrk
Copy link
Contributor Author

Better if I squash the commits that are: linting, updating from master and removing the debugging commented out stuff?

request = respx_mock.add(method_str, url, content=content)
response = await getattr(client, client_method_attr)(url)
assert request.called is True
assert response.json() == content
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also be testing the respx.add way of doing this like in test_mock.py::test_start_stop?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test is fine as is.

Copy link
Owner

@lundberg lundberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing

@@ -226,7 +226,7 @@ def __init__(
self.pass_through = None
self._match_func = method
else:
self.method = method
self.method = method.upper()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the correct place and way to solve the issue.

About the constants, I'd say we skip them to align with HTTPX. If HTTPX adds constants for the http methods in the future, then those can be uses with RESPX.

request = respx_mock.add(method_str, url, content=content)
response = await getattr(client, client_method_attr)(url)
assert request.called is True
assert response.json() == content
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test is fine as is.

lbillinghamwrk and others added 2 commits October 1, 2020 14:41

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Co-authored-by: Jonas Lundberg <jonas@5monkeys.se>

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@lundberg lundberg merged commit ee95e16 into lundberg:master Oct 1, 2020
lundberg added a commit that referenced this pull request Oct 15, 2020
Added
- Added `text`, `html` and `json` content shorthands to ResponseTemplate. (PR #82)
- Added `text`, `html` and `json` content shorthands to high level API. (PR #93)
- Added support to set `http_version` for a mocked response. (PR #82)
- Added support for mocking by lowercase http methods, thanks @lbillinghamtn. (PR #80)
- Added query `params` to align with HTTPX API, thanks @jocke-l. (PR #81)
- Easier API to get request/response from call stats, thanks @SlavaSkvortsov. (PR #85)
- Enhanced test to verify better content encoding by HTTPX. (PR #78)
- Added Python 3.9 to supported versions and test suite, thanks @jairhenrique. (PR #89)

Changed
- `ResponseTemplate.content` as proper getter, i.e. no resolve/encode to bytes. (PR #82)
- Enhanced headers by using HTTPX Response when encoding raw responses. (PR #82)
- Deprecated `respx.stats` in favour of `respx.calls`, thanks @SlavaSkvortsov. (PR #92)

Fixed
- Recorded requests in call stats are pre-read like the responses. (PR #86)
- Postponed request decoding for enhanced performance. (PR #91)
- Lazy call history for enhanced performance, thanks @SlavaSkvortsov. (PR #92)

Removed
- Removed auto setting the `Content-Type: text/plain` header. (PR #82)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement proposal: Increase flexibility of method in MockTransport().add?
2 participants