Feat: Tribe equality on name and add tests

This commit is contained in:
Bertrand Benjamin 2022-12-20 10:37:55 +01:00
parent 723092c38f
commit b4df4d6c09
2 changed files with 28 additions and 1 deletions

View File

@ -23,5 +23,5 @@ class Tribe:
def __eq__(self, other: object) -> bool:
if isinstance(other, Tribe):
return self.name == other.name and self.level == other.level
return self.name == other.name
return False

View File

@ -13,3 +13,30 @@ def test_tribes_mapper_can_load_tribe(session):
(Tribe("tribe2", "1ST")),
]
assert session.query(Tribe).all() == expected
def test_tribe_mapper_can_save_tribe(session):
tribe_infos = ("tribe1", "2nd")
tribe = Tribe(*tribe_infos)
session.add(tribe)
rows = list(session.execute("SELECT name, level FROM 'tribes'"))
assert rows == []
session.commit()
rows = list(session.execute("SELECT name, level FROM 'tribes'"))
assert rows == [tribe_infos]
def test_tribe_mapper_can_save_and_load_tribe(session):
tribe_infos = ("tribe1", "2nd")
tribe = Tribe(*tribe_infos)
assert session.query(Tribe).all() == []
session.add(tribe)
assert session.query(Tribe).all() == [tribe]
session.commit()
assert session.query(Tribe).all() == [tribe]