-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Testing notion-sdk-py when part of another project #108
Comments
The most common method in that kind of scenario is to mock the library completely. Another solution is to use cassettes, just as we're doing in notion-sdk-py (instead of mocking httpx). It requires a test account or a template page for when you're writing new tests or updating the API calls made in previous tests, but the good point is that the rest of the time, i.e. when anyone just changes a few things, all the API calls are perfectly mocked without effort. |
What do you mean by mock the library completely ? |
Monkey patching the library during the tests so that it returns what you assume it would always return in your scenarios, so that you can run the test without an API key. The basic way to do this is with
Only when I write new tests that call the API, or change the calls of an existing test.
The API key is passed through the environment (12 factors style). Tests are run both locally and through CI with the cassettes. But real API calls to generate the cassettes are only made locally.
There's only so much you can do when depending on a tier API you don't have any control over. I wish Notion's team would release a fake API server à la localstack but I don't see that coming soon and I'm not sure I want to do it myself either. :) |
Ok thank you for your detailed answer :) !
Understandable haha |
Hello,
I am using notion-sdk-py for a project, I would like to write tests in order to see if the different functions that are using some modules from notion-sdk-py are working in order to enhance the workflow/stability of my project. However I am not sure how it is possible to test this API as it is linked to a notion database/account.
Do you have recommendation on how to do so ?
Thanks!
The text was updated successfully, but these errors were encountered: