feat: add update and delete for tribes
This commit is contained in:
parent
f73ad3a34d
commit
dfd0bb2b81
@ -7,8 +7,7 @@ class TribeSQLiteRepository(AbstractRepository):
|
||||
self.conn = conn
|
||||
|
||||
def add(self, tribe: Tribe) -> None:
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute(
|
||||
self.conn.execute(
|
||||
"""
|
||||
INSERT INTO tribes(name, level) VALUES (?, ?)
|
||||
""",
|
||||
@ -19,7 +18,16 @@ class TribeSQLiteRepository(AbstractRepository):
|
||||
)
|
||||
|
||||
def update(self, name: str, tribe: Tribe) -> None:
|
||||
pass
|
||||
self.conn.execute(
|
||||
"""
|
||||
UPDATE tribes SET name=:newname, level=:newlevel WHERE name=:name
|
||||
""",
|
||||
{
|
||||
"newname": tribe.name,
|
||||
"newlevel": tribe.level,
|
||||
"name": name,
|
||||
},
|
||||
)
|
||||
|
||||
def get(self, name: str) -> Tribe:
|
||||
cursor = self.conn.cursor()
|
||||
@ -48,4 +56,11 @@ class TribeSQLiteRepository(AbstractRepository):
|
||||
return [Tribe(*r) for r in rows]
|
||||
|
||||
def delete(self, tribe: Tribe) -> None:
|
||||
pass
|
||||
self.conn.execute(
|
||||
"""
|
||||
DELETE FROM tribes WHERE name=:name
|
||||
""",
|
||||
{
|
||||
"name": tribe.name,
|
||||
},
|
||||
)
|
||||
|
@ -86,3 +86,34 @@ def test_add_tribe_fail_exists(sqlite_conn):
|
||||
tribe = Tribe(*tribe_infos)
|
||||
with pytest.raises(sqlite3.IntegrityError):
|
||||
tribe_repo.add(tribe)
|
||||
|
||||
|
||||
def test_update_tribe(sqlite_conn):
|
||||
create_db(sqlite_conn)
|
||||
prebuild_tribes = populate_tribe(sqlite_conn)
|
||||
|
||||
tribe_repo = TribeSQLiteRepository(sqlite_conn)
|
||||
tribe_repo.update("Tribe1", Tribe("Tribe0", "Term"))
|
||||
sqlite_conn.commit()
|
||||
|
||||
expected = [
|
||||
Tribe("Tribe0", "Term"),
|
||||
Tribe("Tribe2", "2nd"),
|
||||
Tribe("Tribe3", "1ST"),
|
||||
]
|
||||
assert tribe_repo.list() == expected
|
||||
|
||||
|
||||
def test_delete_tribe(sqlite_conn):
|
||||
create_db(sqlite_conn)
|
||||
prebuild_tribes = populate_tribe(sqlite_conn)
|
||||
|
||||
tribe_repo = TribeSQLiteRepository(sqlite_conn)
|
||||
tribe_repo.delete(prebuild_tribes[0])
|
||||
sqlite_conn.commit()
|
||||
|
||||
expected = [
|
||||
Tribe("Tribe2", "2nd"),
|
||||
Tribe("Tribe3", "1ST"),
|
||||
]
|
||||
assert tribe_repo.list() == expected
|
||||
|
Loading…
Reference in New Issue
Block a user