diff --git a/features/support/__init__.py b/features/support/__init__.py new file mode 100644 index 0000000..1653b89 --- /dev/null +++ b/features/support/__init__.py @@ -0,0 +1,4 @@ +from .fake_factories import FakeFactories +from .data_seeds import DataSeeds + +__all__ = ['FakeFactories', 'DataSeeds'] diff --git a/features/support/data_seeds.py b/features/support/data_seeds.py new file mode 100644 index 0000000..fa135aa --- /dev/null +++ b/features/support/data_seeds.py @@ -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() diff --git a/features/support/fake_factories.py b/features/support/fake_factories.py new file mode 100644 index 0000000..9e40b93 --- /dev/null +++ b/features/support/fake_factories.py @@ -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()]) diff --git a/poetry.lock b/poetry.lock index 1b2481d..618e928 100644 --- a/poetry.lock +++ b/poetry.lock @@ -48,6 +48,22 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "faker" +version = "35.0.0" +description = "Faker is a Python package that generates fake data for you." +category = "dev" +optional = false +python-versions = ">=3.8" +files = [ + {file = "Faker-35.0.0-py3-none-any.whl", hash = "sha256:926d2301787220e0554c2e39afc4dc535ce4b0a8d0a089657137999f66334ef4"}, + {file = "faker-35.0.0.tar.gz", hash = "sha256:42f2da8cf561e38c72b25e9891168b1e25fec42b6b0b5b0b6cd6041da54af885"}, +] + +[package.dependencies] +python-dateutil = ">=2.4" +typing-extensions = "*" + [[package]] name = "injector" version = "0.22.0" @@ -187,6 +203,21 @@ files = [ [package.extras] plugins = ["importlib-metadata"] +[[package]] +name = "python-dateutil" +version = "2.9.0.post0" +description = "Extensions to the standard Python datetime module" +category = "dev" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +files = [ + {file = "python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3"}, + {file = "python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"}, +] + +[package.dependencies] +six = ">=1.5" + [[package]] name = "rich" version = "13.3.1" @@ -239,7 +270,19 @@ dev = ["autoflake (>=1.3.1,<2.0.0)", "flake8 (>=3.8.3,<4.0.0)", "pre-commit (>=2 doc = ["cairosvg (>=2.5.2,<3.0.0)", "mdx-include (>=1.4.1,<2.0.0)", "mkdocs (>=1.1.2,<2.0.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "pillow (>=9.3.0,<10.0.0)"] test = ["black (>=22.3.0,<23.0.0)", "coverage (>=6.2,<7.0)", "isort (>=5.0.6,<6.0.0)", "mypy (==0.910)", "pytest (>=4.4.0,<8.0.0)", "pytest-cov (>=2.10.0,<5.0.0)", "pytest-sugar (>=0.9.4,<0.10.0)", "pytest-xdist (>=1.32.0,<4.0.0)", "rich (>=10.11.0,<13.0.0)", "shellingham (>=1.3.0,<2.0.0)"] +[[package]] +name = "typing-extensions" +version = "4.12.2" +description = "Backported and Experimental Type Hints for Python 3.8+" +category = "dev" +optional = false +python-versions = ">=3.8" +files = [ + {file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"}, + {file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"}, +] + [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "d0b0192e0197ecd6f960d87e534852e700a4a52e72ed35f1dd58806f2a96c354" +content-hash = "a120a93b02cdb7d460b634c268f377711e70a391395715d5635058193c108084" diff --git a/pyproject.toml b/pyproject.toml index f3f4982..bae670d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ tui-rsync = "tui_rsync.main:main" [tool.poetry.group.dev.dependencies] behave = "^1.2.6" +faker = "^35.0.0" [build-system] requires = ["poetry-core"]