Skip to content

Latest commit

 

History

History
463 lines (374 loc) · 23.6 KB

CHANGELOG.md

File metadata and controls

463 lines (374 loc) · 23.6 KB

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

0.35.0 - 2024-11-28

Changed

0.34.0 - 2024-11-18

Added

  • is_optional parameter is now available on responses and callbacks registration. Allowing to add optional responses while keeping other responses as mandatory. Refer to documentation for more details.
  • is_reusable parameter is now available on responses and callbacks registration. Allowing to add multi-match responses while keeping other responses as single-match. Refer to documentation for more details.

Fixed

  • httpx_mock.get_request will now also propose to refine filters if more than one request is found instead of only proposing to switch to httpx_mock.get_requests.

0.33.0 - 2024-10-28

Added

  • Explicit support for python 3.13.
  • should_mock option (callable returning a boolean) is now available, defaulting to always returning True. Refer to documentation for more details.
  • Matching on the full multipart body can now be performed using match_files and match_data parameters. Refer to documentation for more details.
  • Matching on extensions (including timeout) can now be performed using match_extensions parameter. Refer to documentation for more details.

Removed

  • non_mocked_hosts option is not available anymore. Use should_mock instead as in the following sample:
    import pytest
    
    @pytest.mark.httpx_mock(non_mocked_hosts=["my_local_test_host"])
    def test_previous_behavior(httpx_mock):
        ...
    
    @pytest.mark.httpx_mock(should_mock=lambda request: request.url.host not in ["my_local_test_host"])
    def test_new_behavior(httpx_mock):
        ...
    Please note that your hosts might need to be prefixed with www. depending on your usage.

0.32.0 - 2024-09-27

Added

  • The following option is now available:
    • can_send_already_matched_responses (boolean), defaulting to False.
  • Assertion failure message in case of unmatched responses is now linking documentation on how to deactivate the check.
  • Assertion failure message in case of unmatched requests is now linking documentation on how to deactivate the check.
  • httpx.TimeoutException message issued in case of unmatched request is now linking documentation on how to reuse responses (in case some responses are already matched).

Fixed

  • Documentation now clearly state the risks associated with changing the default options.
  • Assertion failure message in case of unmatched requests at teardown is now describing requests in a more user-friendly way.
  • Assertion failure message in case of unmatched requests at teardown is now prefixing requests with - to highlight the fact that this is a list, preventing misapprehension in case only one element exists.
  • Assertion failure message in case of unmatched responses at teardown is now prefixing responses with - to highlight the fact that this is a list, preventing misapprehension in case only one element exists.
  • httpx.TimeoutException message issued in case of unmatched request is now prefixing available responses with - to highlight the fact that this is a list, preventing misapprehension in case only one element exists.
  • httpx.TimeoutException message issued in case of unmatched request is now listing unmatched responses (in registration order) before already matched one (still in registration order).
    • The incentive behind this change is to help identify a potential mismatch faster as the first unmatched response is the most likely to be the one expected to match.
  • Response description in failure messages (httpx.TimeoutException message issued in case of unmatched request or assertion failure message in case of unmatched responses at teardown) is now displaying if the response was already matched or not and less misleading in it's phrasing about what it can match (a single request by default).

Changed

  • Last registered matching response will not be reused by default anymore in case all matching responses have already been sent.
    • This behavior can be changed thanks to the new pytest.mark.httpx_mock(can_send_already_matched_responses=True) option.
    • The incentive behind this change is to spot regression if a request was issued more than the expected number of times.
  • HTTPXMock class was only exposed for type hinting purpose. This is now explained in the class docstring.
    • As a result this is the last time a change to __init__ signature will be documented and considered a breaking change.
    • Future changes will not be documented and will be considered as internal refactoring not worth a version bump.
    • __init__ now expects one parameter, the newly introduced (since 0.31.0) options.
  • HTTPXMockOptions class was never intended to be exposed and is now marked as private.

0.31.2 - 2024-09-23

Fixed

  • httpx_mock marker can now be defined at different levels for a single test.

