mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-09-13 08:57:43 +00:00
Update the remove all backup plans command.
Refactor the commands names. Add the service to remove all plans. Add tests for remove all command.
This commit is contained in:
@@ -28,3 +28,29 @@ Feature: Deleting a backup plan with the CLI
|
|||||||
| arguments | result | result_error | description |
|
| 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 |
|
| 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 "<arguments>"
|
||||||
|
When I run the CLI
|
||||||
|
Then the CLI executed with "<result>"
|
||||||
|
And the CLI output contains "<result_message>"
|
||||||
|
|
||||||
|
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 "<arguments>"
|
||||||
|
When I run the CLI
|
||||||
|
Then the CLI executed with "<result>"
|
||||||
|
And the CLI output contains "<result_message>"
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
| arguments | result | result_message | description |
|
||||||
|
| plans remove all | success | All backup plans removed. | delete all backup plans |
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from .remove_all_backup_plans_command import RemoveAllBackupBackupPlansCommand
|
from .remove_all_backup_plans_command import RemoveAllBackupPlansCommand
|
||||||
from .remove_backup_plan_destinations_command import RemoveBackupBackupPlanDestinationsCommand
|
from .remove_backup_plan_destinations_command import RemoveBackupPlanDestinationsCommand
|
||||||
from .remove_backup_plan_command import RemoveBackupBackupPlanCommand
|
from .remove_backup_plan_command import RemoveBackupPlanCommand
|
||||||
|
|
||||||
__all__ = ['RemoveAllBackupBackupPlansCommand', 'RemoveBackupBackupPlanCommand', 'RemoveBackupBackupPlanDestinationsCommand']
|
__all__ = ['RemoveAllBackupPlansCommand', 'RemoveBackupPlanCommand', 'RemoveBackupPlanDestinationsCommand']
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ from tui_rsync.core.ports.orm import DatabaseManagerPort
|
|||||||
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
|
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
|
||||||
|
|
||||||
|
|
||||||
class RemoveAllBackupBackupPlansCommand:
|
class RemoveAllBackupPlansCommand:
|
||||||
def __init__(self, database_manager: DatabaseManagerPort):
|
def __init__(self, database_manager: DatabaseManagerPort):
|
||||||
self.databaseManager = database_manager
|
self.databaseManager = database_manager
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException
|
|||||||
from tui_rsync.infrastructure.orm.models import DestinationModel, BackupPlanModel
|
from tui_rsync.infrastructure.orm.models import DestinationModel, BackupPlanModel
|
||||||
|
|
||||||
|
|
||||||
class RemoveBackupBackupPlanCommand:
|
class RemoveBackupPlanCommand:
|
||||||
def __init__(self, database_manager: DatabaseManagerPort):
|
def __init__(self, database_manager: DatabaseManagerPort):
|
||||||
self.databaseManager = database_manager
|
self.databaseManager = database_manager
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ from tui_rsync.core.shared_kernel.components.common import UUID
|
|||||||
from tui_rsync.infrastructure.orm.models import DestinationModel
|
from tui_rsync.infrastructure.orm.models import DestinationModel
|
||||||
|
|
||||||
|
|
||||||
class RemoveBackupBackupPlanDestinationsCommand:
|
class RemoveBackupPlanDestinationsCommand:
|
||||||
def __init__(self, database_manager: DatabaseManagerPort):
|
def __init__(self, database_manager: DatabaseManagerPort):
|
||||||
self.databaseManager = database_manager
|
self.databaseManager = database_manager
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -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.core.shared_kernel.components.common import UUID
|
||||||
|
|
||||||
from tui_rsync.infrastructure.orm.models import BackupPlanModel
|
from tui_rsync.infrastructure.orm.models import BackupPlanModel
|
||||||
from ..commands import RemoveBackupBackupPlanDestinationsCommand, RemoveBackupBackupPlanCommand
|
from ..commands import RemoveBackupPlanDestinationsCommand, RemoveBackupPlanCommand
|
||||||
from ..queries import GetBackupPlanByIdQuery
|
from ..queries import GetBackupPlanByIdQuery
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
|
|||||||
def update(self, backup_plan: BackupPlan):
|
def update(self, backup_plan: BackupPlan):
|
||||||
updated_model = BackupPlanDTO.to_model(backup_plan)
|
updated_model = BackupPlanDTO.to_model(backup_plan)
|
||||||
model = BackupPlanModel.get_or_none(BackupPlanModel.id == updated_model.id)
|
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.label = updated_model.label
|
||||||
model.source = updated_model.source
|
model.source = updated_model.source
|
||||||
@@ -42,5 +42,5 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
|
|||||||
destination.save(force_insert=True)
|
destination.save(force_insert=True)
|
||||||
|
|
||||||
def delete(self, uuid: UUID) -> bool:
|
def delete(self, uuid: UUID) -> bool:
|
||||||
command = RemoveBackupBackupPlanCommand(self.databaseManager)
|
command = RemoveBackupPlanCommand(self.databaseManager)
|
||||||
return command.execute(uuid)
|
return command.execute(uuid)
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
from .backup_plan_service import BackupPlanService
|
from .backup_plan_service import BackupPlanService
|
||||||
from .get_all_backup_plans_service import GetAllBackupPlansService
|
from .get_all_backup_plans_service import GetAllBackupPlansService
|
||||||
from .get_backup_plan_count_service import GetBackupPlanCountService
|
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',
|
||||||
|
]
|
||||||
|
|||||||
+9
@@ -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()
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
from injector import singleton, Module, provider
|
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.queries import GetAllBackupPlansQuery, GetBackupPlanCountQuery
|
||||||
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort, BackupPlanRepository
|
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort, BackupPlanRepository
|
||||||
from tui_rsync.core.components.backup_plan.application.services import GetBackupPlanCountService, \
|
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.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||||
from tui_rsync.core.ports.configuration import UserDataPathsPort
|
from tui_rsync.core.ports.configuration import UserDataPathsPort
|
||||||
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
||||||
@@ -39,8 +39,13 @@ class Configuration(Module):
|
|||||||
|
|
||||||
@provider
|
@provider
|
||||||
@singleton
|
@singleton
|
||||||
def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand:
|
def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupPlansCommand:
|
||||||
return RemoveAllBackupBackupPlansCommand(database_manager)
|
return RemoveAllBackupPlansCommand(database_manager)
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_remove_all_backup_plans_service(self, command: RemoveAllBackupPlansCommand) -> RemoveAllBackupPlansService:
|
||||||
|
return RemoveAllBackupPlansService(command)
|
||||||
|
|
||||||
@provider
|
@provider
|
||||||
@singleton
|
@singleton
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
from injector import singleton, Module, provider
|
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.queries import GetAllBackupPlansQuery, GetBackupPlanCountQuery
|
||||||
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort, BackupPlanRepository
|
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort, BackupPlanRepository
|
||||||
from tui_rsync.core.components.backup_plan.application.services import GetBackupPlanCountService, \
|
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.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||||
from tui_rsync.core.ports.configuration import UserDataPathsPort
|
from tui_rsync.core.ports.configuration import UserDataPathsPort
|
||||||
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
||||||
@@ -39,8 +39,13 @@ class TestingConfiguration(Module):
|
|||||||
|
|
||||||
@provider
|
@provider
|
||||||
@singleton
|
@singleton
|
||||||
def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand:
|
def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupPlansCommand:
|
||||||
return RemoveAllBackupBackupPlansCommand(database_manager)
|
return RemoveAllBackupPlansCommand(database_manager)
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_remove_all_backup_plans_service(self, command: RemoveAllBackupPlansCommand) -> RemoveAllBackupPlansService:
|
||||||
|
return RemoveAllBackupPlansService(command)
|
||||||
|
|
||||||
@provider
|
@provider
|
||||||
@singleton
|
@singleton
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
import typer
|
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.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.components.common import UUID
|
||||||
from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException
|
from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException
|
||||||
@@ -57,10 +57,9 @@ def all():
|
|||||||
[red b]Remove[/] [yellow] all existing backup plans[/].
|
[red b]Remove[/] [yellow] all existing backup plans[/].
|
||||||
"""
|
"""
|
||||||
|
|
||||||
command: RemoveAllBackupBackupPlansCommand = CurrentConfiguration.get(RemoveAllBackupBackupPlansCommand)
|
service: RemoveAllBackupPlansService = CurrentConfiguration.get(RemoveAllBackupPlansService)
|
||||||
removed = command.execute()
|
|
||||||
|
|
||||||
if removed:
|
if service.remove_all():
|
||||||
console.print(f"Removed all backup plans.")
|
console.print("All backup plans removed.")
|
||||||
else:
|
else:
|
||||||
console.print(f"Nothing to remove. No backup plans.")
|
console.print("Nothing to remove. No backup plans.")
|
||||||
|
|||||||
Reference in New Issue
Block a user