Feat: Add FakeTribeRepository
This commit is contained in:
parent
5735d344c5
commit
6f486a6f3c
@ -7,7 +7,7 @@ class AbstractRepository(abc.ABC):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def update(self, element):
|
def update(self, reference, element):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
@ -19,5 +19,5 @@ class AbstractRepository(abc.ABC):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def delete(self, reference):
|
def delete(self, element):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -4,6 +4,7 @@ from faker import Faker
|
|||||||
|
|
||||||
from backend.model.assessment import Assessment, Domain, Exercise, Question, Skill
|
from backend.model.assessment import Assessment, Domain, Exercise, Question, Skill
|
||||||
from backend.model.tribe import Tribe
|
from backend.model.tribe import Tribe
|
||||||
|
from backend.repository.abstract_repository import AbstractRepository
|
||||||
|
|
||||||
faker = Faker()
|
faker = Faker()
|
||||||
|
|
||||||
@ -66,3 +67,35 @@ def build_questions(
|
|||||||
]
|
]
|
||||||
|
|
||||||
return 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")
|
||||||
|
Loading…
Reference in New Issue
Block a user