didier/tests/test_database/test_crud/test_users.py

25 lines
742 B
Python
Raw Normal View History

2022-06-30 21:33:37 +02:00
from sqlalchemy import select
from database.crud import users as crud
2022-07-25 21:20:09 +02:00
from database.schemas.relational import User
2022-06-30 21:33:37 +02:00
2022-07-25 19:12:27 +02:00
async def test_get_or_add_non_existing(postgres):
2022-06-30 21:33:37 +02:00
"""Test get_or_add for a user that doesn't exist"""
2022-07-25 19:12:27 +02:00
await crud.get_or_add(postgres, 1)
2022-06-30 21:33:37 +02:00
statement = select(User)
2022-07-25 19:12:27 +02:00
res = (await postgres.execute(statement)).scalars().all()
2022-06-30 21:33:37 +02:00
assert len(res) == 1
assert res[0].bank is not None
assert res[0].nightly_data is not None
2022-07-25 19:12:27 +02:00
async def test_get_or_add_existing(postgres):
2022-06-30 21:33:37 +02:00
"""Test get_or_add for a user that does exist"""
2022-07-25 19:12:27 +02:00
user = await crud.get_or_add(postgres, 1)
2022-06-30 21:33:37 +02:00
bank = user.bank
2022-07-25 19:12:27 +02:00
assert await crud.get_or_add(postgres, 1) == user
assert (await crud.get_or_add(postgres, 1)).bank == bank