gtalarico / pyairtable

Python Api Client for Airtable
https://pyairtable.readthedocs.io
MIT License
784 stars 138 forks source link

Context manager for mocking API interactions in tests #388

Closed mesozoic closed 3 weeks ago

mesozoic commented 1 month ago

This is the last item on the roadmap for 3.0. There is still a lot more that this could do, but at a bare minimum it offers a way to:

  1. Set up some fake records that we'll pretend exist in "real" tables
  2. Mock all the typical API methods for manipulating records, with sensible side effects
  3. Disallow any interaction with the API which was not mocked out

We've found this pattern useful with complex background jobs that make several sequential operations against the API, where even if we have sensible unit tests for smaller components of functionality, it's easier to test edge cases or bug reports when we can treat the entire job as a single function under test and, given certain inputs, make assertions about its behavior.

FYI @walkingpendulum

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (97f2f1b) to head (8ae9d6a).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #388 +/- ## ========================================== Coverage 100.00% 100.00% ========================================== Files 28 28 Lines 2985 3132 +147 ========================================== + Hits 2985 3132 +147 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.