0.31.1 - 2024-09-22

Fixed

  • It is now possible to match on content provided as async iterable by the client.

0.31.0 - 2024-09-20

Changed

  • Tests will now fail at teardown by default if some requests were issued but were not matched.
    • This behavior can be changed thanks to the new pytest.mark.httpx_mock(assert_all_requests_were_expected=False) option.
    • The incentive behind this change is to spot unexpected requests in case code is swallowing httpx.TimeoutException.
  • The httpx_mock fixture is now configured using a marker (many thanks to Frazer McLean).
    # Apply marker to whole module
    pytestmark = pytest.mark.httpx_mock(assert_all_responses_were_requested=False)
    
    # Or to specific tests
    @pytest.mark.httpx_mock(non_mocked_hosts=[...])
    def test_foo(httpx_mock):
        ...
    • The following options are available:
      • assert_all_responses_were_requested (boolean), defaulting to True.
      • assert_all_requests_were_expected (boolean), defaulting to True.
      • non_mocked_hosts (iterable), defaulting to an empty list, meaning all hosts are mocked.
  • httpx_mock.reset do not expect any parameter anymore and will only reset the mock state (no assertions will be performed).

Removed

  • pytest 7 is not supported anymore (pytest 8 has been out for 9 months already).
  • assert_all_responses_were_requested fixture is not available anymore, use pytest.mark.httpx_mock(assert_all_responses_were_requested=False) instead.
  • non_mocked_hosts fixture is not available anymore, use pytest.mark.httpx_mock(non_mocked_hosts=[]) instead.

0.30.0 - 2024-02-21

Changed

Fixed

  • Switch from setup.py to pyproject.toml (many thanks to Felix Scherz).

0.29.0 - 2024-01-29

Added

0.28.0 - 2023-12-21

Changed

0.27.0 - 2023-11-13

Added

  • Explicit support for python 3.12.

Fixed

  • Custom HTTP transport are now handled (parent call to handle_async_request or handle_request).

Changed

  • Only HTTP transport are now mocked, this should not have any impact, however if it does, please feel free to open an issue describing your use case.

0.26.0 - 2023-09-18

Added

  • Added proxy_url parameter which allows matching on proxy URL.

0.25.0 - 2023-09-11

Changed

Removed

  • pytest 6 is no longer supported.

0.24.0 - 2023-09-04

Added

  • Added match_json parameter which allows matching on JSON decoded body (matching against python representation instead of bytes).

Changed

  • Even if it was never documented as a feature, the match_headers parameter was not considering header names case when matching.
    • As this might have been considered a feature by some users, the fact that match_headers will now respect casing is documented as a breaking change.

Fixed

  • Matching on headers does not ignore name case anymore, the name must now be cased as sent (as some servers might expect a specific case).
  • Error message in case a request does not match will now include request headers with mismatching name case as well.
  • Error message in case a request does not match will now include request headers when not provided as lower-cased to match_headers.
  • Add :Any type hint to **matchers function arguments to satisfy strict type checking mode in pyright.

0.23.1 - 2023-08-02

Fixed

  • Version 0.23.0 introduced a regression removing the support for mutating json content provided in httpx_mock.add_response.
    • This is fixed, you can now expect the JSON return being as it was when provided to httpx_mock.add_response:
    mutating_json = {"content": "request 1"}
    # This will return {"content": "request 1"}
    httpx_mock.add_response(json=mutating_json)

    mutating_json["content"] = "request 2"
    # This will return {"content": "request 2"}
    httpx_mock.add_response(json=mutating_json)

0.23.0 - 2023-08-02

Removed

  • Python 3.7 and 3.8 are no longer supported.

Fixed

  • httpx_mock.add_response is now returning a new httpx.Response instance upon each matching request. Preventing unnecessary recursion in streams.

0.22.0 - 2023-04-12

Changed

0.21.3 - 2023-01-20

Fixed

  • Update version specifiers for pytest dependency to support packaging 23.
  • Add explicit support for python 3.11.

0.21.2 - 2022-11-03

