mirror of https://gitlab.com/KKlochko/tui-rsync
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.1 KiB
99 lines
3.1 KiB
from behave import given, when, then
|
|
import json
|
|
|
|
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
|
|
from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException
|
|
|
|
|
|
@given('the label "{label}"')
|
|
def given_source_label(context, label):
|
|
context.label = label
|
|
|
|
|
|
@given('the path "{source_path}"')
|
|
def given_source_path(context, source_path):
|
|
context.source_path = source_path
|
|
|
|
|
|
@given('the destinations {destinations_json}')
|
|
def given_source_destinations(context, destinations_json):
|
|
context.destinations = json.loads(destinations_json)
|
|
|
|
|
|
@when('I create the backup plan')
|
|
def add_backup_plan(context):
|
|
try:
|
|
context.backup_plan = BackupPlan(
|
|
label=context.label,
|
|
source=Source(context.source_path),
|
|
destinations=list(map(lambda path: Destination(path), context.destinations)),
|
|
)
|
|
|
|
context.backup_plan_service.add(context.backup_plan)
|
|
|
|
context.backup_plan = context.backup_plan_service.get_by_id(context.backup_plan.id)
|
|
except Exception as e:
|
|
context.exception_raised = True
|
|
else:
|
|
context.exception_raised = False
|
|
|
|
|
|
@when('I delete the backup plan')
|
|
def add_backup_plan(context):
|
|
try:
|
|
context.deleted_result = context.backup_plan_service.delete(context.backup_plan.id)
|
|
context.backup_plan = context.backup_plan_service.get_by_id(context.backup_plan.id)
|
|
except Exception as e:
|
|
context.exception_raised = True
|
|
else:
|
|
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):
|
|
try:
|
|
context.backup_plan_service = context.injector.get(BackupPlanService)
|
|
context.backup_plan_service.delete(UUID(backup_plan_id))
|
|
except CommandException as e:
|
|
context.exception_raised = True
|
|
else:
|
|
context.exception_raised = False
|
|
|
|
|
|
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)
|
|
|
|
|
|
@then('it should be created successfully')
|
|
def backup_plan_has_added(context):
|
|
assert context.exception_raised == False
|
|
assert context.backup_plan is not None
|
|
|
|
assert context.backup_plan.label == context.label
|
|
assert context.backup_plan.source == Source(context.source_path)
|
|
|
|
assert compare_destinations(
|
|
context.backup_plan.destinations,
|
|
context.destinations
|
|
)
|
|
|
|
@then('it should be deleted successfully')
|
|
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
|
|
|
|
|