recopytex/tests/integration/test_repository_tribe.py

74 lines
1.9 KiB
Python

from backend.model.tribe import Tribe
from backend.repository.tribe_sqlalchemy_repository import TribeSQLAlchemyRepository
def test_add_tribe(session):
tribe_infos = ("tribe1", "2nd")
tribe = Tribe(*tribe_infos)
tribe_repo = TribeSQLAlchemyRepository(session)
tribe_repo.add(tribe)
session.commit()
rows = list(session.execute("SELECT name, level FROM 'tribes'"))
assert rows == [tribe_infos]
def test_list_tribes(session):
session.execute(
"INSERT INTO tribes (name, level) VALUES "
"('tribe1', '2nd'),"
"('tribe2', '1ST')"
)
expected = [
(Tribe("tribe1", "2nd")),
(Tribe("tribe2", "1ST")),
]
tribe_repo = TribeSQLAlchemyRepository(session)
assert tribe_repo.list() == expected
def test_update_tribe(session):
session.execute(
"INSERT INTO tribes (name, level) VALUES "
"('tribe1', '2nd'),"
"('tribe2', '1ST')"
)
tribe_repo = TribeSQLAlchemyRepository(session)
tribe_repo.update("tribe1", Tribe("tribe3", "Term"))
session.commit()
expected = [
(Tribe("tribe3", "Term")),
(Tribe("tribe2", "1ST")),
]
assert tribe_repo.list() == expected
def test_get_tribes(session):
session.execute(
"INSERT INTO tribes (name, level) VALUES "
"('tribe1', '2nd'),"
"('tribe2', '1ST')"
)
expected = Tribe("tribe1", "2nd")
tribe_repo = TribeSQLAlchemyRepository(session)
assert tribe_repo.get("tribe1") == expected
def test_delete_tribes(session):
session.execute(
"INSERT INTO tribes (name, level) VALUES "
"('tribe1', '2nd'),"
"('tribe2', '1ST')"
)
expected = [
(Tribe("tribe2", "1ST")),
]
tribe_repo = TribeSQLAlchemyRepository(session)
tribe_repo.delete(Tribe("tribe1", "2nd"))
session.commit()
assert tribe_repo.list() == expected