-
Hello, I'm working on writing some unit tests for my project which utilizes this API. I see you have some test data within the test directory for populating a league object. How can I properly retrieve and save similar data with some more edge case leagues that I'm running into? If it helps, this is for the football module. Thanks anyone for their help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Thats a great question, if you are already part of a league or the league is public you can run the >>> import sys
>>> f = open("log.out", 'w')
>>> sys.stdout = f
>>> from espn_api.football import League
>>> league = League(league_id=1234, year=2022, debug=True) Then log.out will look something like this
The hard part is if you are not part of a league that has the edge cases you are looking for. If you know what the data could look like you can always adjust the response yourself or try to find a public league that is the type of league you are looking for. At the beginning of the season I usually try to join a couple public leagues with different scoring types so that I can always try out the package with different leagues. |
Beta Was this translation helpful? Give feedback.
-
Ok, excellent. I pulled a few and it seems that while printing out the json response in the response, it it returning the pythonic json vs the raw json. i.e. it returns None, True, and False instead of null, true, and false. Additionally, it returns things in single quotes instead of double quotes for valid json. I thought just saving the data and doing a search and replace of those values would fix it, but many player names have single quotes so it becomes a bit of a nightmare. Are we able to assume that ESPN API response will always be json? If so, we should be able to safely change the end of this logger statement to be |
Beta Was this translation helpful? Give feedback.
Thats a great question, if you are already part of a league or the league is public you can run the
espn_api
package in debug mode to get all of the request and response from the api calls and then use the data for unit tests. Here is quick example in the CLIThen log.out will look something like this