Feat: Add FakeTribeRepository

This commit is contained in:
Bertrand Benjamin 2022-12-26 07:03:52 +01:00
parent 5735d344c5
commit 6f486a6f3c
2 changed files with 35 additions and 2 deletions

View File

@ -7,7 +7,7 @@ class AbstractRepository(abc.ABC):
raise NotImplementedError
@abc.abstractmethod
def update(self, element):
def update(self, reference, element):
raise NotImplementedError
@abc.abstractmethod
@ -19,5 +19,5 @@ class AbstractRepository(abc.ABC):
raise NotImplementedError
@abc.abstractmethod
def delete(self, reference):
def delete(self, element):
raise NotImplementedError

View File

@ -4,6 +4,7 @@ from faker import Faker
from backend.model.assessment import Assessment, Domain, Exercise, Question, Skill
from backend.model.tribe import Tribe
from backend.repository.abstract_repository import AbstractRepository
faker = Faker()
@ -66,3 +67,35 @@ def build_questions(
]
return questions
class FakeTribeRepository(AbstractRepository):
def __init__(self, tribes):
self._tribes = {t.name: t for t in tribes}
def add(self, tribe):
if tribe.name not in self._tribes.keys():
self._tribes[tribe.name] = tribe
raise KeyError(f"{tribe} already exists")
def update(self, name, tribe):
try:
self._tribes.pop(name)
self._tribes[tribe.name] = tribe
except KeyError:
raise KeyError(f"The tribe {tribe} does not exists")
def list(self):
return list(self._tribes.values())
def get(self, name):
try:
return self._tribes[name]
except KeyError:
raise KeyError(f"The tribe {tribe} does not exists")
def delete(self, name):
try:
self._tribes.pop(name)
except KeyError:
raise KeyError(f"The tribe {tribe} does not exists")