Commit Graph

149 Commits

Author SHA1 Message Date
Jamie Lennox 67663054a5 Deprecate openstack repository
Remove all code and add a deprecation notice to the README. This should
make it really clear that we've moved.

Change-Id: Ic554437cf34fda7211ddfd2bb9d5f799f80a3096
2018-03-05 14:40:13 +11:00
Zuul 10a3470dac Merge "Fix last_request examples" 2018-02-27 03:03:35 +00:00
Ville Skyttä 13233c1df8 Fix last_request examples
last_request examples should not refer to qs for netloc and scheme.

Change-Id: I370b0f383e41f06cd0193b71ed7cbae3e044a1f3
Closes-Bug: #1751891
2018-02-27 13:44:21 +11:00
Ville Skyttä cd969eaded Fix spelling mistakes
Address simple spelling issues.

Closes-Bug: #1751890
Change-Id: I034e619ca47b7b0eb6299dcd75f740b938212a4e
2018-02-27 13:39:05 +11:00
Andreas Jaeger d9608f5f59 Move Zuul jobs in-tree
Convert the tox jobs to Zuul v3 native and move them here.

Use tox environment instead of openstack-tox since upper-constraint
is not needed.

Change-Id: Ic933cf202d20625e692c9ec40584ca6bc12f7da5
Needed-By: Ie295a23c5921e9213ccef31367d642eec2288ef3
2018-01-21 12:10:49 +01:00
Zuul fccc52d494 Merge "allow an adapter to be passed to a Mocker object" 2017-12-05 05:31:55 +00:00
David Kremer 9de969e548 allow an adapter to be passed to a Mocker object
Change-Id: I3e1a1d1a69ea2ed864c4dffac043466b257a7ef5
2017-12-05 14:13:08 +11:00
Zuul 8036cecc02 Merge "Remove discover from test-requirements" 2017-12-04 23:40:19 +00:00
Zuul b4fe4165b7 Merge "Rename [wheel] section to [bdist_wheel] as the former is legacy" 2017-12-04 23:25:30 +00:00
Zuul 4626cef28f Merge "Add testing for newer Python versions 3.5 and 3.6" 2017-12-04 23:25:15 +00:00
Zuul eee8a8b215 Merge "Include license file in the generated wheel package" 2017-12-04 23:25:14 +00:00
Jon Dufresne 2a193a2dc5 Rename [wheel] section to [bdist_wheel] as the former is legacy
For additional details, see:

54ddbcc9ce/wheel/bdist_wheel.py?fileviewer=file-view-default#bdist_wheel.py-119:125

http://pythonwheels.com/

Change-Id: I3e34a09499684cfd5adc6d89273ded54459e89c6
2017-11-19 14:16:27 -08:00
Jon Dufresne 0c9bccafd6 Include license file in the generated wheel package
The wheel package format supports including the license file. This is
done using the [metadata] section in the setup.cfg file. For additional
information on this feature, see:

https://wheel.readthedocs.io/en/stable/index.html#including-the-license-in-the-generated-wheel-file

Change-Id: I972b93e3c048aab31f4e630865fcf3ca1da733a6
2017-11-19 14:15:59 -08:00
Jon Dufresne 281867576d Add testing for newer Python versions 3.5 and 3.6
Include all supported Python versions as trove classifiers. Helps
library users know, at a glance, if the library can be integrated with
a project.

Remove Python 2.6 trove classifier, support was removed in
9bcf955af8

Also add trove classifier for PyPy as it is included in the tox test
matrix.

Change-Id: Iff7dcec47260006b325e3059cfaf8b8e912d2318
2017-11-19 14:11:51 -08:00
Darragh Bailey d59b584d88 Return a separate copy for each call to decorator
Similar to decorating a class, should create a separate mock copy
otherwise it acts as a caching decorator and any mock responses added
on each call will be present for subsequent calls.

Change-Id: Iabd70aa457ceb4dbc147d7cbaeec913148cb3b56
2017-06-26 11:14:43 +01: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
Swapnil Kulkarni (coolsvap) fa287fa98a Remove discover from test-requirements
It's only needed for python < 2.7 which is not supported

Change-Id: I09ed0815f1ad34bcf54076fbfd76c2ffba47845b
2016-07-22 06:58:48 +00: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