This commit is part of a series to retire the Packaging Deb
project. Step 2 is to remove all content from the project
repos, replacing it with a README notification where to find
ongoing work, and how to recover the repo if needed at some
future point (as in
https://docs.openstack.org/infra/manual/drivers.html#retiring-a-project).
Change-Id: I0fac484f313f2b453e1de7a8fda3014251eb83e5
It really should have gone in with the review that implemented the
feature but better late than never.
Change-Id: Iafcfd17b9ddad8c09d66aadb6eda6f5603c23b8b
There was no documentation on how to use the exc= parameter. Add some
simple docs so people at least know that it's there.
Change-Id: I743e6899c2fe611790a7880bd909bb1260f9de52
Closes-Bug: #1625580
When creating a response we type check that the user has passed the
correct type to content and text, however we check this based on whether
the value is True and not whether it has been passed at all which means
that the empty string of the wrong type can incorrectly pass through
this check.
Fix this check to test the empty string.
Anyone relying on this passing will be caught with a more confusing
TypeError later and so this should be backwards compatible.
Change-Id: I826da9b7fd83bb88af50e4a96a5e6358ee35e4b2
Closes-Bug: #1647880
To handle requests for additional features on matching add a callback
function that can match anything on the request object. This is easier
than adding every combination of matcher option - though we should still
add things that are commonly used.
Change-Id: I300f74a1f2103545eca60087b2352a535add188d
Closes-Bug: #1657308
The double mocking solution we have now of mocking send and get_adapter
is a bit unusual. One of the problems is that if you have a nested mock
situation then send calling the last send means get_adapter is remocked
again and the outer adapter ends up being the last installed.
To avoid this always go to the real original send function to bypass any
outer installed mockers and make sure our get_adapter function is
triggered.
Change-Id: I47bff5e7da98e5238bd926e22845a7ca34f21940
Closes-Bug: #1642690
The old FakeHTTPResponse we're using in the tests is really basic and
lacks a lot of the information that is expected in a response from an
adapter. This is a hard problem that we've already solved in the
create_response function so use that to create a test response instead
of a custom solution here.
Change-Id: I2999c9c69b4e9ad895114fab8ae7f8ce275fa2a4
Closes-Bug: #1642697
Using request.netloc can be confusing because you have to check whether
or not the port is included. We are going to want this seperation in
later patches so expose it on the request.
Change-Id: I2e4bad425fdbc2501727b295752900d4ce4086bc
The Request proxy object is growing bigger and already has its own
category of tests. Move each into their own file with some simplified
helpers for testing.
Change-Id: I0dcc5d8d09feaf3febfcc8a4d114973096279c51
The called_once function was added to the Matcher and the Adapter but
not the top level Mocker function.
Change-Id: I4daa839d931b44fa69133ace663d41c84796b4ba
Closes-Bug: #1630159
As part of review [1] the openstack build system assumes the layout of
the docs directories to be doc/build. This is not what requests-mock was
producing. Fix the docs building directories to make it work with the
build system again.
[1] Icb0c02dc5b6f7b5e248e0df6d6093c29535b08f3
Closes-Bug: #1630114
Change-Id: Iea93ecfb0506d5ccd0b79ad35f5677797fadf730
When you register a handler the type for text or data can be a string or
a callback that provides a string. By the time you get to
create_response this callback should have been called and only a string
can be passed.
This check originally would have been in place for when a callback was
run and the return value was not the expected type, however
create_response is a public function that can be used on its own.
Correct the exception to clarify in create_response you must pass a
string or bytes and not a callback.
Change-Id: I3e700afddc1f40454f69a564066495bfc77d91c8
Closes-Bug: #1627506
Mock has a useful feature called assert_called_once. We don't have the
asserts here, but having called_once as a property is an easy way to
emulate this.
Change-Id: I59dfb53830195e73884fa0ca8a43b1de91fa1425
When matching URLs both strings are always lowercased to provide case
insensitive matching. Whilst this makes sense for the protocol and the
host names it does not necessarily hold true for paths and query
strings.
A byproduct of this is that the lowercased strings are being reported in
request_history which makes it harder to verify requests you made.
We enable globally and per adapter setting case sensitive matching. This
is intended to become the default in future releases.
Change-Id: I7bde70a52995ecf31a0eaeff96f2823a1a6682b2
Closes-Bug: #1584008
Allow installing the additional requirements for using the fixture
contrib module using pip extras.
Closes-Bug: #1501665
Change-Id: I20510d8db35c3cfdc0bc2892675b04d224027c7e
If you set up requests_mock to catch all requests (which I would
recommend) you sometimes get caught with things like file:// paths that
should be allowed to reach the filesystem.
To do this we should allow you to add a matcher that says a specific
route can bypass the catch all and do a real request.
This is a bit of a layer violation but I thought it was easy to start
with, then realized why it wasn't.
Change-Id: Ic2516f78413b88a489c8d6bd2bc39b8ebb5bf273
Closes-Bug: #1501665
A HTTPResponse returns a b'' when you read from a closed socket. BytesIO
raises a ValueError. This only comes to light when you are specifically
reading past the end of the stream in a chunking scenario like
swiftclient does.
Change-Id: I67ed45252deac9472cfb011a5eb89130a3791d6b
Closes-Bug: #1616690
Add a new environment that will install the latest development version
of requests. This lets you check for anything new coming down that might
bite us in upcoming releases.
Change-Id: I3dfaf79c681c5c4075b387947d797285c011cb88
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
When adding timeout and allow_redirects we added the ability to fetch
some of the connection parameters from the request. Given we have made
that link we should also expose the verify, cert and proxies so users
can test that.
Particularly testing that cert has been passed through to a request is
something i've come across a number of times.
Change-Id: I2c60be44769607c32eaf68ad697656b85cae0737
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
py33 has been deprecated from Mitaka so removing the
same from setup.cfg.
tox.ini supported py34 but setup.cfg did not, so adding
the change for the same.
Change-Id: I05c01df2022d3bdfb756cb47166ddc00a941c101
Closes-Bug: #1526170
To solve the problem of "db type could
not be determined" on py34 we have to run first the py34 env to, then,
run py27. This patch puts py34 first on the tox.ini list of envs to
avoid this problem to happen. py33/py26 is not supported from Mitaka,
as per Infra, therefore removing the support for the same.
Closes-Bug: #1526170
Closes-bug: #1489059
Change-Id: Ia4a7d21179efc17d4d9af2bbc0c060e5b6512b79
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