Update the show all plans command to show if there're no plans.

dev
KKlochko 3 months ago
parent b999975695
commit 9729f442c2

@ -1,18 +1,46 @@
Feature: Deleting a backup plan with the CLI Feature: Show a backup plan with the CLI
@fixture.injector @fixture.injector
@fixture.in_memory_database @fixture.in_memory_database
@fixture.seeds @fixture.seeds
@fixture.cli @fixture.cli
Scenario Outline: Deleting a backup plan with the CLI Scenario Outline: Show a backup plan with the CLI
Given the CLI arguments are "<arguments>" Given the CLI arguments are "<arguments>"
And I have a backup plan with id="<existing_backup_plan_id>" And I have a backup plan with id="<existing_backup_plan_id>"
When I run the CLI When I run the CLI
Then the CLI executed with "<result>" Then the CLI executed with "<result>"
Examples: Examples:
| arguments | existing_backup_plan_id | result | description | | arguments | existing_backup_plan_id | result | description |
| plans show one -i 8aa59e7e-dc75-459b-beb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be583 | success | delete an existing plan | | plans show one -i 8aa59e7e-dc75-459b-beb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be583 | success | show an existing plan |
| plans show one -i 8aa59e7e-dc75-459b-aeb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be512 | error | delete a non-existing plan | | plans show one -i 8aa59e7e-dc75-459b-aeb5-b710b39be583 | 8aa59e7e-dc75-459b-beb5-b710b39be512 | error | show a non-existing plan |
@fixture.injector
@fixture.in_memory_database
@fixture.cli
Scenario Outline: Show no backup plans with the CLI
Given the CLI arguments are "<arguments>"
When I run the CLI
Then the CLI executed with "<result>"
And the CLI output contains "<result_message>"
Examples:
| arguments | result | result_message | description |
| plans show all | success | No backup plans. | shows no plans |
@fixture.injector
@fixture.in_memory_database
@fixture.seeds
@fixture.cli
Scenario Outline: Show backup plans with the CLI
Given the CLI arguments are "<arguments>"
And I have a backup plan with id="8aa59e7e-dc75-459b-beb5-b710b39be583"
When I run the CLI
Then the CLI executed with "<result>"
And the CLI output contains "8aa59e7e-dc75-459b-beb5-b710b39be583"
And the CLI output doesn't contains "<no_message>"
Examples:
| arguments | result | no_message | description |
| plans show all | success | No backup plans. | shows plans |

@ -3,9 +3,7 @@ from behave import given, when, then
@given('the CLI arguments are "{arguments}"') @given('the CLI arguments are "{arguments}"')
def given_cli_arguments(context, arguments): def given_cli_arguments(context, arguments):
print(f"{arguments}")
context.arguments = arguments.split() context.arguments = arguments.split()
print(f"{context.arguments}")
@when('I run the CLI') @when('I run the CLI')
@ -27,6 +25,10 @@ def then_cli_output_contains(context, string):
assert string in context.cli_result.stdout assert string in context.cli_result.stdout
@then('the CLI output doesn\'t contains "{string}"')
def then_cli_output_contains(context, string):
assert not (string in context.cli_result.stdout)
@then('the CLI contains the error: "{string}"') @then('the CLI contains the error: "{string}"')
def then_cli_output_contains_error(context, string): def then_cli_output_contains_error(context, string):
assert string in context.cli_result.stdout assert string in context.cli_result.stdout

@ -1,4 +1,5 @@
from .get_all_backup_plans_query import GetAllBackupBackupPlansQuery from .get_all_backup_plans_query import GetAllBackupPlansQuery
from .get_backup_plan_by_id_query import GetBackupBackupPlanByIdQuery from .get_backup_plan_by_id_query import GetBackupPlanByIdQuery
from .get_backup_plan_count_query import GetBackupPlanCountQuery
__all__ = ['GetAllBackupBackupPlansQuery', 'GetBackupBackupPlanByIdQuery'] __all__ = ['GetAllBackupPlansQuery', 'GetBackupPlanByIdQuery', 'GetBackupPlanCountQuery']

@ -0,0 +1,12 @@
from tui_rsync.core.ports.orm import DatabaseManagerPort
from tui_rsync.infrastructure.orm.dto.dtos import BackupPlanDTO
from tui_rsync.infrastructure.orm.models import BackupPlanModel
class GetAllBackupBackupPlansQuery:
def __init__(self, database_manager: DatabaseManagerPort):
self.databaseManager = database_manager
def execute(self):
return (BackupPlanDTO.to_domain(model) for model in BackupPlanModel.select().iterator())

