Lately, I've been building a Python platform that relies heavily on interactions with Github. Instead of re-inventing the wheel, I decided to go with PyGithub as a wrapper around Github v3 API.
This library implements the full API, which allows me to be very productive when I need to add a workflow in my platform that involves Github. However, it quickly became a real PITA to write unit tests. Even if the package comes with its own testing Framework, it is not documented yet and I didn't manage to crack it up in a decent amount of time.
I decided to hack the testing a little bit, using another very cool package, httpretty. Httpretty allows you to monkey patch the socket module during testing, so you can respond anything you want to any kind of network requests. Here's what I came up with, do not hesitate to give any feedback.
NOTE
This is a workaround solution, at best, knowing that PyGithub does have a built-in testing framework. If, like me and a few others, you don't want to spend too much time trying to figure out how it works, my solution is quick, easy and efficient enough... But is probably not as good as the built-in solution ;-)
Thank you for your response. I did something similar but on calling the
g.get_organization(org).get_repos()
, its not calling the right response registered in httpretty:This is the pagenation class I have, where the repo.json file is a list of dictionaries containing some fake repo responses. The name of my org is dummy_org and this is my addition to response_mapping
'/orgs/dummy_org/repos(/(\w+))?': fake.repo
, but callingg.get_organization(org).get_repos()
in the code is not getting fake.repo as a response, rather, its getting an empty PaginationList object