Parsing Twitter Geo Data and Mocking API Calls by Example
Blog post from Pybites
Bob from PyBites created a script called "whotweeted" to determine whether he or Julian tweeted from their shared Twitter account by parsing tweet location data using the Tweepy library. This script evolved into a learning exercise on how to unittest an API. Bob implemented a caching decorator to store API outputs and used the `unittest.mock` library to patch and mock the Tweepy API calls, allowing for effective testing without repeatedly hitting the live API, thus avoiding potential rate limits and reducing test execution time. The script raises exceptions for invalid input data, enhancing its robustness. Bob plans to explore mocking further in future articles, emphasizing the educational value of extending simple exercises into more complex explorations in coding.