diff --git a/features/backup_plan_cli_delete.feature b/features/backup_plan_cli_delete.feature index 2fc331a..d044679 100644 --- a/features/backup_plan_cli_delete.feature +++ b/features/backup_plan_cli_delete.feature @@ -28,3 +28,29 @@ Feature: Deleting a backup plan with the CLI | arguments | result | result_error | description | | plans remove one -i 8aa59e7e-dc75-459b-aeb5-b710b39be583 | error | [ERROR] Failed to delete the backup plan, because it doesn't exist. | delete a non-existing plan | + @fixture.injector + @fixture.in_memory_database + @fixture.cli + Scenario Outline: Delete no backup plans with the CLI + Given the CLI arguments are "" + When I run the CLI + Then the CLI executed with "" + And the CLI output contains "" + + Examples: + | arguments | result | result_message | description | + | plans remove all | success | Nothing to remove. No backup plans. | delete no plans | + + @fixture.injector + @fixture.in_memory_database + @fixture.seeds + @fixture.cli + Scenario Outline: Delete all backup plans with the CLI + Given the CLI arguments are "" + When I run the CLI + Then the CLI executed with "" + And the CLI output contains "" + + Examples: + | arguments | result | result_message | description | + | plans remove all | success | All backup plans removed. | delete all backup plans | diff --git a/tui_rsync/core/components/backup_plan/application/commands/__init__.py b/tui_rsync/core/components/backup_plan/application/commands/__init__.py index 7b568a9..30a58ad 100644 --- a/tui_rsync/core/components/backup_plan/application/commands/__init__.py +++ b/tui_rsync/core/components/backup_plan/application/commands/__init__.py @@ -1,5 +1,5 @@ -from .remove_all_backup_plans_command import RemoveAllBackupBackupPlansCommand -from .remove_backup_plan_destinations_command import RemoveBackupBackupPlanDestinationsCommand -from .remove_backup_plan_command import RemoveBackupBackupPlanCommand +from .remove_all_backup_plans_command import RemoveAllBackupPlansCommand +from .remove_backup_plan_destinations_command import RemoveBackupPlanDestinationsCommand +from .remove_backup_plan_command import RemoveBackupPlanCommand -__all__ = ['RemoveAllBackupBackupPlansCommand', 'RemoveBackupBackupPlanCommand', 'RemoveBackupBackupPlanDestinationsCommand'] +__all__ = ['RemoveAllBackupPlansCommand', 'RemoveBackupPlanCommand', 'RemoveBackupPlanDestinationsCommand'] diff --git a/tui_rsync/core/components/backup_plan/application/commands/remove_all_backup_plans_command.py b/tui_rsync/core/components/backup_plan/application/commands/remove_all_backup_plans_command.py index 1a10610..a0b4945 100644 --- a/tui_rsync/core/components/backup_plan/application/commands/remove_all_backup_plans_command.py +++ b/tui_rsync/core/components/backup_plan/application/commands/remove_all_backup_plans_command.py @@ -2,7 +2,7 @@ from tui_rsync.core.ports.orm import DatabaseManagerPort from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel -class RemoveAllBackupBackupPlansCommand: +class RemoveAllBackupPlansCommand: def __init__(self, database_manager: DatabaseManagerPort): self.databaseManager = database_manager diff --git a/tui_rsync/core/components/backup_plan/application/commands/remove_backup_plan_command.py b/tui_rsync/core/components/backup_plan/application/commands/remove_backup_plan_command.py index baf70e1..01154fd 100644 --- a/tui_rsync/core/components/backup_plan/application/commands/remove_backup_plan_command.py +++ b/tui_rsync/core/components/backup_plan/application/commands/remove_backup_plan_command.py @@ -4,7 +4,7 @@ from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException from tui_rsync.infrastructure.orm.models import DestinationModel, BackupPlanModel -class RemoveBackupBackupPlanCommand: +class RemoveBackupPlanCommand: def __init__(self, database_manager: DatabaseManagerPort): self.databaseManager = database_manager diff --git a/tui_rsync/core/components/backup_plan/application/commands/remove_backup_plan_destinations_command.py b/tui_rsync/core/components/backup_plan/application/commands/remove_backup_plan_destinations_command.py index 1575705..83edc21 100644 --- a/tui_rsync/core/components/backup_plan/application/commands/remove_backup_plan_destinations_command.py +++ b/tui_rsync/core/components/backup_plan/application/commands/remove_backup_plan_destinations_command.py @@ -3,7 +3,7 @@ from tui_rsync.core.shared_kernel.components.common import UUID from tui_rsync.infrastructure.orm.models import DestinationModel -class RemoveBackupBackupPlanDestinationsCommand: +class RemoveBackupPlanDestinationsCommand: def __init__(self, database_manager: DatabaseManagerPort): self.databaseManager = database_manager diff --git a/tui_rsync/core/components/backup_plan/application/repository/backup_plan_repository.py b/tui_rsync/core/components/backup_plan/application/repository/backup_plan_repository.py index fb80562..525288b 100644 --- a/tui_rsync/core/components/backup_plan/application/repository/backup_plan_repository.py +++ b/tui_rsync/core/components/backup_plan/application/repository/backup_plan_repository.py @@ -8,7 +8,7 @@ from tui_rsync.core.components.backup_plan.domain import BackupPlan from tui_rsync.core.shared_kernel.components.common import UUID from tui_rsync.infrastructure.orm.models import BackupPlanModel -from ..commands import RemoveBackupBackupPlanDestinationsCommand, RemoveBackupBackupPlanCommand +from ..commands import RemoveBackupPlanDestinationsCommand, RemoveBackupPlanCommand from ..queries import GetBackupPlanByIdQuery @@ -30,7 +30,7 @@ class BackupPlanRepository(BackupPlanRepositoryPort): def update(self, backup_plan: BackupPlan): updated_model = BackupPlanDTO.to_model(backup_plan) model = BackupPlanModel.get_or_none(BackupPlanModel.id == updated_model.id) - remove_backup_plan_destinations_command = RemoveBackupBackupPlanDestinationsCommand(self.databaseManager) + remove_backup_plan_destinations_command = RemoveBackupPlanDestinationsCommand(self.databaseManager) model.label = updated_model.label model.source = updated_model.source @@ -42,5 +42,5 @@ class BackupPlanRepository(BackupPlanRepositoryPort): destination.save(force_insert=True) def delete(self, uuid: UUID) -> bool: - command = RemoveBackupBackupPlanCommand(self.databaseManager) + command = RemoveBackupPlanCommand(self.databaseManager) return command.execute(uuid) diff --git a/tui_rsync/core/components/backup_plan/application/services/__init__.py b/tui_rsync/core/components/backup_plan/application/services/__init__.py index 66eb856..b269842 100644 --- a/tui_rsync/core/components/backup_plan/application/services/__init__.py +++ b/tui_rsync/core/components/backup_plan/application/services/__init__.py @@ -1,5 +1,11 @@ from .backup_plan_service import BackupPlanService from .get_all_backup_plans_service import GetAllBackupPlansService from .get_backup_plan_count_service import GetBackupPlanCountService +from .remove_all_backup_plans_service import RemoveAllBackupPlansService -__all__ = ['BackupPlanService', 'GetAllBackupPlansService', 'GetBackupPlanCountService'] +__all__ = [ + 'BackupPlanService', + 'GetAllBackupPlansService', + 'GetBackupPlanCountService', + 'RemoveAllBackupPlansService', +] diff --git a/tui_rsync/core/components/backup_plan/application/services/remove_all_backup_plans_service.py b/tui_rsync/core/components/backup_plan/application/services/remove_all_backup_plans_service.py new file mode 100644 index 0000000..92755ec --- /dev/null +++ b/tui_rsync/core/components/backup_plan/application/services/remove_all_backup_plans_service.py @@ -0,0 +1,9 @@ +from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupPlansCommand + + +class RemoveAllBackupPlansService: + def __init__(self, remove_all_backup_plan_command: RemoveAllBackupPlansCommand): + self.remove_all_backup_plan_command = remove_all_backup_plan_command + + def remove_all(self) -> bool: + return self.remove_all_backup_plan_command.execute() diff --git a/tui_rsync/infrastructure/configuration/configuration.py b/tui_rsync/infrastructure/configuration/configuration.py index 2f8f87e..e35a71f 100644 --- a/tui_rsync/infrastructure/configuration/configuration.py +++ b/tui_rsync/infrastructure/configuration/configuration.py @@ -1,10 +1,10 @@ from injector import singleton, Module, provider -from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand +from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupPlansCommand from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupPlansQuery, GetBackupPlanCountQuery from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort, BackupPlanRepository from tui_rsync.core.components.backup_plan.application.services import GetBackupPlanCountService, \ - GetAllBackupPlansService + GetAllBackupPlansService, RemoveAllBackupPlansService from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService from tui_rsync.core.ports.configuration import UserDataPathsPort from tui_rsync.core.ports.orm import DatabaseManagerPort @@ -39,8 +39,13 @@ class Configuration(Module): @provider @singleton - def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand: - return RemoveAllBackupBackupPlansCommand(database_manager) + def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupPlansCommand: + return RemoveAllBackupPlansCommand(database_manager) + + @provider + @singleton + def provide_remove_all_backup_plans_service(self, command: RemoveAllBackupPlansCommand) -> RemoveAllBackupPlansService: + return RemoveAllBackupPlansService(command) @provider @singleton diff --git a/tui_rsync/infrastructure/configuration/testing_configuration.py b/tui_rsync/infrastructure/configuration/testing_configuration.py index abc7624..643eb68 100644 --- a/tui_rsync/infrastructure/configuration/testing_configuration.py +++ b/tui_rsync/infrastructure/configuration/testing_configuration.py @@ -1,10 +1,10 @@ from injector import singleton, Module, provider -from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand +from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupPlansCommand from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupPlansQuery, GetBackupPlanCountQuery from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort, BackupPlanRepository from tui_rsync.core.components.backup_plan.application.services import GetBackupPlanCountService, \ - GetAllBackupPlansService + GetAllBackupPlansService, RemoveAllBackupPlansService from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService from tui_rsync.core.ports.configuration import UserDataPathsPort from tui_rsync.core.ports.orm import DatabaseManagerPort @@ -39,8 +39,13 @@ class TestingConfiguration(Module): @provider @singleton - def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand: - return RemoveAllBackupBackupPlansCommand(database_manager) + def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupPlansCommand: + return RemoveAllBackupPlansCommand(database_manager) + + @provider + @singleton + def provide_remove_all_backup_plans_service(self, command: RemoveAllBackupPlansCommand) -> RemoveAllBackupPlansService: + return RemoveAllBackupPlansService(command) @provider @singleton diff --git a/tui_rsync/user_interface/cli/components/backup_plan/remove_backup_plan.py b/tui_rsync/user_interface/cli/components/backup_plan/remove_backup_plan.py index cfb7c58..5a692e3 100644 --- a/tui_rsync/user_interface/cli/components/backup_plan/remove_backup_plan.py +++ b/tui_rsync/user_interface/cli/components/backup_plan/remove_backup_plan.py @@ -20,7 +20,7 @@ from rich.console import Console import typer -from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand +from tui_rsync.core.components.backup_plan.application.services import RemoveAllBackupPlansService from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService from tui_rsync.core.shared_kernel.components.common import UUID from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException @@ -57,10 +57,9 @@ def all(): [red b]Remove[/] [yellow] all existing backup plans[/]. """ - command: RemoveAllBackupBackupPlansCommand = CurrentConfiguration.get(RemoveAllBackupBackupPlansCommand) - removed = command.execute() + service: RemoveAllBackupPlansService = CurrentConfiguration.get(RemoveAllBackupPlansService) - if removed: - console.print(f"Removed all backup plans.") + if service.remove_all(): + console.print("All backup plans removed.") else: - console.print(f"Nothing to remove. No backup plans.") + console.print("Nothing to remove. No backup plans.")