mirror of
https://github.com/283375/arcaea-offline.git
synced 2025-07-01 20:26:27 +00:00
fix: adapt to new model and tests
- I actually forgot I wrote tests lol
This commit is contained in:
@ -10,11 +10,13 @@ Database model v5 common relationships
|
||||
└───────────┘
|
||||
"""
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from arcaea_offline.constants.enums import ArcaeaRatingClass
|
||||
from arcaea_offline.database.models import (
|
||||
ChartInfo,
|
||||
Difficulty,
|
||||
ModelsV5Base,
|
||||
ModelBase,
|
||||
Pack,
|
||||
PlayResult,
|
||||
Song,
|
||||
@ -24,7 +26,7 @@ from arcaea_offline.database.models import (
|
||||
class TestSongRelationships:
|
||||
@staticmethod
|
||||
def init_db(session):
|
||||
ModelsV5Base.metadata.create_all(session.bind)
|
||||
ModelBase.metadata.create_all(session.bind)
|
||||
|
||||
def test_relationships(self, db_session):
|
||||
self.init_db(db_session)
|
||||
@ -45,52 +47,56 @@ class TestSongRelationships:
|
||||
title=title_en,
|
||||
artist=artist_en,
|
||||
pack_id=pack.id,
|
||||
added_at=datetime(2024, 7, 5, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
difficulty_pst = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PAST,
|
||||
rating=2,
|
||||
rating_plus=False,
|
||||
is_rating_plus=False,
|
||||
)
|
||||
chart_info_pst = ChartInfo(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PAST,
|
||||
constant=20,
|
||||
notes=200,
|
||||
added_at=datetime(2024, 7, 12, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
difficulty_prs = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PRESENT,
|
||||
rating=7,
|
||||
rating_plus=True,
|
||||
is_rating_plus=True,
|
||||
)
|
||||
chart_info_prs = ChartInfo(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PRESENT,
|
||||
constant=78,
|
||||
notes=780,
|
||||
added_at=datetime(2024, 7, 12, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
difficulty_ftr = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.FUTURE,
|
||||
rating=10,
|
||||
rating_plus=True,
|
||||
is_rating_plus=True,
|
||||
)
|
||||
chart_info_ftr = ChartInfo(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.FUTURE,
|
||||
constant=109,
|
||||
notes=1090,
|
||||
added_at=datetime(2024, 7, 12, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
difficulty_etr = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.ETERNAL,
|
||||
rating=9,
|
||||
rating_plus=True,
|
||||
is_rating_plus=True,
|
||||
)
|
||||
|
||||
play_result_ftr = PlayResult(
|
||||
@ -124,20 +130,19 @@ class TestSongRelationships:
|
||||
difficulty_ftr,
|
||||
difficulty_etr,
|
||||
]
|
||||
assert song.charts_info == [chart_info_pst, chart_info_prs, chart_info_ftr]
|
||||
|
||||
assert difficulty_pst.song == song
|
||||
assert difficulty_prs.song == song
|
||||
assert difficulty_ftr.song == song
|
||||
assert difficulty_etr.song == song
|
||||
|
||||
assert difficulty_pst.chart_info == chart_info_pst
|
||||
assert difficulty_prs.chart_info == chart_info_prs
|
||||
assert difficulty_ftr.chart_info == chart_info_ftr
|
||||
assert difficulty_etr.chart_info is None
|
||||
assert difficulty_pst.chart_info_list == [chart_info_pst]
|
||||
assert difficulty_prs.chart_info_list == [chart_info_prs]
|
||||
assert difficulty_ftr.chart_info_list == [chart_info_ftr]
|
||||
assert difficulty_etr.chart_info_list == []
|
||||
|
||||
assert chart_info_pst.difficulty == difficulty_pst
|
||||
assert chart_info_prs.difficulty == difficulty_prs
|
||||
assert chart_info_ftr.difficulty == difficulty_ftr
|
||||
|
||||
assert play_result_ftr.difficulty == difficulty_ftr
|
||||
# assert play_result_ftr.difficulty == difficulty_ftr
|
||||
|
@ -5,13 +5,13 @@ Pack <> PackLocalized
|
||||
"""
|
||||
|
||||
from arcaea_offline.constants.enums import ArcaeaLanguage
|
||||
from arcaea_offline.database.models import ModelsV5Base, Pack, PackLocalized
|
||||
from arcaea_offline.database.models import ModelBase, Pack, PackLocalization
|
||||
|
||||
|
||||
class TestPackRelationships:
|
||||
@staticmethod
|
||||
def init_db(session):
|
||||
ModelsV5Base.metadata.create_all(session.bind)
|
||||
ModelBase.metadata.create_all(session.bind)
|
||||
|
||||
def test_localized_objects(self, db_session):
|
||||
self.init_db(db_session)
|
||||
@ -26,20 +26,16 @@ class TestPackRelationships:
|
||||
description=description_en,
|
||||
)
|
||||
|
||||
pkid_ja = 1
|
||||
description_ja = "普通のパートナー「∅」と一緒に、\n不人気フレームワーク「Arcaea Offline」より、\n一般的なデータベース・モデルを通過する。"
|
||||
pack_localized_ja = PackLocalized(
|
||||
pkid=pkid_ja,
|
||||
pack_localized_ja = PackLocalization(
|
||||
id=pack_id,
|
||||
lang=ArcaeaLanguage.JA.value,
|
||||
name=None,
|
||||
description=description_ja,
|
||||
)
|
||||
|
||||
pkid_zh_hans = 2
|
||||
description_zh_hans = "与平凡的「∅」一起,\n在没人用的「Arcaea Offline」框架里,\n一同探索随处可见的数据库模型。"
|
||||
pack_localized_zh_hans = PackLocalized(
|
||||
pkid=pkid_zh_hans,
|
||||
pack_localized_zh_hans = PackLocalization(
|
||||
id=pack_id,
|
||||
lang=ArcaeaLanguage.ZH_HANS.value,
|
||||
name=None,
|
||||
@ -49,11 +45,11 @@ class TestPackRelationships:
|
||||
db_session.add_all([pack, pack_localized_ja])
|
||||
db_session.commit()
|
||||
|
||||
assert len(pack.localized_objects) == len([pack_localized_ja])
|
||||
assert len(pack.localized_entries) == len([pack_localized_ja])
|
||||
|
||||
assert pack_localized_ja.parent.description == pack.description
|
||||
assert pack_localized_ja.pack.description == pack.description
|
||||
|
||||
# relationships should be viewonly
|
||||
# test back populates
|
||||
new_pack = Pack(
|
||||
id=f"{pack_id}_new",
|
||||
name="NEW",
|
||||
@ -61,9 +57,10 @@ class TestPackRelationships:
|
||||
)
|
||||
db_session.add(new_pack)
|
||||
|
||||
pack_localized_ja.parent = new_pack
|
||||
pack.localized_objects.append(pack_localized_zh_hans)
|
||||
pack_localized_ja.pack = new_pack
|
||||
pack.localized_entries.append(pack_localized_zh_hans)
|
||||
db_session.commit()
|
||||
|
||||
assert pack_localized_ja.parent == pack
|
||||
assert len(pack.localized_objects) == 1
|
||||
assert pack_localized_ja.pack.id == new_pack.id
|
||||
# TODO: this failes but why
|
||||
assert len(pack.localized_entries) == 2
|
||||
|
Reference in New Issue
Block a user