Add the support helpers to use fake data for tests.

This commit is contained in:
2025-01-24 21:32:40 +02:00
parent 18eb9b4d91
commit 7094a0d866
5 changed files with 102 additions and 1 deletions
+4
View File
@@ -0,0 +1,4 @@
from .fake_factories import FakeFactories
from .data_seeds import DataSeeds
__all__ = ['FakeFactories', 'DataSeeds']
+19
View File
@@ -0,0 +1,19 @@
from injector import Injector
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
from . import FakeFactories
class DataSeeds:
def __init__(self, configuration: Injector):
self.fake_factories = FakeFactories()
self.configuration = configuration
def create_backup_plan(self, uuid: str | None = None):
service = self.configuration.get(BackupPlanService)
backup_plan = self.fake_factories.backup_plan(uuid)
service.add(backup_plan)
return backup_plan
def seeds(self, context):
context.backup_plan_seed = self.create_backup_plan()
+34
View File
@@ -0,0 +1,34 @@
from faker import Faker
from tui_rsync.core.components.backup_plan.domain import BackupPlan, Path, BackupPlanId, Source, Destination
from tui_rsync.core.shared_kernel.components.common import UUID, Label
class FakeFactories:
def __init__(self):
self.faker = Faker()
def uuid(self):
return UUID(self.faker.uuid4())
def backup_plan_id(self):
return BackupPlanId(self.uuid().id)
def label(self) -> Label:
return Label(self.faker.sentence(nb_words=4))
def path(self) -> Path:
return Path(self.faker.file_path())
def source(self) -> Source:
return Source(self.path().path)
def destination(self) -> Destination:
return Destination(self.path().path)
def backup_plan(self, uuid: str | None = None):
uuid = self.backup_plan_id() if uuid is None else UUID(uuid)
return BackupPlan(id=uuid,
label=self.label(),
source=self.source(),
destinations=[self.destination()])