21 Commits

Author SHA1 Message Date
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
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
Manuel Kaufmann
b3de408600 Fixture documentation error
Closes-Bug: #1583786
Change-Id: Ic30fe1b6da649a3ceed332bfb69285f1794faa72
2016-05-20 10:44:57 +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
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
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
Sebastian Kalinowski
1774bb11a9 Allow to decorate class with mock
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
2014-12-22 08:37:55 +01:00
Jamie Lennox
22760510b7 Allow querying if a mock was called.
Firstly privatize everything on the existing matcher object as it is now
going to be a public interface.

Add called and call_count parameters for querying how many times that
particular mock was invoked. We do this by saving a reference to every
request that passes through. This is inefficient for now, however it
lets us do more interesting things like called_with in the future.
2014-07-29 17:40:50 +10:00
Jamie Lennox
33474a296e Http Methods handling to look more like requests
Allow users to specify methods via the same HTTP method based format
that requests does. It makes them look more synchronous.
2014-07-10 14:24:50 +10:00
Jamie Lennox
24e7d43a16 Allow custom matchers
Allow users to specify there own matchers. A matcher should take a
request and return a response or None.
2014-07-01 12:50:56 +10:00
Jamie Lennox
793ed719b7 Remove Overview section of fixtures 2014-06-23 22:42:53 +10:00
Jamie Lennox
97fb2bce39 Doctest fixups 2014-06-23 22:37:36 +10:00
Jamie Lennox
595deb3dfd Add request_headers matching
If you provide request_headers then the headers must also match the
requeest to match.
2014-06-23 20:28:50 +10:00
Jamie Lennox
833ee180c3 Create the Mocker
A standard means of mock loading the adapter. Because we have this move
fixtures stuff into contrib.

Add some documentation for all this.
2014-06-23 16:03:40 +10:00
Jamie Lennox
d826ba6f82 Fixup doc function link 2014-06-17 12:51:21 +10:00
Jamie Lennox
13d3322d90 Add regexp url matching 2014-06-17 10:37:25 +10:00
Jamie Lennox
5e360fb73c Add the ANY wildcard 2014-06-17 09:56:09 +10:00
Jamie Lennox
4c97632c53 Split docs for better RTFD viewing
Simplified README, not sure how wise that is.
2014-06-16 22:36:56 +10:00
Jamie Lennox
bdb7239cd1 A documentation effort
Added sphinx setup, apidoc and fixed up readme.
2014-06-16 14:53:48 +10:00