mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Tests for birthday commands, overwrite existing birthdays
This commit is contained in:
parent
f49f32d2e9
commit
adcf94c66e
9 changed files with 103 additions and 19 deletions
47
tests/test_database/test_crud/test_birthdays.py
Normal file
47
tests/test_database/test_crud/test_birthdays.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
from datetime import datetime, timedelta
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from database.crud import birthdays as crud
|
||||
from database.models import User
|
||||
|
||||
|
||||
async def test_add_birthday_not_present(database_session: AsyncSession, user: User):
|
||||
"""Test setting a user's birthday when it doesn't exist yet"""
|
||||
assert user.birthday is None
|
||||
|
||||
bd_date = datetime.today().date()
|
||||
await crud.add_birthday(database_session, user.user_id, bd_date)
|
||||
await database_session.refresh(user)
|
||||
assert user.birthday is not None
|
||||
assert user.birthday.birthday.date() == bd_date
|
||||
|
||||
|
||||
async def test_add_birthday_overwrite(database_session: AsyncSession, user: User):
|
||||
"""Test that setting a user's birthday when it already exists overwrites it"""
|
||||
bd_date = datetime.today().date()
|
||||
await crud.add_birthday(database_session, user.user_id, bd_date)
|
||||
await database_session.refresh(user)
|
||||
assert user.birthday is not None
|
||||
|
||||
new_bd_date = bd_date + timedelta(weeks=1)
|
||||
await crud.add_birthday(database_session, user.user_id, new_bd_date)
|
||||
await database_session.refresh(user)
|
||||
assert user.birthday.birthday.date() == new_bd_date
|
||||
|
||||
|
||||
async def test_get_birthday_exists(database_session: AsyncSession, user: User):
|
||||
"""Test getting a user's birthday when it exists"""
|
||||
bd_date = datetime.today().date()
|
||||
await crud.add_birthday(database_session, user.user_id, bd_date)
|
||||
await database_session.refresh(user)
|
||||
|
||||
bd = await crud.get_birthday_for_user(database_session, user.user_id)
|
||||
assert bd is not None
|
||||
assert bd.birthday.date() == bd_date
|
||||
|
||||
|
||||
async def test_get_birthday_not_exists(database_session: AsyncSession, user: User):
|
||||
"""Test getting a user's birthday when it doesn't exist"""
|
||||
bd = await crud.get_birthday_for_user(database_session, user.user_id)
|
||||
assert bd is None
|
||||
|
|
@ -6,16 +6,6 @@ from database.exceptions import currency as exceptions
|
|||
from database.models import Bank
|
||||
|
||||
|
||||
DEBUG_USER_ID = 1
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def bank(database_session: AsyncSession) -> Bank:
|
||||
_bank = await crud.get_bank(database_session, DEBUG_USER_ID)
|
||||
await database_session.refresh(_bank)
|
||||
return _bank
|
||||
|
||||
|
||||
async def test_add_dinks(database_session: AsyncSession, bank: Bank):
|
||||
"""Test adding dinks to an account"""
|
||||
assert bank.dinks == 0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import datetime
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from database.crud import ufora_announcements as crud
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue