From a4a0f32f5278f854720216855c3999ddb67681d8 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sat, 25 Jan 2025 21:45:35 +0200 Subject: [PATCH] Add the service's test for deleting. --- features/backup_plan_model_delete.feature | 14 ++++++++++++++ features/steps/backup_plan_model_steps.py | 23 ++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 features/backup_plan_model_delete.feature diff --git a/features/backup_plan_model_delete.feature b/features/backup_plan_model_delete.feature new file mode 100644 index 0000000..e110674 --- /dev/null +++ b/features/backup_plan_model_delete.feature @@ -0,0 +1,14 @@ +Feature: Delete a backup plan + + @fixture.injector + @fixture.in_memory_database + @fixture.seeds + Scenario Outline: Deleting a backup plan with the CLI + Given I have a backup plan with id="" + When I remove the backup plan with id="" + Then the result should be "" + + Examples: + | backup_plan_id | existing_backup_plan_id | result | description | + | 8aa59e7e-dc75-459b-beb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be583 | success | delete an existing plan | + | 8aa59e7e-dc75-459b-aeb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be512 | error | delete a non-existing plan | diff --git a/features/steps/backup_plan_model_steps.py b/features/steps/backup_plan_model_steps.py index 1806e43..69c94e4 100644 --- a/features/steps/backup_plan_model_steps.py +++ b/features/steps/backup_plan_model_steps.py @@ -1,7 +1,9 @@ from behave import given, when, then import json -from tui_rsync.core.components.backup_plan.domain import BackupPlan, Source, Destination +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.shared_kernel.components.common import UUID @given('the label "{label}"') @@ -48,6 +50,14 @@ def add_backup_plan(context): context.exception_raised = False +@when('I remove the backup plan with id="{backup_plan_id}"') +def given_existing_backup_plan_id_seed(context, backup_plan_id): + context.backup_plan_service = context.injector.get(BackupPlanService) + context.deleted_result = context.backup_plan_service.delete(UUID(backup_plan_id)) + # TODO error value or exception? + context.exception_raised = not context.deleted_result + + def compare_destinations(actual: list[Destination], expected: list[str]) -> bool: actual_path_set = {destionation.path for destionation in actual} return actual_path_set == set(expected) @@ -71,3 +81,14 @@ def backup_plan_has_deleted(context): assert context.exception_raised == False assert context.backup_plan is None assert context.deleted_result + + +@then('the result should be "{result}"') +def then_cli_executed_successfully(context, result): + match result: + case "success": + assert context.exception_raised == False + case "error": + assert context.exception_raised + +