Re: suggestion for dependency injection in view tests

2011-10-04 Thread Stuart
Also, depending on your scenario, the classes might be overkill. You could just as easily pass in a callable. In that case your view would look something like this... def suggest(request, usrid=None, get_friends=__get_friends):     current_user = request.facebook.user     facebook_friends = get_fr

Re: suggestion for dependency injection in view tests

2011-10-04 Thread Stuart
Here is one approach... class FBFriends: def get_friends(self, current_user): return __get_friends(current_user) # heavy call def suggest(request, usrid=None, friend_source=FBFriends()): current_user = request.facebook.user facebook_friends = friend_source.get_friends(current_

suggestion for dependency injection in view tests

2011-10-04 Thread Reikje
In one of my views, I am doing a call to the Facebook graph API which is a bit heavyweight and you also need a valid token. I am looking into ways to use mocking/dependency injection to avoid having to do this call during view tests. So let's say i have this view method: def suggest(request, usrid