Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context manager for mocking API interactions in tests #388

Merged
merged 9 commits into from
Oct 13, 2024

Conversation

mesozoic
Copy link
Collaborator

@mesozoic mesozoic commented Sep 6, 2024

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

Copy link

codecov bot commented Sep 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mesozoic mesozoic merged commit 4fd2172 into gtalarico:main Oct 13, 2024
3 of 4 checks passed
@mesozoic mesozoic deleted the testing branch October 13, 2024 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant