vendredi 20 novembre 2015

How do I spy on a requests querystring params using requests_mock?

I'm trying to write unit tests against my requests that use the requests library. I'm using requests_mock to spy on them but .qs doesn't seem to return what was passed via .params

import requests
import requests_mock

session = requests.Session()
adapter = requests_mock.Adapter()
session.mount('mock', adapter)

adapter.register_uri('GET', 'mock://test.com', text='mocked')

params = {'foo': 'bar'}
session.get('mock://test.com', params=params)

print(adapter.request_history[0].qs) # prints {}

Any idea what I'm doing wrong?

Aucun commentaire:

Enregistrer un commentaire