We've been using requests-mock in openstack testing now for quite some
time without issue. The interface has been stable since about 0.3.
Change the classifier to stable and the next release will be a 1.0
Change-Id: I8ab3121a04c2b69f2a9cef2f9d4d662b527387fb
This information is available via the connection but not on the request
object. Make it available for testing as well.
Closes-Bug: #1565576
Co-Authored-By: Nikolay Martynov <mar.kolya@gmail.com>
Change-Id: I3bfb84472e223421dcdaa04161460e1cbfba352a
Cookies are treated unusually in requests. To handle them exactly as
requests does we would need to create httplib responses with headers and
pass those back. This would be a significant change that is a little
tricky. Instead use the available requests cookies handlers to merge the
cookies into the responses returned from the adapter.
Provide a way to create and preload a CookieJar that will be returned as
part of responses. We also provide the dict interface that requests
does. We don't really have a lot of choice here as these interfaces are
supported by the cookie apis and we would need to actively work around
things to remove that interface.
Change-Id: Ifc1253abc1b4004e81aa7bffad1faf32aedd0d4c
Closes-Bug: #1480835
The FakeHTTPMessage and FakeHTTPResponse objects were only defined for
old versions of requests to provide compatibility. It turns out we need
these for cookie extraction in new versions as well so always define the
object and leave the old compatibility check.
Change-Id: Ifb42fd1c6b1b895b26bee59632ad0dedd78a6256
Now it is possible to mock not only a function but also a class:
class TestClass(object)
def test_func_a(self, m):
m.register_uri('GET', 'http://test.com', text='data')
...
def test_func_b(self, m)
m.register_uri('GET', 'http://test.com', text='data')
...
This new behavior mimics behavior of `patch` from `mock` library.
Added docs for this new feature.
Closes-Bug: #1404805
Change-Id: I8303dc4bc682cf12ffe86e7712b5a1c54de83efb
There is a cyclical reference here where the matcher holds a list of
requests in history and the requests hold a reference to the matcher.
Break this using a weakref so that it can be cleaned up easily.
In practice I don't see this being a problem as people will want to test
that value as part of the test where the mock is still active.
There has not been a release with this functionality so there is no
compatibility change.
Change-Id: Id1669ea40a48d09432367646a0004866947ff72b
Include the matcher that handled this request as part of the request in
history. This will allow users to ensure that a particular history
response was generated by this mock matcher.
This is somewhat of a replacement for simply including the full response
in the history as the response object is not great to work with from a
user perspective and will be transformed between what is returned by the
adapter and what the user will see from requests.
Closes-Bug: #1402874
Change-Id: I5612f080755dbc4ce719aa961d9b29ed54a677a4
This seems to have been an oversight to leave off. Proxy the call and
call_count variables so that they can be retrieved from the mocker.
Change-Id: I5abe9cb0b3870fd9f50a8834193d939268f11efa
Update the example code on the README to use the .get() function rather
than register_uri('GET'). This is the first thing most people see and we
want to make that look as clean as possible.
Change-Id: I87e0d40d76f70acfbe8ba9686a5ea5a6b0d73f85
Make it easy to specify an exception that should be raised instead of
having to create a callback and raise it manually.
Change-Id: Iabf951e070e9ba8572f5ac14f4e09dbdd5824261
Closes-Bug: #1402496
The locations provided are no longer available. The cgit portion of the
URL has been removed.
Switch to https:// for transport.
Closes-Bug: #1402501
Change-Id: I7216259dcbae2104ee4a4dba6a451e11b14d3214
Doc builds are failing, apparently it's fixed by having pbr installed.
PBR really should be installed in all tox environments so just put it in
the main tox deps.
Change-Id: Iffc9a343d2953800a0afb4a92a5a6835e868994d
As per the governance resolution https://review.openstack.org/119875,
projects should have a docs environment in their tox.ini testing
interface. Add one.
Change-Id: Ia92b59e9b0db701b152d9c76535d7dcffdacf45d
When running the keystoneclient and novaclient tip tests we should run
against the development branch of requests as well so that we are not
surprised by new releases upstream.
Change-Id: Iac36c91adbdf2b6fa8444d15aa8f9dee66f7e297
Related-Bug: #1363632
In requests 1.2 and python 3 headers are bytes so we need to optionally
convert unicode text to bytes when testing that the request headers
match those being checked for.
Change-Id: I02dadc05dd5a93769da646686b938c2b26f6f267
Closes-Bug: #1361528
In requests 1.2 Responses are assumed to always have a HTTPResponse
object and it tries to extract headers from it. We solved this in the
create_response function but we didn't use it in all our tests.
Always use create_response when creating a custom matcher response.
Change-Id: I979f74a64c6f5accf1b88dcc3e5e004131945dff
Closes-Bug: #1361515
This will make it much easier to do matching on last_request and when
doing callbacks.
Change-Id: I705f28b925afdf92c417433375d0f99d36071a6b
Closes-Bug: #1361462
Requests 1.2.3 seems to be a real pain, it's right before the v2.0
cleanup and there have been a number of inconsistencies. Create a tox
environment for checking them, and we should really gate on this as
well.
Change-Id: I343b9b7124a6bfb8e1fb711a286b8a896f50fc7b
This is used in python 3 rather that the getheaders function that we
already stub out.
Change-Id: Ie147214a49fc744dd2ff1fc958c60547874d05d9
Closes-Bug: #1361527
This works in requests 1.1 and 2.0 but it fails in the 1.2 series. It's
not something we should be too concerned about enforcing at the
requests-mock layer so just fix up the test.
Closes-Bug: #1361497
Change-Id: I8f30262ab3177d9e3d3644c083aed6031eeba78f
Session.prepare_request didn't exist until requests 2.0 which is newer
than our requirements specifies.
We don't really need this function, we can use the older version for
testing rather than increase our minimum required version.
Change-Id: Ia5a8c187e31b8f883e93d8086481f5e08d764bc7
Closes-Bug: #1361488
The response.connection should be the adapter that the request went
through. This is important in some situations (requests-kerberos) where
the connection is reused by the auth plugin to send additional requests.
Change-Id: I87bf996e2edbfb29eba9b4000d976a49cbf6c8cc
Closes-Bug: #1358903
We want to be able to test changes in requests-mock against some of our
consumers to ensure we don't break anyone.
Change-Id: I029c25d7274e0d7638d85cbf3dc6c42aad3a5463
Remove Travis file, and links to travis buttons from readme.
Change homepage to the docs site, rather than personal github repo.
Change-Id: Ic6f279f9f243081c50b80a13ee1158dd181ff8cd
Stub out the httplib.HTTPResponse so that we can be compatible with
Requests < 2.3. We need this to be packaged in major systems that still
have older requests.
Change-Id: Ibec3cead76b7246a6987f9f3b3fef5df6bcc7bc8