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

Advice or example of mocking the client for tests #681

Open
philliphartin opened this issue Feb 2, 2024 · 5 comments
Open

Advice or example of mocking the client for tests #681

philliphartin opened this issue Feb 2, 2024 · 5 comments

Comments

@philliphartin
Copy link

Is your feature request related to a problem? Please describe.

  • I'm working on a FastAPI project that uses the supabase-py client.
  • I am writing tests focused on API interaction (payload validation, return structure, etc).
  • Many of the endpoints interact with the supabase client to fetch data, perform some transforms and return it.
  • I want to mock the client and fake a query return - without actually calling Supabase.
  • However, I cannot find an example of best practice on how to do this.

Describe the solution you'd like

  • An example of how to mock the client to provide mocked query returns.

Describe alternatives you've considered

  • Considered running local DB to run tests against - but feels heavy
@Atticuszz
Copy link

repo
hey bro👋,there is base template of fastapi+ supabase with 90+% test
coverage,although i do not apply mock client tests,hope the rest of tests or other code would help💪

@philliphartin
Copy link
Author

Thank you @Atticuszz, I'll take a read and hope to understand it :)

@tinvaan
Copy link
Contributor

tinvaan commented Feb 6, 2024

@philliphartin have you tried https://vcrpy.readthedocs.io/en/latest ?

Basically, you keep aside a test account and use it with the API once. vcr-py will cache the responses and reuse them subsequently. A workaround like this might be your best bet in the absence of a dynamic & stateful mocking library.

@philliphartin
Copy link
Author

That's actually really cool @tinvaan. Certainly will save a lot of effort. Thanks

@syou98
Copy link

syou98 commented Mar 7, 2024

I run my test in a special project. When running test, at the beggining my test load all my tables, functions, triggers, etc ... via psql command. Then it launch all my scenarios including business logic, and then when it finish, it drops all to clean it for the next test.
So for my real project, I just need to change api keys, variables (for psql) and loads all tables, functions, etc ...

@philliphartin I have a question. Do you use middleware for your project ?
Thank you

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

4 participants