1
The best way to go about it is probably as you suggest, creating the api object outside and passing it to the constructor. This will allow you to replace the api class easily for testing.
You could create a MockPyChimp class, which has the same methods as the actual PyChimp api. This way you could easily reuse the same mock class across your tests.
I’m not familiar enough with python/django unit testing to be able to suggest any specific libraries to assist in this, but I would assume there exists some sort of mocking libraries or such.
0
Well the best way to “mock” a function call in Python is with the mock library. Also if you are using nose as your unit-test framework then a plugin worth considering is nose-blockage which ensures no API calls get through if your tests don’t properly mock out everything.
- [Django]-Query Limits and Order cannot work together in django
- [Django]-How do I programmatically create a user with django_social_auth?
- [Django]-Using Django, I want to find all of the published events after today, but only from the nearest month containing events