Ability to set real_http for specific pattern

Bug #1501665 reported by Michael van Tellingen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
requests-mock
Fix Released
Wishlist
Jamie Lennox

Bug Description

Using requests-mock in combination with suds requests I want to mock https:// calls but not file:// calls since that is used to load wsdl's available in the project.

Would be cool to add for example: requests.get('file://', real_http=True)

Revision history for this message
Jamie Lennox (jamielennox) wrote :

Interesting, i'd never really considered doing file:// based stuff through requests.

I'll have a think about how you can do this, but if you're looking for a solution today you could probably do something like:

adapter = requests_mock.Adapter()

session = requests.Session()
session.mount('http', adapter)
session.mount('https', adapter)

adapter.get('://test.com/path', text='text') # set up the mock ignoring protocol

resp = session.get('http://test.com/path) # do the request

Changed in requests-mock:
importance: Undecided → Wishlist
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to requests-mock (master)

Fix proposed to branch: master
Review: https://review.openstack.org/360172

Changed in requests-mock:
assignee: nobody → Jamie Lennox (jamielennox)
status: New → In Progress
Changed in requests-mock:
milestone: none → 1.1
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.openstack.org/360189

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to requests-mock (master)

Reviewed: https://review.openstack.org/360172
Committed: https://git.openstack.org/cgit/openstack/requests-mock/commit/?id=6df03ed3d03d05f606bff28764e72bc0574333b7
Submitter: Jenkins
Branch: master

commit 6df03ed3d03d05f606bff28764e72bc0574333b7
Author: Jamie Lennox <email address hidden>
Date: Thu Aug 25 11:42:52 2016 +1000

    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

Changed in requests-mock:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Reviewed: https://review.openstack.org/360189
Committed: https://git.openstack.org/cgit/openstack/requests-mock/commit/?id=b2026313e304e92312b0cbae3ff266626b068953
Submitter: Jenkins
Branch: master

commit b2026313e304e92312b0cbae3ff266626b068953
Author: Jamie Lennox <email address hidden>
Date: Thu Aug 25 12:49:39 2016 +1000

    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

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.