Feat: add get_tribe for sqlite
This commit is contained in:
parent
6fbe238e59
commit
fe92433311
@ -13,7 +13,19 @@ class TribeSQLiteRepository(AbstractRepository):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def get(self, name: str) -> Tribe:
|
def get(self, name: str) -> Tribe:
|
||||||
pass
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
SELECT * FROM tribes WHERE name=?
|
||||||
|
""",
|
||||||
|
(name,),
|
||||||
|
)
|
||||||
|
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if row:
|
||||||
|
return Tribe(*row)
|
||||||
|
|
||||||
|
raise ValueError(f"The tribe {name} does not exists")
|
||||||
|
|
||||||
def list(self) -> list[Tribe]:
|
def list(self) -> list[Tribe]:
|
||||||
cursor = self.conn.cursor()
|
cursor = self.conn.cursor()
|
||||||
@ -22,6 +34,7 @@ class TribeSQLiteRepository(AbstractRepository):
|
|||||||
SELECT * FROM tribes
|
SELECT * FROM tribes
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
return [Tribe(*r) for r in rows]
|
return [Tribe(*r) for r in rows]
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
from backend.adapters.sqlite import create_db
|
from backend.adapters.sqlite import create_db
|
||||||
from backend.model.tribe import Tribe
|
from backend.model.tribe import Tribe
|
||||||
from backend.repository.tribe_sqlite_repository import TribeSQLiteRepository
|
from backend.repository.tribe_sqlite_repository import TribeSQLiteRepository
|
||||||
|
|
||||||
|
|
||||||
def populate_tribe(conn) -> None:
|
def populate_tribe(conn) -> list[Tribe]:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
tribes = [
|
tribes = [
|
||||||
("Tribe1", "2nd"),
|
("Tribe1", "2nd"),
|
||||||
@ -21,6 +23,25 @@ def populate_tribe(conn) -> None:
|
|||||||
return [Tribe(*t) for t in tribes]
|
return [Tribe(*t) for t in tribes]
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_tribe(sqlite_conn):
|
||||||
|
create_db(sqlite_conn)
|
||||||
|
prebuild_tribes = populate_tribe(sqlite_conn)
|
||||||
|
|
||||||
|
tribe_repo = TribeSQLiteRepository(sqlite_conn)
|
||||||
|
tribes = tribe_repo.get("Tribe1")
|
||||||
|
|
||||||
|
assert prebuild_tribes[0] == tribes
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_tribe_not_exists(sqlite_conn):
|
||||||
|
create_db(sqlite_conn)
|
||||||
|
prebuild_tribes = populate_tribe(sqlite_conn)
|
||||||
|
|
||||||
|
tribe_repo = TribeSQLiteRepository(sqlite_conn)
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
tribe_repo.get("Tribe0")
|
||||||
|
|
||||||
|
|
||||||
def test_list_tribes(sqlite_conn):
|
def test_list_tribes(sqlite_conn):
|
||||||
create_db(sqlite_conn)
|
create_db(sqlite_conn)
|
||||||
prebuild_tribes = populate_tribe(sqlite_conn)
|
prebuild_tribes = populate_tribe(sqlite_conn)
|
||||||
|
Loading…
Reference in New Issue
Block a user