mirror of
https://github.com/283375/arcaea-offline.git
synced 2025-07-01 12:16:26 +00:00
wip: v5 database models and tests
This commit is contained in:
0
tests/db/models/v5/__init__.py
Normal file
0
tests/db/models/v5/__init__.py
Normal file
0
tests/db/models/v5/relationships/__init__.py
Normal file
0
tests/db/models/v5/relationships/__init__.py
Normal file
143
tests/db/models/v5/relationships/test_common.py
Normal file
143
tests/db/models/v5/relationships/test_common.py
Normal file
@ -0,0 +1,143 @@
|
||||
"""
|
||||
Database model v5 common relationships
|
||||
|
||||
┌──────┐ ┌──────┐ ┌────────────┐ ┌────────────┐
|
||||
│ Pack ◄───► Song ◄───► Difficulty ◄───┤ PlayResult │
|
||||
└──────┘ └──┬───┘ └─────▲──────┘ └────────────┘
|
||||
│ │
|
||||
│ ┌─────▼─────┐
|
||||
└───────► ChartInfo │
|
||||
└───────────┘
|
||||
"""
|
||||
|
||||
from arcaea_offline.constants.enums import ArcaeaRatingClass
|
||||
from arcaea_offline.database.models.v5 import (
|
||||
ChartInfo,
|
||||
Difficulty,
|
||||
ModelsV5Base,
|
||||
Pack,
|
||||
PlayResult,
|
||||
Song,
|
||||
)
|
||||
|
||||
|
||||
class TestSongRelationships:
|
||||
@staticmethod
|
||||
def init_db(session):
|
||||
ModelsV5Base.metadata.create_all(session.bind)
|
||||
|
||||
def test_relationships(self, db_session):
|
||||
self.init_db(db_session)
|
||||
|
||||
song_id = "test_song"
|
||||
title_en = "Test Lorem Ipsum"
|
||||
artist_en = "Test Artist"
|
||||
|
||||
pack = Pack(
|
||||
id="test_pack",
|
||||
name="Test Pack",
|
||||
description="This is a test pack.",
|
||||
)
|
||||
|
||||
song = Song(
|
||||
idx=1,
|
||||
id=song_id,
|
||||
title=title_en,
|
||||
artist=artist_en,
|
||||
pack_id=pack.id,
|
||||
)
|
||||
|
||||
difficulty_pst = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PAST,
|
||||
rating=2,
|
||||
rating_plus=False,
|
||||
)
|
||||
chart_info_pst = ChartInfo(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PAST,
|
||||
constant=20,
|
||||
notes=200,
|
||||
)
|
||||
|
||||
difficulty_prs = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PRESENT,
|
||||
rating=7,
|
||||
rating_plus=True,
|
||||
)
|
||||
chart_info_prs = ChartInfo(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.PRESENT,
|
||||
constant=78,
|
||||
notes=780,
|
||||
)
|
||||
|
||||
difficulty_ftr = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.FUTURE,
|
||||
rating=10,
|
||||
rating_plus=True,
|
||||
)
|
||||
chart_info_ftr = ChartInfo(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.FUTURE,
|
||||
constant=109,
|
||||
notes=1090,
|
||||
)
|
||||
|
||||
difficulty_etr = Difficulty(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.ETERNAL,
|
||||
rating=9,
|
||||
rating_plus=True,
|
||||
)
|
||||
|
||||
play_result_ftr = PlayResult(
|
||||
song_id=song.id,
|
||||
rating_class=ArcaeaRatingClass.FUTURE,
|
||||
score=123456,
|
||||
)
|
||||
|
||||
db_session.add_all(
|
||||
[
|
||||
pack,
|
||||
song,
|
||||
difficulty_pst,
|
||||
chart_info_pst,
|
||||
difficulty_prs,
|
||||
chart_info_prs,
|
||||
difficulty_ftr,
|
||||
chart_info_ftr,
|
||||
difficulty_etr,
|
||||
play_result_ftr,
|
||||
]
|
||||
)
|
||||
db_session.commit()
|
||||
|
||||
assert pack.songs == [song]
|
||||
|
||||
assert song.pack == pack
|
||||
assert song.difficulties == [
|
||||
difficulty_pst,
|
||||
difficulty_prs,
|
||||
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 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
|
69
tests/db/models/v5/relationships/test_pack.py
Normal file
69
tests/db/models/v5/relationships/test_pack.py
Normal file
@ -0,0 +1,69 @@
|
||||
"""
|
||||
Database model v5 relationships
|
||||
|
||||
Pack <> PackLocalized
|
||||
"""
|
||||
|
||||
from arcaea_offline.constants.enums import ArcaeaLanguage
|
||||
from arcaea_offline.database.models.v5 import ModelsV5Base, Pack, PackLocalized
|
||||
|
||||
|
||||
class TestPackRelationships:
|
||||
@staticmethod
|
||||
def init_db(session):
|
||||
ModelsV5Base.metadata.create_all(session.bind)
|
||||
|
||||
def test_localized_objects(self, db_session):
|
||||
self.init_db(db_session)
|
||||
|
||||
pack_id = "test_pack"
|
||||
name_en = "Test Pack"
|
||||
description_en = "Travel through common database models\nfrom the unpopular framework 'Arcaea Offline'\ntogether with an ordinary partner '∅'."
|
||||
|
||||
pack = Pack(
|
||||
id=pack_id,
|
||||
name=name_en,
|
||||
description=description_en,
|
||||
)
|
||||
|
||||
pkid_ja = 1
|
||||
description_ja = "普通のパートナー「∅」と一緒に、\n不人気フレームワーク「Arcaea Offline」より、\n一般的なデータベース・モデルを通過する。"
|
||||
pack_localized_ja = PackLocalized(
|
||||
pkid=pkid_ja,
|
||||
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,
|
||||
id=pack_id,
|
||||
lang=ArcaeaLanguage.ZH_HANS.value,
|
||||
name=None,
|
||||
description=description_zh_hans,
|
||||
)
|
||||
|
||||
db_session.add_all([pack, pack_localized_ja])
|
||||
db_session.commit()
|
||||
|
||||
assert len(pack.localized_objects) == len([pack_localized_ja])
|
||||
|
||||
assert pack_localized_ja.parent.description == pack.description
|
||||
|
||||
# relationships should be viewonly
|
||||
new_pack = Pack(
|
||||
id=f"{pack_id}_new",
|
||||
name="NEW",
|
||||
description="new new pack",
|
||||
)
|
||||
db_session.add(new_pack)
|
||||
|
||||
pack_localized_ja.parent = new_pack
|
||||
pack.localized_objects.append(pack_localized_zh_hans)
|
||||
db_session.commit()
|
||||
|
||||
assert pack_localized_ja.parent == pack
|
||||
assert len(pack.localized_objects) == 1
|
110
tests/db/models/v5/test_chart.py
Normal file
110
tests/db/models/v5/test_chart.py
Normal file
@ -0,0 +1,110 @@
|
||||
"""
|
||||
Database models v5
|
||||
|
||||
Chart functionalities
|
||||
- basic data handling
|
||||
- Difficulty song info overriding
|
||||
"""
|
||||
|
||||
from arcaea_offline.constants.enums.arcaea import ArcaeaRatingClass
|
||||
from arcaea_offline.database.models.v5 import (
|
||||
Chart,
|
||||
ChartInfo,
|
||||
Difficulty,
|
||||
ModelsV5Base,
|
||||
ModelsV5ViewBase,
|
||||
Pack,
|
||||
Song,
|
||||
)
|
||||
|
||||
|
||||
class TestChart:
|
||||
def init_db(self, session):
|
||||
ModelsV5Base.metadata.create_all(session.bind)
|
||||
ModelsV5ViewBase.metadata.create_all(session.bind)
|
||||
|
||||
def test_basic(self, db_session):
|
||||
self.init_db(db_session)
|
||||
|
||||
pack_id = "test_pack"
|
||||
song_id = "test_song"
|
||||
rating_class = ArcaeaRatingClass.FUTURE
|
||||
|
||||
pack = Pack(id=pack_id, name="Test Pack")
|
||||
song = Song(
|
||||
idx=2,
|
||||
id=song_id,
|
||||
title="~TEST~",
|
||||
artist="~test~",
|
||||
pack_id=pack_id,
|
||||
)
|
||||
difficulty = Difficulty(
|
||||
song_id=song_id,
|
||||
rating_class=rating_class,
|
||||
rating=9,
|
||||
rating_plus=True,
|
||||
)
|
||||
chart_info = ChartInfo(
|
||||
song_id=song_id,
|
||||
rating_class=rating_class,
|
||||
constant=98,
|
||||
notes=980,
|
||||
)
|
||||
db_session.add_all([pack, song, difficulty, chart_info])
|
||||
|
||||
chart: Chart = (
|
||||
db_session.query(Chart)
|
||||
.where((Chart.song_id == song_id) & (Chart.rating_class == rating_class))
|
||||
.one()
|
||||
)
|
||||
|
||||
# `song_id` and `rating_class` are guarded by the WHERE clause above
|
||||
assert chart.song_idx == song.idx
|
||||
assert chart.title == song.title
|
||||
assert chart.artist == song.artist
|
||||
assert chart.pack_id == song.pack_id
|
||||
assert chart.rating == difficulty.rating
|
||||
assert chart.rating_plus == difficulty.rating_plus
|
||||
assert chart.constant == chart_info.constant
|
||||
assert chart.notes == chart_info.notes
|
||||
|
||||
def test_difficulty_override(self, db_session):
|
||||
self.init_db(db_session)
|
||||
|
||||
pack_id = "test_pack"
|
||||
song_id = "test_song"
|
||||
rating_class = ArcaeaRatingClass.FUTURE
|
||||
|
||||
pack = Pack(id=pack_id, name="Test Pack")
|
||||
song = Song(
|
||||
idx=2,
|
||||
id=song_id,
|
||||
title="~TEST~",
|
||||
artist="~test~",
|
||||
pack_id=pack_id,
|
||||
)
|
||||
difficulty = Difficulty(
|
||||
song_id=song_id,
|
||||
rating_class=rating_class,
|
||||
rating=9,
|
||||
rating_plus=True,
|
||||
title="~TEST DIFF~",
|
||||
artist="~diff~",
|
||||
)
|
||||
chart_info = ChartInfo(
|
||||
song_id=song_id,
|
||||
rating_class=rating_class,
|
||||
constant=98,
|
||||
notes=980,
|
||||
)
|
||||
db_session.add_all([pack, song, difficulty, chart_info])
|
||||
|
||||
chart: Chart = (
|
||||
db_session.query(Chart)
|
||||
.where((Chart.song_id == song_id) & (Chart.rating_class == rating_class))
|
||||
.one()
|
||||
)
|
||||
|
||||
assert chart.song_idx == song.idx
|
||||
assert chart.title == difficulty.title
|
||||
assert chart.artist == difficulty.artist
|
Reference in New Issue
Block a user