Feat: add sad path test and exceptions for update and delete
This commit is contained in:
parent
36e90a004e
commit
6eec1f83bb
@ -28,6 +28,13 @@ class TribeSQLiteRepository(AbstractRepository):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def update(self, name: str, tribe: Tribe) -> None:
|
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(
|
self.conn.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE tribes SET name=:newname, level=:newlevel WHERE name=:name
|
UPDATE tribes SET name=:newname, level=:newlevel WHERE name=:name
|
||||||
@ -66,6 +73,12 @@ class TribeSQLiteRepository(AbstractRepository):
|
|||||||
return [Tribe(*r) for r in rows]
|
return [Tribe(*r) for r in rows]
|
||||||
|
|
||||||
def delete(self, tribe: Tribe) -> None:
|
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(
|
self.conn.execute(
|
||||||
"""
|
"""
|
||||||
DELETE FROM tribes WHERE name=:name
|
DELETE FROM tribes WHERE name=:name
|
||||||
|
@ -96,12 +96,22 @@ def test_update_tribe(sqlite_conn):
|
|||||||
assert tribe_repo.list() == prebuild_tribes
|
assert tribe_repo.list() == prebuild_tribes
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_tribe_not_exists(sqlite_conn):
|
||||||
|
prebuild_tribes = populate_tribes(sqlite_conn)
|
||||||
|
|
||||||
|
tribe_repo = TribeSQLiteRepository(sqlite_conn)
|
||||||
|
|
||||||
|
name = prebuild_tribes[0].name
|
||||||
|
new_tribe = Tribe("Tribe0", "Term")
|
||||||
|
with pytest.raises(TribeRepositoryError):
|
||||||
|
tribe_repo.update("iouiou", new_tribe)
|
||||||
|
|
||||||
|
|
||||||
def test_delete_tribe(sqlite_conn):
|
def test_delete_tribe(sqlite_conn):
|
||||||
prebuild_tribes = populate_tribes(sqlite_conn)
|
prebuild_tribes = populate_tribes(sqlite_conn)
|
||||||
|
|
||||||
tribe_repo = TribeSQLiteRepository(sqlite_conn)
|
tribe_repo = TribeSQLiteRepository(sqlite_conn)
|
||||||
deleted_tribe = prebuild_tribes.pop()
|
deleted_tribe = prebuild_tribes.pop()
|
||||||
|
deleted_tribe.name = "iouiou"
|
||||||
|
with pytest.raises(TribeRepositoryError):
|
||||||
tribe_repo.delete(deleted_tribe)
|
tribe_repo.delete(deleted_tribe)
|
||||||
sqlite_conn.commit()
|
|
||||||
|
|
||||||
assert tribe_repo.list() == prebuild_tribes
|
|
||||||
|
Loading…
Reference in New Issue
Block a user