From 6f486a6f3c5b8c3582c0668c82ad7533ad332d67 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Mon, 26 Dec 2022 07:03:52 +0100 Subject: [PATCH] Feat: Add FakeTribeRepository --- backend/repository/abstract_repository.py | 4 +-- tests/model/fakes.py | 33 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/backend/repository/abstract_repository.py b/backend/repository/abstract_repository.py index 14f9651..003fcbc 100644 --- a/backend/repository/abstract_repository.py +++ b/backend/repository/abstract_repository.py @@ -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 diff --git a/tests/model/fakes.py b/tests/model/fakes.py index a8e2d92..314b883 100644 --- a/tests/model/fakes.py +++ b/tests/model/fakes.py @@ -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")