mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-12 09:47:44 +00:00
Update the repository to use exception for the delete action.
This commit is contained in:
@@ -4,6 +4,7 @@ import json
|
|||||||
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.components.backup_plan.domain import BackupPlan, Source, Destination
|
from tui_rsync.core.components.backup_plan.domain import BackupPlan, Source, Destination
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
@given('the label "{label}"')
|
@given('the label "{label}"')
|
||||||
@@ -52,10 +53,13 @@ def add_backup_plan(context):
|
|||||||
|
|
||||||
@when('I remove the backup plan with id="{backup_plan_id}"')
|
@when('I remove the backup plan with id="{backup_plan_id}"')
|
||||||
def given_existing_backup_plan_id_seed(context, backup_plan_id):
|
def given_existing_backup_plan_id_seed(context, backup_plan_id):
|
||||||
|
try:
|
||||||
context.backup_plan_service = context.injector.get(BackupPlanService)
|
context.backup_plan_service = context.injector.get(BackupPlanService)
|
||||||
context.deleted_result = context.backup_plan_service.delete(UUID(backup_plan_id))
|
context.backup_plan_service.delete(UUID(backup_plan_id))
|
||||||
# TODO error value or exception?
|
except CommandException as e:
|
||||||
context.exception_raised = not context.deleted_result
|
context.exception_raised = True
|
||||||
|
else:
|
||||||
|
context.exception_raised = False
|
||||||
|
|
||||||
|
|
||||||
def compare_destinations(actual: list[Destination], expected: list[str]) -> bool:
|
def compare_destinations(actual: list[Destination], expected: list[str]) -> bool:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ def then_cli_executed_successfully(context, result):
|
|||||||
case "success":
|
case "success":
|
||||||
assert context.cli_result.exit_code == 0
|
assert context.cli_result.exit_code == 0
|
||||||
case "error":
|
case "error":
|
||||||
assert context.cli_result.exit_code == 0
|
assert context.cli_result.exit_code != 0
|
||||||
|
|
||||||
|
|
||||||
@then('the CLI output contains "{string}"')
|
@then('the CLI output contains "{string}"')
|
||||||
|
|||||||
+6
-1
@@ -1,6 +1,7 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
||||||
|
from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException
|
||||||
from tui_rsync.infrastructure.orm.dto.dtos import BackupPlanDTO
|
from tui_rsync.infrastructure.orm.dto.dtos import BackupPlanDTO
|
||||||
from .backup_plan_repository_port import BackupPlanRepositoryPort
|
from .backup_plan_repository_port import BackupPlanRepositoryPort
|
||||||
|
|
||||||
@@ -47,4 +48,8 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
|
|||||||
def delete(self, uuid: UUID) -> bool:
|
def delete(self, uuid: UUID) -> bool:
|
||||||
deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute()
|
deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute()
|
||||||
deleted = DestinationModel.delete().where(DestinationModel.source == uuid.id).execute() | deleted
|
deleted = DestinationModel.delete().where(DestinationModel.source == uuid.id).execute() | deleted
|
||||||
return bool(deleted)
|
|
||||||
|
if deleted == 0:
|
||||||
|
raise CommandException("Failed to delete the backup plan, because it doesn't exist.")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|||||||
@@ -23,13 +23,16 @@ import typer
|
|||||||
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
|
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
|
||||||
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.infrastructure.configuration import CurrentConfiguration
|
from tui_rsync.infrastructure.configuration import CurrentConfiguration
|
||||||
|
from tui_rsync.user_interface.cli.shared_kernel.components.errors.applications.exceptions import catch_exception
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
remove_backup_plan = typer.Typer()
|
remove_backup_plan = typer.Typer()
|
||||||
|
|
||||||
|
|
||||||
@remove_backup_plan.command()
|
@remove_backup_plan.command()
|
||||||
|
@catch_exception(CommandException, 1)
|
||||||
def one(
|
def one(
|
||||||
id: str = typer.Option(
|
id: str = typer.Option(
|
||||||
None, "--id", "-i",
|
None, "--id", "-i",
|
||||||
@@ -43,15 +46,7 @@ def one(
|
|||||||
|
|
||||||
service: BackupPlanService = CurrentConfiguration.get(BackupPlanService)
|
service: BackupPlanService = CurrentConfiguration.get(BackupPlanService)
|
||||||
|
|
||||||
if id is None:
|
service.delete(UUID(id))
|
||||||
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
|
|
||||||
return
|
|
||||||
|
|
||||||
plan = service.delete(UUID(id))
|
|
||||||
|
|
||||||
if plan is None:
|
|
||||||
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
|
|
||||||
return
|
|
||||||
|
|
||||||
console.print(f"Removed the backup plan with {id}.")
|
console.print(f"Removed the backup plan with {id}.")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user