Update the test to test models in a memory database.

Add fixtures in the environment.
This commit is contained in:
2025-01-07 22:04:48 +02:00
parent 0abefda95a
commit c8d2b84cfc
4 changed files with 82 additions and 33 deletions
@@ -3,6 +3,7 @@ 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
@@ -18,26 +19,30 @@ def given_source_destinations(context, destinations_json):
context.destinations = json.loads(destinations_json)
@given('the arguments "{arguments}"')
def given_source_arguments(context, arguments):
context.args = arguments
if arguments == "<empty>":
context.args = ""
@when('I create the backup plan')
def add_source(context):
def add_backup_plan(context):
try:
context.backup_plan = BackupPlan(
label=context.label,
source=Source(context.source_path),
destinations=map(lambda path: Destination(path), context.destinations),
#context.args,
destinations=list(map(lambda path: Destination(path), context.destinations)),
)
#context.source = Source.get_source(context.label)
except Exception:
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
@@ -49,16 +54,20 @@ def compare_destinations(actual: list[Destination], expected: list[str]) -> bool
@then('it should be created successfully')
def path_has_added(context):
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)
print(f'{context.backup_plan.destinations=}')
print(f'{context.destinations=}')
assert compare_destinations(
context.backup_plan.destinations,
context.destinations
)
#assert context.source.args.command == context.args
@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