Completely rewrite textbook
module and its unit tests
#198
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contributes to #45 by fixing all
mypy
errors intextbook.py
as part of the module rewriteAs discussed in the CSC Discord server,
textbook.py
has been found to be broken. Parts of the underlying textbook API had changed, invalidating most of the existing code. For instance, one major change to the underlying API is that the API's request URLs now require CSRF tokens, which I believe weren't required before. Major breaking changes like this weren't caught earlier becausetextbook_test.py
mostly didn't validate any function outputs, only their return types, and thus the module's unit tests merely gave the illusion of correctness.I rewrote the module along with its unit tests to adjust for the changed textbook API, while taking the liberty to make the code more readable and robust based on discussions in the CSC Discord server. This includes better error handling, input validation, automatic retrieval of CSRF tokens, and much more comprehensive unit tests. The rewritten
textbook.py
passesmypy --strict --ignore-missing-imports
with no errors and has 90+% code coverage withpytest
.In addition to the code changes, I'm also introducing several more sample/mock files in order to properly test the API requests. As part of the changes to the mocks, I replaced the data for the STAT department with data for the MATH department instead—for some reason STAT classes just don't seem to have their textbooks listed on the Pitt textbook site, meaning that there's virtually no textbook data available for those classes that we can use as mocks anyway.