From cabcde00c71ce1784b956998277420a06cad6929 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 28 Jan 2025 10:52:14 +0200 Subject: [PATCH] Add tests for the remove all backup plans service. --- features/backup_plan_model_delete.feature | 16 +++++++++++++++- features/steps/backup_plan_model_steps.py | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/features/backup_plan_model_delete.feature b/features/backup_plan_model_delete.feature index e110674..8c12ca0 100644 --- a/features/backup_plan_model_delete.feature +++ b/features/backup_plan_model_delete.feature @@ -3,7 +3,7 @@ Feature: Delete a backup plan @fixture.injector @fixture.in_memory_database @fixture.seeds - Scenario Outline: Deleting a backup plan with the CLI + Scenario Outline: Deleting a backup plan Given I have a backup plan with id="" When I remove the backup plan with id="" Then the result should be "" @@ -12,3 +12,17 @@ Feature: Delete a backup plan | 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 | + + @fixture.injector + @fixture.in_memory_database + Scenario: Delete no backup plans + When I remove all backup plans + Then the result value should be "False" + + @fixture.injector + @fixture.in_memory_database + @fixture.seeds + Scenario: Delete all backup plans + Given I have a backup plan with id="8aa59e7e-dc75-459b-beb5-b710b39be583" + When I remove all backup plans + Then the result value should be "True" diff --git a/features/steps/backup_plan_model_steps.py b/features/steps/backup_plan_model_steps.py index 03107b7..01dba6d 100644 --- a/features/steps/backup_plan_model_steps.py +++ b/features/steps/backup_plan_model_steps.py @@ -1,6 +1,7 @@ from behave import given, when, then import json +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.domain import BackupPlan, Source, Destination from tui_rsync.core.shared_kernel.components.common import UUID @@ -52,6 +53,17 @@ def when_remove_backup_plan_with_id(context, backup_plan_id): context.exception_raised = False +@when('I remove all backup plans') +def when_remove_all_backup_plans(context): + try: + context.backup_plan_service = context.injector.get(RemoveAllBackupPlansService) + context.result_value = context.backup_plan_service.remove_all() + except CommandException as e: + context.exception_raised = True + else: + context.exception_raised = False + + @when('I read the backup plan with id="{backup_plan_id}"') def when_read_backup_plan_with_id(context, backup_plan_id): try: @@ -91,3 +103,8 @@ def then_cli_executed_successfully(context, result): assert context.exception_raised +@then('the result value should be "{result}"') +def then_cli_executed_successfully(context, result): + assert result == str(context.result_value) + +