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.
74 lines
2.2 KiB
74 lines
2.2 KiB
from behave import given, when, then
|
|
import json
|
|
from tui_rsync.core.components.backup_plan.domain import BackupPlan, Source, Destination
|
|
|
|
|
|
|
|
@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_repository.add(context.backup_plan)
|
|
|
|
context.backup_plan = context.backup_plan_repository.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_repository.delete(context.backup_plan.id)
|
|
context.backup_plan = context.backup_plan_repository.get_by_id(context.backup_plan.id)
|
|
except Exception 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
|