@ -4,7 +4,7 @@ from tui_rsync.infrastructure.orm.dto.dtos import BackupPlanDTO
from tui_rsync.infrastructure.orm.models import BackupPlanModel from tui_rsync.infrastructure.orm.models import BackupPlanModel
class GetAllBackupBackupPlansQuery: class GetAllBackupPlansQuery:
def __init__(self, database_manager: DatabaseManagerPort): def __init__(self, database_manager: DatabaseManagerPort):
self.databaseManager = database_manager self.databaseManager = database_manager

@ -7,7 +7,7 @@ from tui_rsync.infrastructure.orm.dto.dtos import BackupPlanDTO
from tui_rsync.infrastructure.orm.models import BackupPlanModel from tui_rsync.infrastructure.orm.models import BackupPlanModel
class GetBackupBackupPlanByIdQuery: class GetBackupPlanByIdQuery:
def __init__(self, database_manager: DatabaseManagerPort): def __init__(self, database_manager: DatabaseManagerPort):
self.databaseManager = database_manager self.databaseManager = database_manager

@ -0,0 +1,11 @@
from tui_rsync.core.ports.orm import DatabaseManagerPort
from tui_rsync.infrastructure.orm.models import BackupPlanModel
class GetBackupPlanCountQuery:
def __init__(self, database_manager: DatabaseManagerPort):
self.databaseManager = database_manager
def execute(self):
return BackupPlanModel.select().count()

@ -1,3 +1,4 @@
from .backup_plan_repository_port import BackupPlanRepositoryPort from .backup_plan_repository_port import BackupPlanRepositoryPort
from .backup_plan_repository import BackupPlanRepository
__all__ = ['BackupPlanRepositoryPort'] __all__ = ['BackupPlanRepositoryPort', 'BackupPlanRepository']

@ -9,7 +9,7 @@ from tui_rsync.core.shared_kernel.components.common import UUID
from tui_rsync.infrastructure.orm.models import BackupPlanModel from tui_rsync.infrastructure.orm.models import BackupPlanModel
from ..commands import RemoveBackupBackupPlanDestinationsCommand, RemoveBackupBackupPlanCommand from ..commands import RemoveBackupBackupPlanDestinationsCommand, RemoveBackupBackupPlanCommand
from ..queries import GetBackupBackupPlanByIdQuery from ..queries import GetBackupPlanByIdQuery
class BackupPlanRepository(BackupPlanRepositoryPort): class BackupPlanRepository(BackupPlanRepositoryPort):
@ -24,7 +24,7 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
destination.save(force_insert=True) destination.save(force_insert=True)
def get_by_id(self, uuid: UUID) -> BackupPlan: def get_by_id(self, uuid: UUID) -> BackupPlan:
query = GetBackupBackupPlanByIdQuery(self.databaseManager) query = GetBackupPlanByIdQuery(self.databaseManager)
return query.execute(uuid) return query.execute(uuid)
def update(self, backup_plan: BackupPlan): def update(self, backup_plan: BackupPlan):

@ -0,0 +1,5 @@
from .backup_plan_service import BackupPlanService
from .get_all_backup_plans_service import GetAllBackupPlansService
from .get_backup_plan_count_service import GetBackupPlanCountService
__all__ = ['BackupPlanService', 'GetAllBackupPlansService', 'GetBackupPlanCountService']

@ -0,0 +1,13 @@
from typing import List
from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupPlansQuery
from tui_rsync.core.components.backup_plan.domain import BackupPlan
class GetAllBackupPlansService:
def __init__(self, get_all_backup_plan_query: GetAllBackupPlansQuery):
self.get_all_backup_plan_query = get_all_backup_plan_query
def get_all(self) -> List[BackupPlan]:
return self.get_all_backup_plan_query.execute()

@ -0,0 +1,16 @@
from typing import List
from tui_rsync.core.components.backup_plan.application.queries import GetBackupPlanCountQuery
from tui_rsync.core.components.backup_plan.domain import BackupPlan
class GetBackupPlanCountService:
def __init__(self, get_backup_plan_count_query: GetBackupPlanCountQuery):
self.get_backup_plan_count_query = get_backup_plan_count_query
def count(self) -> int:
return self.get_backup_plan_count_query.execute()
def is_empty(self) -> bool:
return self.count() == 0

