2022-06-30 19:33:37 +00:00
|
|
|
from sqlalchemy import select
|
2022-07-27 19:10:43 +00:00
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
2022-06-30 19:33:37 +00:00
|
|
|
|
|
|
|
from database.crud import users as crud
|
2022-08-29 18:24:42 +00:00
|
|
|
from database.schemas import User
|
2022-06-30 19:33:37 +00:00
|
|
|
|
|
|
|
|
2022-07-27 19:10:43 +00:00
|
|
|
async def test_get_or_add_non_existing(postgres: AsyncSession):
|
2022-06-30 19:33:37 +00:00
|
|
|
"""Test get_or_add for a user that doesn't exist"""
|
2022-08-29 18:49:29 +00:00
|
|
|
await crud.get_or_add_user(postgres, 1)
|
2022-06-30 19:33:37 +00:00
|
|
|
statement = select(User)
|
2022-07-25 17:12:27 +00:00
|
|
|
res = (await postgres.execute(statement)).scalars().all()
|
2022-06-30 19:33:37 +00:00
|
|
|
|
|
|
|
assert len(res) == 1
|
|
|
|
assert res[0].bank is not None
|
|
|
|
assert res[0].nightly_data is not None
|
|
|
|
|
|
|
|
|
2022-07-27 19:10:43 +00:00
|
|
|
async def test_get_or_add_existing(postgres: AsyncSession):
|
2022-06-30 19:33:37 +00:00
|
|
|
"""Test get_or_add for a user that does exist"""
|
2022-08-29 18:49:29 +00:00
|
|
|
user = await crud.get_or_add_user(postgres, 1)
|
2022-06-30 19:33:37 +00:00
|
|
|
bank = user.bank
|
|
|
|
|
2022-08-29 18:49:29 +00:00
|
|
|
assert await crud.get_or_add_user(postgres, 1) == user
|
|
|
|
assert (await crud.get_or_add_user(postgres, 1)).bank == bank
|