prisma-korea / prisma-fastapi Goto Github PK
View Code? Open in Web Editor NEWFastapi prisma template
Fastapi prisma template
Hello, I came across your medium tutorial on how to use FastAPI and Prisma. It helped me get started with FastAPI and Prisma
But I'm having issues writing tests. I am trying to use a separate DB and reset it after testing
This is how my conftest.py currently looks like:
TEST_DB_DSN = "postgresql://postgres:postgres@localhost:5433/postgres"
prisma = Prisma(datasource={"url": TEST_DB_DSN})
async def teardown_db(client: Prisma) -> None:
print("Teardown")
print("Dropping all tables")
await client.execute_raw("DROP schema public CASCADE")
print("Creating all tables")
stream = os.popen(f"DB_DSN={TEST_DB_DSN} prisma db push --skip-generate")
output = stream.read()
@pytest.fixture(scope="module", autouse=True)
async def test_init(request):
await prisma.connect()
yield
await teardown_db(client=prisma)
await prisma.disconnect()
@pytest.fixture(scope="module")
def event_loop() -> Iterator[asyncio.AbstractEventLoop]:
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()
# Test client
@pytest.fixture(scope="module")
def client(event_loop: asyncio.BaseEventLoop) -> Iterator[TestClient]:
initializer(TORTOISE_ORM["apps"]["models"]["models"], loop=event_loop)
with TestClient(app) as c:
yield c
finalizer()
Every other config is the same as yours
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.