mirror of https://gitlab.com/KKlochko/tui-rsync
parent
e0f8ec9db5
commit
7ef5b9975c
@ -0,0 +1,30 @@
|
||||
Feature: Update a backup plan
|
||||
|
||||
@fixture.injector
|
||||
@fixture.in_memory_database
|
||||
@fixture.seeds
|
||||
Scenario Outline: Update a backup plan's fields
|
||||
Given I have a backup plan with id="<existing_backup_plan_id>"
|
||||
When I update the backup plan with id="<backup_plan_id>" and data="<updated_data>"
|
||||
Then the result should be "<result>"
|
||||
|
||||
Examples:
|
||||
| backup_plan_id | existing_backup_plan_id | updated_data | result | description |
|
||||
| 8aa59e7e-dc75-459b-beb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be583 | {"label": "new_label"} | success | update an existing plan |
|
||||
| 8aa59e7e-dc75-459b-aeb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be512 | {"label": "new_label"} | error | update a non-existing plan |
|
||||
|
||||
@fixture.injector
|
||||
@fixture.in_memory_database
|
||||
@fixture.seeds
|
||||
Scenario Outline: Updated backup plan's fields must be updated
|
||||
Given I have a backup plan with id="<existing_backup_plan_id>"
|
||||
When I update the backup plan with id="<backup_plan_id>" and data="<updated_data>"
|
||||
And I read the backup plan with id="<backup_plan_id>"
|
||||
Then the result should be "<result>"
|
||||
And the backup_plan must have same field: "<updated_data>"
|
||||
|
||||
Examples:
|
||||
| backup_plan_id | existing_backup_plan_id | updated_data | result | description |
|
||||
| 8aa59e7e-dc75-459b-beb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be583 | {"label": "new_label"} | success | update the label |
|
||||
| 8aa59e7e-dc75-459b-beb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be583 | {"source": "/new/mnt"} | success | update the source |
|
||||
| 8aa59e7e-dc75-459b-beb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be583 | {"destinations": ["/mnt2", "/mnt3"]} | success | update the destinations |
|
@ -0,0 +1,57 @@
|
||||
from features.support.helpers import json_to_dict
|
||||
from tui_rsync.core.components.backup_plan.domain import Destination, BackupPlan, Source
|
||||
|
||||
|
||||
def json_to_backup_plan(backup_plan_json):
|
||||
fields = json_to_dict(backup_plan_json)
|
||||
|
||||
backup_plan = BackupPlan(
|
||||
label=fields['label'],
|
||||
source=Source(fields['source']),
|
||||
destinations=list(map(lambda path: Destination(path), fields['destinations'])),
|
||||
)
|
||||
|
||||
return backup_plan
|
||||
|
||||
|
||||
def update_backup_plan(backup_plan, fields: dict):
|
||||
for field, value in fields.items():
|
||||
match field:
|
||||
case 'label':
|
||||
backup_plan.label = value
|
||||
case 'source':
|
||||
backup_plan.source = Source(value)
|
||||
case 'destinations':
|
||||
backup_plan.destinations = list(map(lambda path: Destination(path), value))
|
||||
|
||||
return backup_plan
|
||||
|
||||
|
||||
def compare_backup_plan_fields(backup_plan, fields: dict):
|
||||
for field, value in fields.items():
|
||||
match field:
|
||||
case 'label':
|
||||
if backup_plan.label != value:
|
||||
return False
|
||||
case 'source':
|
||||
if backup_plan.source.path != value:
|
||||
return False
|
||||
case 'destinations':
|
||||
if not compare_destinations(backup_plan.destinations, value):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def compare_backup_plans(backup_plan, expected):
|
||||
return backup_plan.label == expected.label \
|
||||
and backup_plan.source == expected.source_path \
|
||||
and compare_destinations(
|
||||
backup_plan.destinations,
|
||||
expected.destinations
|
||||
)
|
@ -0,0 +1,5 @@
|
||||
import json
|
||||
|
||||
|
||||
def json_to_dict(json_data):
|
||||
return json.loads(json_data)
|
Loading…
Reference in new issue