Skip to content
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

Fixed #63: Support HTTPX params argument #81

Merged
merged 2 commits into from Oct 13, 2020

Conversation

jocke-l
Copy link
Contributor

@jocke-l jocke-l commented Sep 25, 2020

This PR adds support for params argument (#63) to respx.add and it's shortcuts. It does so by using httpx.QueryParams which seems to be "publicly" exposed. I'm open for other solutions too, but I think it's easier to be on par with httpx' API this way.

It also makes all other parameter except method and url keyword-only arguments, which means this code may break existing test suites. The reason for this is to be able to arrange the arguments in a natural way and avoid further backward incompatibilities in the future.

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.

Awesome to see some light on this!

respx/api.py Show resolved Hide resolved
respx/api.py Show resolved Hide resolved
respx/models.py Outdated Show resolved Hide resolved
@lundberg
Copy link
Owner

lundberg commented Oct 1, 2020

Ticks one feature of #79

@lundberg
Copy link
Owner

lundberg commented Oct 1, 2020

FYI @jocke-l , httpx.URL takes params kwarg, so if we go that route in this PR, it would be less params-handling to do in set_url.

Still, your current httpx.QueryParams code might be needed for regex urls.

respx/models.py Outdated Show resolved Hide resolved
@lundberg
Copy link
Owner

lundberg commented Oct 5, 2020

Let's do the final touches to simplify our code in set_url by handling base_url and params with httpx URL, see httpx Client base_url, url merging and Request params for inspiration @jocke-l .

@lundberg lundberg mentioned this pull request Oct 9, 2020
@jocke-l jocke-l force-pushed the feature/api-params branch 2 times, most recently from 90c0ada to f4992f8 Compare October 10, 2020 00:15
@jocke-l jocke-l requested a review from lundberg October 10, 2020 00:29
tests/test_api.py Outdated Show resolved Hide resolved
@jocke-l jocke-l force-pushed the feature/api-params branch 2 times, most recently from 6b02739 to 4ded5f7 Compare October 10, 2020 10:40
respx/models.py Outdated Show resolved Hide resolved
respx/transports.py Outdated Show resolved Hide resolved
respx/transports.py Outdated Show resolved Hide resolved
respx/models.py Outdated Show resolved Hide resolved
tests/test_transports.py Outdated Show resolved Hide resolved
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.

Almost there...

respx/models.py Outdated Show resolved Hide resolved
tests/test_api.py Outdated Show resolved Hide resolved
respx/models.py Outdated Show resolved Hide resolved
respx/models.py Outdated Show resolved Hide resolved
@jocke-l jocke-l force-pushed the feature/api-params branch 2 times, most recently from 6956203 to 314b021 Compare October 12, 2020 20:21
tests/test_api.py Outdated Show resolved Hide resolved
tests/test_api.py Outdated Show resolved Hide resolved
tests/test_api.py Outdated Show resolved Hide resolved
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.

Legit!

@lundberg lundberg merged commit aaac1c3 into lundberg:master Oct 13, 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.

None yet

2 participants