Feat: add update and delete tribe to services
This commit is contained in:
parent
6eec1f83bb
commit
12b3220170
@ -11,7 +11,7 @@ class TribeDosNotExists(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def add_tribe(name: str, level: str, tribe_repo: AbstractRepository, conn):
|
||||
def add_tribe(name: str, level: str, tribe_repo: AbstractRepository, conn) -> Tribe:
|
||||
tribe = Tribe(name=name, level=level)
|
||||
try:
|
||||
tribe_repo.add(tribe)
|
||||
@ -21,7 +21,7 @@ def add_tribe(name: str, level: str, tribe_repo: AbstractRepository, conn):
|
||||
return tribe
|
||||
|
||||
|
||||
def update_tribe(name: str, level: str, tribe_repo: AbstractRepository, conn):
|
||||
def update_tribe(name: str, level: str, tribe_repo: AbstractRepository, conn) -> Tribe:
|
||||
tribe = Tribe(name=name, level=level)
|
||||
try:
|
||||
tribe_repo.update(name=name, tribe=tribe)
|
||||
@ -29,3 +29,12 @@ def update_tribe(name: str, level: str, tribe_repo: AbstractRepository, conn):
|
||||
raise TribeDosNotExists(f"The tribe {name} does not exists you can't update it")
|
||||
conn.commit()
|
||||
return tribe
|
||||
|
||||
|
||||
def delete_tribe(name: str, tribe_repo: AbstractRepository, conn) -> None:
|
||||
try:
|
||||
tribe_repo.delete(name=name)
|
||||
except TribeRepositoryError:
|
||||
raise TribeDosNotExists(f"The tribe {name} does not exists you can't delete it")
|
||||
|
||||
conn.commit()
|
||||
|
@ -40,7 +40,7 @@ class FakeTribeRepository(AbstractRepository):
|
||||
try:
|
||||
self._tribes.pop(name)
|
||||
except KeyError:
|
||||
raise KeyError(f"The tribe {tribe} does not exists")
|
||||
raise TribeRepositoryError(f"The tribe {name} does not exists")
|
||||
|
||||
|
||||
class FakeStudentRepository(AbstractRepository):
|
||||
@ -140,3 +140,26 @@ def test_update_tribe_fail_not_exists():
|
||||
)
|
||||
|
||||
assert conn.committed == False
|
||||
|
||||
|
||||
def test_delete_tribe():
|
||||
tribes = build_tribes(3)
|
||||
tribe_repo = FakeTribeRepository(tribes)
|
||||
conn = FakeConn()
|
||||
|
||||
tribe = tribes.pop()
|
||||
services.delete_tribe(name=tribe.name, tribe_repo=tribe_repo, conn=conn)
|
||||
|
||||
assert conn.committed == True
|
||||
assert set(tribe_repo.list()) == set(tribes)
|
||||
|
||||
|
||||
def test_delete_tribe_fail_not_exists():
|
||||
tribes = build_tribes(3)
|
||||
tribe_repo = FakeTribeRepository(tribes)
|
||||
conn = FakeConn()
|
||||
|
||||
with pytest.raises(TribeDosNotExists):
|
||||
services.delete_tribe(name="azerty", tribe_repo=tribe_repo, conn=conn)
|
||||
|
||||
assert conn.committed == False
|
||||
|
Loading…
Reference in New Issue
Block a user