jabajke

Untitled

Jun 26th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. engine = create_async_engine(
  2. "postgresql+asyncpg://" +
  3. "test_user:" +
  4. "test_password@" +
  5. "db_test/db_test",
  6. echo=True,
  7. poolclass=NullPool
  8. )
  9.  
  10.  
  11.  
  12. test_async_session = async_sessionmaker(
  13. autoflush=False,
  14. autocommit=False,
  15. bind=engine,
  16. class_=AsyncSession
  17. )
  18.  
  19.  
  20. @pytest_asyncio.fixture(scope="function")
  21. async def test_db():
  22. async with engine.begin() as conn:
  23. await conn.run_sync(Base.metadata.create_all)
  24.  
  25. async with test_async_session() as session:
  26. yield session
  27.  
  28. async with engine.begin() as conn:
  29. await conn.run_sync(Base.metadata.drop_all)
  30. await engine.dispose()
  31.  
  32.  
  33.  
  34. @pytest_asyncio.fixture
  35. async def user_in_db_fixture(
  36. db_user_fixture,
  37. test_db
  38. ):
  39. user_instance = User(**db_user_fixture)
  40. test_db.add(user_instance)
  41. await test_db.commit()
  42.  
  43.  
  44.  
  45.  
  46.  
  47. # tests
  48. @pytest.mark.asyncio
  49. async def test_signup_when_user_in_db(
  50. user_in_db_fixture,
  51. async_client_fixture,
  52. user_payload_correct_fixture
  53. ):
  54. response = await async_client_fixture.post(
  55. url='/auth/sign-up',
  56. json=user_payload_correct_fixture
  57. )
  58. assert response.status_code == 400
  59.  
Advertisement
Add Comment
Please, Sign In to add comment