Fixed

  • URL containing non ASCII characters in query can now be matched.
  • Requests are now cleared when calling httpx_mock.reset.

0.21.1 - 2022-10-20

Fixed

  • httpx_mock.add_callback now handles async callbacks.

0.21.0 - 2022-05-24

Changed

Removed

  • Python 3.6 is no longer supported.

0.20.0 - 2022-02-05

Added

0.19.0 - 2022-01-26

Changed

Deprecated

  • Python 3.6 is no longer supported.

0.18.0 - 2022-01-17

Fixed

  • Callback are now executed as expected when there is a matching already sent response.

Changed

  • Registration order is now looking at responses and callbacks. Prior to this version, registration order was looking at responses before callbacks.

Removed

  • httpx_mock.add_response data, files and boundary parameters have been removed. It was deprecated since 0.17.0. Refer to this version changelog entry for more details on how to update your code.

0.17.3 - 2021-12-27

Fixed

  • A callback can now raise an exception again (regression in mypy check since 0.16.0).

Added

  • An exception can now be raised without creating a callback by using httpx_mock.add_exception method.

0.17.2 - 2021-12-23

Fixed

  • Do not consider a callback response as read, even if it is not a stream, before returning to httpx. Allowing any specific httpx handling to be triggered such as httpx.Response.elapsed computing.

0.17.1 - 2021-12-20

Fixed

  • Do not consider a response as read, even if it is not a stream, before returning to httpx. Allowing any specific httpx handling to be triggered such as httpx.Response.elapsed computing.

0.17.0 - 2021-12-20

Changed

  • httpx_mock.add_response data parameter is only used for multipart content. It was deprecated since 0.14.0. Refer to this version changelog entry for more details on how to update your code.

Removed

  • pytest_httpx.to_response function has been removed. It was deprecated since 0.14.0. Refer to this version changelog entry for more details on how to update your code.

Deprecated

  • httpx_mock.add_response data, files and boundary parameters that were only used for multipart content. Instead, provide the stream parameter with an instance of the httpx._multipart.MultipartStream.

Fixed

  • Responses are no more read or closed when returned to the client. Allowing to add a response once and reading it as a new response on every request.

0.16.0 - 2021-12-20

Changed

  • Callbacks are now expected to have a single parameter, the request. The previously second parameter extensions, can still be accessed via request.extensions.

Fixed

  • Allow for users to run mypy --strict.

0.15.0 - 2021-11-16

Changed

0.14.0 - 2021-10-22

Changed

  • Requires httpx==0.20.* (many thanks to Terence Honles)
  • Callbacks are now expected to return a httpx.Response instance instead of the previous httpcore.Response tuple. As a consequence, pytest_httpx.to_response now returns a httpx.Response instance.

Added

  • httpx_mock.add_response now allows to explicitly provide bytes using content parameter.
  • httpx_mock.add_response now allows to explicitly provide string using text parameter.
  • httpx_mock.add_response now allows to explicitly provide HTML string content using html parameter.
  • httpx_mock.add_response now allows to explicitly provide streamed content using stream parameter and the new pytest_httpx.IteratorStream class.

Deprecated

  • pytest_httpx.to_response is now deprecated in favor of httpx.Response. This function will be removed in a future release.
  • httpx_mock.add_response data parameter should now only be used for multipart content. Instead, use the appropriate parameter amongst content, text, html or stream.

0.13.0 - 2021-08-19

Changed

  • Requires httpx==0.19.*
  • files parameter of httpx_mock.add_response now expect dictionary values to be binary (as per httpx new requirement).

0.12.1 - 2021-08-11

Fixed

  • Type information is now provided following PEP 561 (many thanks to Caleb Ho).

0.12.0 - 2021-04-27

Changed

  • Requires httpx==0.18.*
  • ext callback parameter was renamed into extensions.

0.11.0 - 2021-03-01

Changed

0.10.1 - 2020-11-25

Fixed

  • Order of different parameters does not matter anymore for URL matching. It does however still matter for a same parameter.

0.10.0 - 2020-10-06

