mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-12 17:57:43 +00:00
Update the test to test models in a memory database.
Add fixtures in the environment.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
Feature: Creating the source
|
||||
|
||||
@fixture.in_memory_database
|
||||
@fixture.backup_plan_repository
|
||||
Scenario Outline: Create an new unique backup plan
|
||||
Given the label "<label>"
|
||||
And the path "<source_path>"
|
||||
And the destinations <destinations>
|
||||
When I create the backup plan
|
||||
Then it should be created successfully
|
||||
|
||||
Examples:
|
||||
| label | source_path | destinations |
|
||||
| usb | /mnt/usb | [] |
|
||||
| db | /db | ["/backup/db"] |
|
||||
| temp | /tmp | ["/backup/tmp1", "/backup/tmp2"] |
|
||||
|
||||
@fixture.in_memory_database
|
||||
@fixture.backup_plan_repository
|
||||
Scenario Outline: Create an new unique backup plan
|
||||
Given the label "<label>"
|
||||
And the path "<source_path>"
|
||||
And the destinations <destinations>
|
||||
When I create the backup plan
|
||||
When I delete the backup plan
|
||||
Then it should be deleted successfully
|
||||
|
||||
Examples:
|
||||
| label | source_path | destinations |
|
||||
| usb | /mnt/usb | [] |
|
||||
| db | /db | ["/backup/db"] |
|
||||
| temp | /tmp | ["/backup/tmp1", "/backup/tmp2"] |
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
Feature: Creating the source
|
||||
|
||||
Scenario Outline: Create an new unique backup plan
|
||||
Given the label "<label>"
|
||||
And the path "<source_path>"
|
||||
And the destinations <destinations>
|
||||
And the arguments "<arguments>"
|
||||
When I create the backup plan
|
||||
Then it should be created successfully
|
||||
|
||||
Examples:
|
||||
| label | source_path | destinations | arguments |
|
||||
| usb | /mnt/usb | [] | <empty> |
|
||||
| db | /db | ["/backup/db"] | -avuP |
|
||||
| temp | /tmp | ["/backup/tmp1", "/backup/tmp2"] | -avuP --delete |
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
from behave import fixture, use_fixture
|
||||
|
||||
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
|
||||
from tui_rsync.infrastructure.orm import InMemoryDatabaseManager
|
||||
|
||||
|
||||
@fixture
|
||||
def setup_in_memory_database_manager(context):
|
||||
context.db = InMemoryDatabaseManager()
|
||||
yield context.db
|
||||
|
||||
|
||||
@fixture
|
||||
def setup_backup_plan_repository(context):
|
||||
context.backup_plan_repository = BackupPlanRepository(context.db)
|
||||
yield context.db
|
||||
|
||||
|
||||
def before_tag(context, tag):
|
||||
if tag == "fixture.in_memory_database":
|
||||
use_fixture(setup_in_memory_database_manager, context)
|
||||
if tag == "fixture.backup_plan_repository":
|
||||
use_fixture(setup_backup_plan_repository, context)
|
||||
+26
-17
@@ -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
|
||||
Reference in New Issue
Block a user