Commit Graph

134 Commits

Author SHA1 Message Date
Tony Breeds c403dea95a Retire Packaging Deb project repos
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
2017-09-12 16:10:46 -06:00
Rick van de Loo fcc640f495 Add string representation to _RequestObjectProxy
Via https://github.com/openstack/requests-mock/pull/12 by @allardhoeve

Change-Id: I7e9bba3a22a08ee41af5480b8a3cee49ef06624d
2017-04-18 10:20:06 +02:00
Jamie Lennox aa3e87c4ee Add a releasenote for additional_matcher
It really should have gone in with the review that implemented the
feature but better late than never.

Change-Id: Iafcfd17b9ddad8c09d66aadb6eda6f5603c23b8b
2017-02-01 16:13:52 +11:00
Jenkins 3b3042f29a Merge "Add documentation for the exception response" 2017-02-01 05:07:52 +00:00
Jenkins 11f77e0f5c Merge "Fix occurences of `adatper`" 2017-02-01 05:02:51 +00:00
Jamie Lennox d333f179f3 Add documentation for the exception response
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
2017-02-01 15:57:15 +11:00
Jamie Lennox fc11bac6cc Fix occurences of `adatper`
Interestingly there is more than 1.

Change-Id: I14ee8e233cfdb89e385a35eb624412cac3691b89
2017-02-01 15:54:46 +11:00
Jenkins bf7c25f8d4 Merge "Allow arbirtrary matcher to be add to match" 2017-02-01 04:31:51 +00:00
Jamie Lennox 86fb33d13d Type check the empty string when creating repsonse
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
2017-01-31 21:55:51 +11:00
Jamie Lennox 10c84747e0 Allow arbirtrary matcher to be add to match
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
2017-01-23 10:19:56 +11:00
Jamie Lennox 95dffefe83 Allow for nested mocking
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
2016-11-18 16:10:54 +11:00
Jamie Lennox 81b72f4397 Use create_response for fake http response in tests
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
2016-11-18 16:09:27 +11:00
Jamie Lennox c3ed2aa479 Add hostname and port properties to request
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
2016-10-13 15:19:46 +11:00
Jamie Lennox 86e33d1eff Move request code and tests into their own files
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
2016-10-13 15:03:21 +11:00
Jenkins 3b48e48ebf Merge "Add called_once to Mocker" 2016-10-05 21:23:46 +00:00
Jenkins 891265bc44 Merge "Fix exception message when creating a response" 2016-10-05 21:20:55 +00:00
Jamie Lennox 3deef1a454 Add called_once to Mocker
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
2016-10-04 19:11:24 +11:00
Jamie Lennox 9fbd45b35f Fix docs building
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
2016-10-04 16:34:16 +11:00
voith 890a4fe9ff Fix exception message when creating a response
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
2016-09-26 10:27:35 +10:00
Jenkins c105f1cae2 Merge "Enable case sensitive matching" 2016-09-14 04:09:28 +00:00
Jamie Lennox 0c6e567ec7 Add a called_once property to adapter
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
2016-09-02 05:56:17 +00:00
Jamie Lennox 1b08dcc705 Enable case sensitive matching
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
2016-08-26 11:54:50 +10:00
Jenkins e42b9828dc Merge "Return b'' when reading closed response." 2016-08-26 01:35:55 +00:00
Jenkins 39f1f74b6b Merge "Allow doing real_http per mock via the mocker" 2016-08-26 01:35:01 +00:00
Jamie Lennox 6df03ed3d0 Provide fixture extras for pip
Allow installing the additional requirements for using the fixture
contrib module using pip extras.

Closes-Bug: #1501665
Change-Id: I20510d8db35c3cfdc0bc2892675b04d224027c7e
2016-08-25 17:48:18 +10:00
Jamie Lennox b2026313e3 Allow doing real_http per mock via the mocker
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
2016-08-25 17:43:19 +10:00
Jamie Lennox fe147914a6 Return b'' when reading closed response.
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
2016-08-25 10:34:49 +10:00
Manuel Kaufmann b3de408600 Fixture documentation error
Closes-Bug: #1583786
Change-Id: Ic30fe1b6da649a3ceed332bfb69285f1794faa72
2016-05-20 10:44:57 +10:00
Jenkins ecfb7b2f95 Merge "Add trove support for py34 and remove py33" 2016-05-18 05:38:22 +00:00
Jenkins a8b009cf28 Merge "Add tox environment to run against master requests" 2016-05-09 05:02:10 +00:00
Jenkins fead1f8c27 Merge "Doc fixups" 2016-05-09 04:42:20 +00:00
Jamie Lennox cacbc01c40 Add tox environment to run against master requests
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
2016-05-09 14:41:15 +10:00
Jenkins b9f9a16f08 Merge "Change dev status classifier to stable" 2016-05-09 04:37:18 +00:00
Jenkins a8d39918ae Merge "Fix py34 DB issue and remove py33/py26" 2016-05-09 04:36:45 +00:00
Jamie Lennox b55b47cfff Change dev status classifier to stable
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
2016-05-09 14:26:30 +10:00
Jamie Lennox 63fe479d22 Doc fixups
Add some of the recent request object attributes into the docs.

Change-Id: If699bf83379032e77ca08a91e0def70fb6b57202
2016-05-09 14:20:51 +10:00
Jamie Lennox 780eb4b4fe Expose cert and proxies as attributes of the last request.
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
2016-05-09 13:50:59 +10:00
Jamie Lennox 459e13cb24 Add timeout and allow_retries to RequestProxy
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
2016-04-04 10:17:10 +10:00
reedip 790dba4c0a Add trove support for py34 and remove py33
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
2016-02-12 01:08:24 +00:00
Janonymous 9bcf955af8 Fix py34 DB issue and remove py33/py26
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
2016-01-07 02:56:49 +00:00
Louis Taylor 28bfbe23ad Remove pypip.in badge from readme
pypip.in has been broken for a long time.

Change-Id: I43766a841d1cc19a8911ee2c5f97646f6e2fa2f2
2015-12-13 01:37:51 +00:00
Jenkins 4cf015d738 Merge "Support Cookies" 2015-11-23 00:55:50 +00:00
Jenkins e6e4dab61d Merge "Expose Fake objects in compat" 2015-11-23 00:53:15 +00:00
Jenkins 49c0ed3f74 Merge "Change ignore-errors to ignore_errors" 2015-11-18 01:03:46 +00:00
Jamie Lennox fe37c6cc3a Support Cookies
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
2015-11-18 12:00:09 +11:00
Jamie Lennox 1b10e30f1e Expose Fake objects in compat
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
2015-11-18 12:00:06 +11:00
Jeremy Stanley ba28c09408 Update .gitreview for new namespace
Change-Id: Ib61eb495d2fb1d466045fd061741ecf703013304
2015-10-17 22:38:27 +00:00
Monty Taylor 3293a13df4 Change ignore-errors to ignore_errors
Needed for coverage 4.0

Change-Id: If91bad253355ecb0f5cbb9b99db09d49c398e639
2015-09-21 15:27:48 +00:00
Jamie Lennox aeb66e9046 Update docs
Update the docs to reference new features and the more recent way that
statements are written.

Change-Id: I7fc00143b9ab4366a00324aaf59d59baecf9da4a
2015-01-19 14:14:28 +10:00
Jenkins 9547a7b6b1 Merge "Allow to decorate class with mock" 2015-01-15 01:44:21 +00:00