chore: tests

This commit is contained in:
283375 2024-05-20 00:19:16 +08:00
parent e295e58388
commit 5f2b66233b
Signed by: 283375
SSH Key Fingerprint: SHA256:UcX0qg6ZOSDOeieKPGokA5h7soykG61nz2uxuQgVLSk
2 changed files with 7 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import pytest import pytest
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.orm import Session, sessionmaker from sqlalchemy.orm import sessionmaker
# region sqlalchemy fixtures # region sqlalchemy fixtures
# from https://medium.com/@vittorio.camisa/agile-database-integration-tests-with-python-sqlalchemy-and-factory-boy-6824e8fe33a1 # from https://medium.com/@vittorio.camisa/agile-database-integration-tests-with-python-sqlalchemy-and-factory-boy-6824e8fe33a1

View File

@ -1,7 +1,7 @@
from typing import Optional from typing import Optional
from sqlalchemy import text from sqlalchemy import text
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
from arcaea_offline.constants.enums import ( from arcaea_offline.constants.enums import (
ArcaeaPlayResultClearType, ArcaeaPlayResultClearType,
@ -47,16 +47,16 @@ class ModifierTestModel(Base):
class TestCustomTypes: class TestCustomTypes:
def _common_test_method(self, db_session, obj: Base, value_in_db): def _common_test_method(self, session: Session, obj: Base, value_in_db):
""" """
This method stores the `obj` into the given `db_session`, This method stores the `obj` into the given `session`,
then fetches the raw value of `obj.value` from database, then fetches the raw value of `obj.value` from database,
and asserts that the value is equal to `value_in_db`. and asserts that the value is equal to `value_in_db`.
""" """
db_session.add(obj) session.add(obj)
db_session.commit() session.commit()
exec_result = db_session.execute( exec_result = session.execute(
text( text(
f"SELECT value FROM {obj.__tablename__} WHERE id = {obj.id}" # type: ignore f"SELECT value FROM {obj.__tablename__} WHERE id = {obj.id}" # type: ignore
) )