Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- engine = create_async_engine(
- "postgresql+asyncpg://" +
- "test_user:" +
- "test_password@" +
- "db_test/db_test",
- echo=True,
- poolclass=NullPool
- )
- test_async_session = async_sessionmaker(
- autoflush=False,
- autocommit=False,
- bind=engine,
- class_=AsyncSession
- )
- @pytest_asyncio.fixture(scope="function")
- async def test_db():
- async with engine.begin() as conn:
- await conn.run_sync(Base.metadata.create_all)
- async with test_async_session() as session:
- yield session
- async with engine.begin() as conn:
- await conn.run_sync(Base.metadata.drop_all)
- await engine.dispose()
- @pytest_asyncio.fixture
- async def user_in_db_fixture(
- db_user_fixture,
- test_db
- ):
- user_instance = User(**db_user_fixture)
- test_db.add(user_instance)
- await test_db.commit()
- # tests
- @pytest.mark.asyncio
- async def test_signup_when_user_in_db(
- user_in_db_fixture,
- async_client_fixture,
- user_payload_correct_fixture
- ):
- response = await async_client_fixture.post(
- url='/auth/sign-up',
- json=user_payload_correct_fixture
- )
- assert response.status_code == 400
Advertisement
Add Comment
Please, Sign In to add comment