@ -1,9 +1,10 @@
from injector import singleton, Module, provider from injector import singleton, Module, provider
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupBackupPlansQuery from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupPlansQuery, GetBackupPlanCountQuery
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort, BackupPlanRepository
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository from tui_rsync.core.components.backup_plan.application.services import GetBackupPlanCountService, \
GetAllBackupPlansService
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
from tui_rsync.core.ports.configuration import UserDataPathsPort from tui_rsync.core.ports.configuration import UserDataPathsPort
from tui_rsync.core.ports.orm import DatabaseManagerPort from tui_rsync.core.ports.orm import DatabaseManagerPort
@ -38,13 +39,28 @@ class Configuration(Module):
@provider @provider
@singleton @singleton
def provide_remove_all_backup_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand: def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand:
return RemoveAllBackupBackupPlansCommand(database_manager) return RemoveAllBackupBackupPlansCommand(database_manager)
@provider @provider
@singleton @singleton
def provide_get_all_backup_backup_plans_query(self, database_manager: DatabaseManagerPort) -> GetAllBackupBackupPlansQuery: def provide_get_all_backup_plans_query(self, database_manager: DatabaseManagerPort) -> GetAllBackupPlansQuery:
return GetAllBackupBackupPlansQuery(database_manager) return GetAllBackupPlansQuery(database_manager)
@provider
@singleton
def provide_get_backup_plan_count_query(self, database_manager: DatabaseManagerPort) -> GetBackupPlanCountQuery:
return GetBackupPlanCountQuery(database_manager)
@provider
@singleton
def provide_get_backup_plan_count_service(self, query: GetBackupPlanCountQuery) -> GetBackupPlanCountService:
return GetBackupPlanCountService(query)
@provider
@singleton
def provide_get_all_backup_plans_service(self, query: GetAllBackupPlansQuery) -> GetAllBackupPlansService:
return GetAllBackupPlansService(query)
@provider @provider
@singleton @singleton

@ -1,9 +1,10 @@
from injector import singleton, Module, provider from injector import singleton, Module, provider
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupBackupPlansQuery from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupPlansQuery, GetBackupPlanCountQuery
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort, BackupPlanRepository
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository from tui_rsync.core.components.backup_plan.application.services import GetBackupPlanCountService, \
GetAllBackupPlansService
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
from tui_rsync.core.ports.configuration import UserDataPathsPort from tui_rsync.core.ports.configuration import UserDataPathsPort
from tui_rsync.core.ports.orm import DatabaseManagerPort from tui_rsync.core.ports.orm import DatabaseManagerPort
@ -38,13 +39,28 @@ class TestingConfiguration(Module):
@provider @provider
@singleton @singleton
def provide_remove_all_backup_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand: def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand:
return RemoveAllBackupBackupPlansCommand(database_manager) return RemoveAllBackupBackupPlansCommand(database_manager)
@provider @provider
@singleton @singleton
def provide_get_all_backup_backup_plans_query(self, database_manager: DatabaseManagerPort) -> GetAllBackupBackupPlansQuery: def provide_get_all_backup_plans_query(self, database_manager: DatabaseManagerPort) -> GetAllBackupPlansQuery:
return GetAllBackupBackupPlansQuery(database_manager) return GetAllBackupPlansQuery(database_manager)
@provider
@singleton
def provide_get_backup_plan_count_query(self, database_manager: DatabaseManagerPort) -> GetBackupPlanCountQuery:
return GetBackupPlanCountQuery(database_manager)
@provider
@singleton
def provide_get_backup_plan_count_service(self, query: GetBackupPlanCountQuery) -> GetBackupPlanCountService:
return GetBackupPlanCountService(query)
@provider
@singleton
def provide_get_all_backup_plans_service(self, query: GetAllBackupPlansQuery) -> GetAllBackupPlansService:
return GetAllBackupPlansService(query)
@provider @provider
@singleton @singleton

@ -20,7 +20,8 @@
from rich.console import Console from rich.console import Console
import typer import typer
from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupBackupPlansQuery from tui_rsync.core.components.backup_plan.application.services import GetAllBackupPlansService, \
GetBackupPlanCountService
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
from tui_rsync.core.shared_kernel.components.common import UUID from tui_rsync.core.shared_kernel.components.common import UUID
@ -48,16 +49,8 @@ def one(
service: BackupPlanService = CurrentConfiguration.get(BackupPlanService) service: BackupPlanService = CurrentConfiguration.get(BackupPlanService)
if id is None:
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
return
plan = service.get_by_id(UUID(id)) plan = service.get_by_id(UUID(id))
if plan is None:
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
return
console.print(BackupPlanFormat.format(plan)) console.print(BackupPlanFormat.format(plan))
@ -67,7 +60,10 @@ def all():
[green b]Show[/] [yellow]all existing backup plans[/]. [green b]Show[/] [yellow]all existing backup plans[/].
""" """
query = CurrentConfiguration.get(GetAllBackupBackupPlansQuery) count_service = CurrentConfiguration.get(GetBackupPlanCountService)
if count_service.is_empty():
for backup_plan in query.execute(): console.print("No backup plans.")
console.print(BackupPlanFormat.format(backup_plan)) else:
service = CurrentConfiguration.get(GetAllBackupPlansService)
for backup_plan in service.get_all():
console.print(BackupPlanFormat.format(backup_plan))

Loading…
Cancel
Save