From b4df4d6c09546d35d34ae03ad6175adf5aeabf61 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Tue, 20 Dec 2022 10:37:55 +0100 Subject: [PATCH] Feat: Tribe equality on name and add tests --- backend/model/tribe.py | 2 +- tests/integration/test_orm.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/backend/model/tribe.py b/backend/model/tribe.py index b902b26..4b33183 100644 --- a/backend/model/tribe.py +++ b/backend/model/tribe.py @@ -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 diff --git a/tests/integration/test_orm.py b/tests/integration/test_orm.py index 2b57066..a137e8c 100644 --- a/tests/integration/test_orm.py +++ b/tests/integration/test_orm.py @@ -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]