pittcsc / PittAPI

An API to easily get data from the University of Pittsburgh
https://pittapi.pittcsc.org
GNU General Public License v2.0
105 stars 30 forks source link

Updated dining tests #165

Closed akrishan11 closed 1 month ago

akrishan11 commented 1 month ago

Fixes #164

Updated tests for functions in new Dining module

Added mocks for dining locations, dining menu, and dining schedule

tianyizheng02 commented 1 month ago

Edited the PR description to automatically link the PR to the correct issue

tianyizheng02 commented 1 month ago
=========================== short test summary info ============================
FAILED tests/lab_test.py::LabTest::test_fetch_labs - RecursionError: maximum recursion depth exceeded
FAILED tests/lab_test.py::LabTest::test_get_status - RecursionError: maximum recursion depth exceeded
FAILED tests/library_test.py::LibraryTest::test_get_documents - RecursionError: maximum recursion depth exceeded
FAILED tests/people_test.py::PeopleTest::test_people_get_person - RecursionError: maximum recursion depth exceeded
FAILED tests/people_test.py::PeopleTest::test_people_get_person_none - RecursionError: maximum recursion depth exceeded
FAILED tests/people_test.py::PeopleTest::test_people_get_person_too_many - RecursionError: maximum recursion depth exceeded
=================== 6 failed, 44 passed, 2 skipped in 4.28s ====================

The tests that are failing don't have anything to do with the dining module, gonna try to take a look at the code to see if there are any patterns.

akrishan11 commented 1 month ago

Tests look good, I think. Where do the contents of the new JSON files come from, BTW?

I just copied the exact data that would be returned from the Dine on Campus at the specific endpoints called by the sample function calls. I don't have much experience writing tests so I'm not sure if there was anything wrong with my approach.

tianyizheng02 commented 1 month ago

The tests that are failing don't have anything to do with the dining module, gonna try to take a look at the code to see if there are any patterns.

OK, I'm pretty sure the failing tests are failing because their inputs aren't mocked. The failing tests in lab_test.py, library_test.py, and people_test.py all run the module functions directly (i.e. make HTTP requests) as opposed to calling the function with mocked inputs. All function tests for other modules (that aren't skipped) do mock their inputs, and those are clearly passing. My guess is that real HTTP requests get messed up when the enclosing functions are run from a test environment, probably something to do with shared resources in the test environment.

TL;DR the tests in lab_test.py, library_test.py, and people_test.py all should be rewritten to use mocked inputs instead of making real HTTP requests.