supabase / supabase-py

Python Client for Supabase. Query Postgres from Flask, Django, FastAPI. Python user authentication, security policies, edge functions, file storage, and realtime data streaming. Good first issue.
https://supabase.com/docs/reference/python
MIT License
1.67k stars 194 forks source link

Advice or example of mocking the client for tests #681

Open philliphartin opened 8 months ago

philliphartin commented 8 months ago

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

Describe the solution you'd like

Describe alternatives you've considered

Atticuszz commented 8 months ago

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 commented 8 months ago

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

tinvaan commented 7 months ago

@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 commented 7 months ago

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

syou98 commented 6 months ago

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