mirror of
https://github.com/283375/arcaea-offline.git
synced 2025-06-30 19:56:26 +00:00
67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
"""
|
||
Database model v5 relationships
|
||
|
||
Pack <> PackLocalized
|
||
"""
|
||
|
||
from arcaea_offline.constants.enums import ArcaeaLanguage
|
||
from arcaea_offline.database.models import ModelBase, Pack, PackLocalization
|
||
|
||
|
||
class TestPackRelationships:
|
||
@staticmethod
|
||
def init_db(session):
|
||
ModelBase.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,
|
||
)
|
||
|
||
description_ja = "普通のパートナー「∅」と一緒に、\n不人気フレームワーク「Arcaea Offline」より、\n一般的なデータベース・モデルを通過する。"
|
||
pack_localized_ja = PackLocalization(
|
||
id=pack_id,
|
||
lang=ArcaeaLanguage.JA.value,
|
||
name=None,
|
||
description=description_ja,
|
||
)
|
||
|
||
description_zh_hans = "与平凡的「∅」一起,\n在没人用的「Arcaea Offline」框架里,\n一同探索随处可见的数据库模型。"
|
||
pack_localized_zh_hans = PackLocalization(
|
||
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_entries) == len([pack_localized_ja])
|
||
|
||
assert pack_localized_ja.pack.description == pack.description
|
||
|
||
# test back populates
|
||
new_pack = Pack(
|
||
id=f"{pack_id}_new",
|
||
name="NEW",
|
||
description="new new pack",
|
||
)
|
||
db_session.add(new_pack)
|
||
|
||
pack_localized_ja.pack = new_pack
|
||
pack.localized_entries.append(pack_localized_zh_hans)
|
||
db_session.commit()
|
||
|
||
assert pack_localized_ja.pack.id == new_pack.id
|
||
# TODO: this failes but why
|
||
assert len(pack.localized_entries) == 2
|