Feat: using service does not require to know about domain

This commit is contained in:
Bertrand Benjamin 2022-12-30 07:27:27 +01:00
parent b8a769b96d
commit a95ce91b29
2 changed files with 11 additions and 4 deletions

View File

@ -7,7 +7,8 @@ class TribeExists(Exception):
pass
def add_tribe(tribe: Tribe, tribe_repo: AbstractRepository, conn):
def add_tribe(name: str, level: str, tribe_repo: AbstractRepository, conn):
tribe = Tribe(name=name, level=level)
try:
tribe_repo.add(tribe)
except TribeRepositoryError:

View File

@ -89,7 +89,9 @@ def test_add_tribe():
tribe_repo = FakeTribeRepository()
tribe = build_tribes(1)[0]
conn = FakeConn()
services.add_tribe(tribe, tribe_repo, conn)
services.add_tribe(
name=tribe.name, level=tribe.level, tribe_repo=tribe_repo, conn=conn
)
assert conn.committed == True
assert tribe_repo.list() == [tribe]
@ -99,10 +101,14 @@ def test_add_tribe_fail_exists():
tribe_repo = FakeTribeRepository()
tribe = build_tribes(1)[0]
conn = FakeConn()
services.add_tribe(tribe, tribe_repo, conn)
services.add_tribe(
name=tribe.name, level=tribe.level, tribe_repo=tribe_repo, conn=conn
)
conn.reset_commit()
with pytest.raises(TribeExists):
services.add_tribe(tribe, tribe_repo, conn)
services.add_tribe(
name=tribe.name, level=tribe.level, tribe_repo=tribe_repo, conn=conn
)
assert conn.committed == False