Feat: add add tribe
This commit is contained in:
parent
fe92433311
commit
f73ad3a34d
@ -6,8 +6,8 @@ def create_tribe_table(conn) -> None:
|
||||
cursor.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS tribes(
|
||||
name TEXT PRIMARY KEY UNIQUE,
|
||||
level TEXT
|
||||
name VARCHAR PRIMARY KEY UNIQUE,
|
||||
level VARCHAR
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
@ -7,7 +7,16 @@ class TribeSQLiteRepository(AbstractRepository):
|
||||
self.conn = conn
|
||||
|
||||
def add(self, tribe: Tribe) -> None:
|
||||
pass
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
INSERT INTO tribes(name, level) VALUES (?, ?)
|
||||
""",
|
||||
(
|
||||
tribe.name,
|
||||
tribe.level,
|
||||
),
|
||||
)
|
||||
|
||||
def update(self, name: str, tribe: Tribe) -> None:
|
||||
pass
|
||||
|
@ -1,3 +1,5 @@
|
||||
import sqlite3
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.adapters.sqlite import create_db
|
||||
@ -50,3 +52,37 @@ def test_list_tribes(sqlite_conn):
|
||||
tribes = tribe_repo.list()
|
||||
|
||||
assert prebuild_tribes == tribes
|
||||
|
||||
|
||||
def test_add_tribe(sqlite_conn):
|
||||
create_db(sqlite_conn)
|
||||
|
||||
tribe_repo = TribeSQLiteRepository(sqlite_conn)
|
||||
|
||||
tribe_infos = ("tribe1", "2nd")
|
||||
tribe = Tribe(*tribe_infos)
|
||||
tribe_repo.add(tribe)
|
||||
sqlite_conn.commit()
|
||||
|
||||
cursor = sqlite_conn.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT * FROM tribes WHERE name=?
|
||||
""",
|
||||
("tribe1",),
|
||||
)
|
||||
|
||||
row = cursor.fetchone()
|
||||
assert row == tribe_infos
|
||||
|
||||
|
||||
def test_add_tribe_fail_exists(sqlite_conn):
|
||||
create_db(sqlite_conn)
|
||||
prebuild_tribes = populate_tribe(sqlite_conn)
|
||||
|
||||
tribe_repo = TribeSQLiteRepository(sqlite_conn)
|
||||
|
||||
tribe_infos = ("Tribe1", "2nd")
|
||||
tribe = Tribe(*tribe_infos)
|
||||
with pytest.raises(sqlite3.IntegrityError):
|
||||
tribe_repo.add(tribe)
|
||||
|
Loading…
Reference in New Issue
Block a user