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

Testing notion-sdk-py when part of another project #108

Closed
thomashirtz opened this issue Feb 5, 2022 · 4 comments
Closed

Testing notion-sdk-py when part of another project #108

thomashirtz opened this issue Feb 5, 2022 · 4 comments

Comments

@thomashirtz
Copy link

thomashirtz commented Feb 5, 2022

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!

@thomashirtz thomashirtz changed the title Database test for notion-sdk-py Test for notion-sdk-py Feb 5, 2022
@thomashirtz thomashirtz changed the title Test for notion-sdk-py Testing notion-sdk-py when part of another project Feb 5, 2022
@ramnes
Copy link
Owner

ramnes commented Feb 5, 2022

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.

@thomashirtz
Copy link
Author

What do you mean by mock the library completely ?
So it means that every time you make changes to this library, you'll use an account to test that notion-sdk-py is working ? You save this account credential locally and test only locally ? I was trying to learn good practices and implement all that on my github but I'm not sure there is an easy and clean way to do this then :/

@ramnes
Copy link
Owner

ramnes commented Feb 5, 2022

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 unittest.mock. Then you have a lot of higher-level wrappers, e.g. pytest-mock.

So it means that every time you make changes to this library, you'll use an account to test that notion-sdk-py is working ?

Only when I write new tests that call the API, or change the calls of an existing test.

You save this account credential locally and test only locally ?

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.

I was trying to learn good practices and implement all that on my github but I'm not sure there is an easy and clean way to do this then :/

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. :)

@thomashirtz
Copy link
Author

Ok thank you for your detailed answer :) !

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. :)

Understandable haha

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

No branches or pull requests

2 participants