I'm building a (facebook connected) web server using Flask. Here's an example route
@app.route('/login', methods=['GET'])
def login():
graph = facebook.GraphAPI(request.args.get('access_token'))
profile = graph.get_object('me')
return jsonify(profile)
This works fine, but it seems bad practice to be continually hitting Facebook servers when I'm doing local dev.
What is the most effective way to re-route the facebook API to mocks or even a mock server? Internally, the facebook-sdk
library uses requests
to reach graph.facebook.com
.
I've seen this question
python mock Requests and the response
and in particular, Dropbox's responses
library, but it looks like you have to wrap each call in their decorator. It would work well for a unit testing suite, but I'm just interested in doing development against mock data and mock responses.
Update: In response to Thomas, I had been thinking about a similar solution. I tried adding:
if config_name == 'development':
print 'monkey'
import requests
def mock(*args, **kwargs):
print args, kwargs
return {}
requests.request = mock
But that didn't seem to change the behavior of the facebook-sdk
library.