Closed joeyagreco closed 2 years ago
Yeah as of right now you would have to mock the REST calls that _fetch_league()
calls. That's currently being done in this repo's unit tests here but its a lot of mock data.
One possibility would be to pass a flag to not initialize the league right away. I wouldn't want to make it default else everyone's current package would be broken. I think the best solution would be to lazy load the data when needed but would require a larger refactor.
Sport
Football
Summary
When trying to instantiate a League object,
self._fetch_league()
is called, which leads to a REST call being made to ESPN's API.This presents problems when trying to create a standalone instance of the object with custom values.
For instance, when trying to create unit tests for code that uses the League class, creating a dummy instance for a mock to return (to avoid making the REST call during test runtime) is impossible, since the REST call is made at instantiation.
A possible solution is to remove the
self._fetch_league()
call from the__init__
method and allow it to be manually called after instantiation.