Added

  • Document how to assert that no requests were issued.
  • Document how to send cookies.
  • Explicit support for python 3.9

Changed

  • Requires httpx==0.16.*
  • Update documentation to reflect the latest way of sending bytes using httpx. Via content parameter instead of data.
  • Code now follow black==20.8b1 formatting instead of the git master version.
  • Sending a JSON response using json parameter will now set the application/json content-type header by default.

Fixed

  • Allow to provide any supported httpx headers type in headers parameter for httpx_mock.add_response and pytest_httpx.to_response. Previously only dict was supported.

0.9.0 - 2020-09-22

Changed

  • Requires httpx==0.15.*
  • Callbacks are now called with ext dictionary instead of timeout. To follow httpcore design changes. You can still retrieve timeout by using ext['timeout']

0.8.0 - 2020-08-26

Added

  • non_mocked_hosts fixture allowing to avoid mocking requests sent on some specific hosts.

Changed

  • Display the matchers that were not matched instead of the responses that were not sent.

0.7.0 - 2020-08-13

Changed

  • The httpx.HTTPError message issued in case no mock could be found is now a httpx.TimeoutException containing all information required to fix the test case (if needed).

0.6.0 - 2020-08-07

Changed

0.5.0 - 2020-07-31

Changed

  • requires pytest 6.
  • assert_and_reset mock method has been renamed to reset and now takes a boolean parameter to specify if assertion should be performed.

Added

  • It is now possible to disable the assertion that all registered responses were requested thanks to the assert_all_responses_were_requested fixture. Refer to documentation for more details.

Removed

  • It is not possible to provide an URL encoded response anymore by providing a dictionary in data parameter.

0.4.0 - 2020-06-05

Changed

  • httpx_mock pytest fixture does not need to be explicitly imported anymore (many thanks to Thomas LÉVEIL).

0.3.0 - 2020-05-24

Changed

  • Requires httpx==0.13.*
  • requires pytest 5.4.0 (at least)
  • callbacks must now return a tuple as per httpcore specifications. Refer to documentation for more details.
  • callbacks timeout parameter is now a dict as per httpcore specifications.

0.2.1 - 2020-03-20

Fixed

  • Handle the fact that some classes and functions we use are now part of internals within httpx.

0.2.0 - 2020-03-09

Changed

0.1.0 - 2020-02-13

Added

  • Consider as stable.

0.0.5 - 2020-02-10

Added

  • match_headers parameter now allows matching on headers.
  • match_content parameter now allows matching on full body.

Changed

  • httpx.HTTPError is now raised instead of Exception in case a request cannot be matched.

0.0.4 - 2020-02-07

Changed

  • url is not a mandatory parameter for response registration anymore.
  • url is not a mandatory parameter for callback registration anymore.
  • url is not a mandatory parameter for request retrieval anymore.
  • method does not have a default value for response registration anymore.
  • method does not have a default value for callback registration anymore.
  • method does not have a default value for request retrieval anymore.
  • url and methods are not positional arguments anymore.

0.0.3 - 2020-02-06

Added

  • Allow providing JSON response as python values.
  • Mock async httpx requests as well.
  • Allow providing files and boundary for multipart response.
  • Allow to provide data as a dictionary for multipart response.
  • Allow providing callbacks that are executed upon reception of a request.
  • Handle the fact that parameters may be introduced in httpx *Dispatcher.send method.
  • Allow to retrieve all matching requests with HTTPXMock.get_requests

Changed

  • method can now be provided even if not entirely upper-cased.
  • content parameter renamed into data.
  • HTTPXMock.get_request now fails if more than one request match. Use HTTPXMock.get_request instead.
  • HTTPXMock.requests is now private, use HTTPXMock.get_requests instead.
  • HTTPXMock.responses is now private, it should not be accessed anyway.
  • url can now be a re.Pattern instance.

0.0.2 - 2020-02-06

Added

  • Allow to retrieve requests.

0.0.1 - 2020-02-05

Added

  • First release, should be considered as unstable for now as design might change.