Feat: add sad path test and exceptions for update and delete

This commit is contained in:
2022-12-30 07:45:26 +01:00
parent 36e90a004e
commit 6eec1f83bb
2 changed files with 27 additions and 4 deletions

View File

@@ -28,6 +28,13 @@ class TribeSQLiteRepository(AbstractRepository):
)
def update(self, name: str, tribe: Tribe) -> None:
tribes = self.list()
if name not in map(lambda x: x.name, tribes):
raise TribeRepositoryError(
f"The tribe {name} doesn't exists. Can't update it"
)
self.conn.execute(
"""
UPDATE tribes SET name=:newname, level=:newlevel WHERE name=:name
@@ -66,6 +73,12 @@ class TribeSQLiteRepository(AbstractRepository):
return [Tribe(*r) for r in rows]
def delete(self, tribe: Tribe) -> None:
tribes = self.list()
if tribe.name not in map(lambda x: x.name, tribes):
raise TribeRepositoryError(
f"The tribe {tribe.name} doesn't exists. Can't delete it."
)
self.conn.execute(
"""
DELETE FROM tribes WHERE name=:name