Fix broken migration

pull/125/head
stijndcl 2022-07-23 20:59:02 +02:00
parent 8bc0f1fa7a
commit 66997b7556
6 changed files with 17 additions and 7 deletions

View File

@ -32,4 +32,5 @@ def upgrade() -> None:
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("tasks")
sa.Enum("BIRTHDAYS", "UFORA_ANNOUNCEMENTS", name="tasktype").drop(op.get_bind())
# ### end Alembic commands ###

View File

@ -1,4 +1,4 @@
from datetime import datetime
from datetime import date
from typing import Union
from sqlalchemy.ext.asyncio import AsyncSession
@ -69,9 +69,9 @@ async def claim_nightly(session: AsyncSession, user_id: int):
"""Claim daily Dinks"""
nightly_data = await get_nightly_data(session, user_id)
now = datetime.now()
now = date.today()
if nightly_data.last_nightly is not None and nightly_data.last_nightly == now.date():
if nightly_data.last_nightly is not None and nightly_data.last_nightly == now:
raise exceptions.DoubleNightly
bank = await get_bank(session, user_id)

View File

@ -1,5 +1,6 @@
black==22.3.0
coverage[toml]==6.4.1
freezegun==1.2.1
mypy==0.961
pre-commit==2.20.0
pytest==7.1.2

View File

@ -23,7 +23,7 @@ def event_loop() -> Generator:
@pytest.fixture(scope="session")
async def tables():
"""Initialize a database before the tests, and then tear it down again
"""Fixture to initialize a database before the tests, and then tear it down again
Checks that the migrations were successful by asserting that we are currently
on the latest migration

View File

@ -14,7 +14,7 @@ async def test_add_birthday_not_present(database_session: AsyncSession, user: Us
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
assert user.birthday.birthday == bd_date
async def test_add_birthday_overwrite(database_session: AsyncSession, user: User):
@ -27,7 +27,7 @@ async def test_add_birthday_overwrite(database_session: AsyncSession, user: User
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
assert user.birthday.birthday == new_bd_date
async def test_get_birthday_exists(database_session: AsyncSession, user: User):
@ -38,7 +38,7 @@ async def test_get_birthday_exists(database_session: AsyncSession, user: User):
bd = await crud.get_birthday_for_user(database_session, user.user_id)
assert bd is not None
assert bd.birthday.date() == bd_date
assert bd.birthday == bd_date
async def test_get_birthday_not_exists(database_session: AsyncSession, user: User):

View File

@ -1,4 +1,7 @@
import datetime
import pytest
from freezegun import freeze_time
from sqlalchemy.ext.asyncio import AsyncSession
from database.crud import currency as crud
@ -14,13 +17,18 @@ async def test_add_dinks(database_session: AsyncSession, bank: Bank):
assert bank.dinks == 10
@freeze_time("2022/07/23")
async def test_claim_nightly_available(database_session: AsyncSession, bank: Bank):
"""Test claiming nightlies when it hasn't been done yet"""
await crud.claim_nightly(database_session, bank.user_id)
await database_session.refresh(bank)
assert bank.dinks == crud.NIGHTLY_AMOUNT
nightly_data = await crud.get_nightly_data(database_session, bank.user_id)
assert nightly_data.last_nightly == datetime.date(year=2022, month=7, day=23)
@freeze_time("2022/07/23")
async def test_claim_nightly_unavailable(database_session: AsyncSession, bank: Bank):
"""Test claiming nightlies twice in a day"""
await crud.claim_nightly(database_session, bank.user_id)