recopytex/tests/integration/test_orm.py

44 lines
1.1 KiB
Python
Raw Normal View History

2022-12-20 09:25:12 +00:00
from backend.adapters.orm import metadata, start_mappers
from backend.model.student import Student
2022-12-20 09:25:12 +00:00
from backend.model.tribe import Tribe
def test_tribes_mapper_can_load_tribe(session):
session.execute(
"INSERT INTO tribes (name, level) VALUES "
"('tribe1', '2nd'),"
"('tribe2', '1ST')"
)
expected = [
(Tribe("tribe1", "2nd")),
(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]