mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-20 05:37:43 +00:00
Add the TestingConfiguration to simplify the testing configuration.
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
Feature: Creating the source
|
Feature: Creating the source
|
||||||
|
|
||||||
|
@fixture.injector
|
||||||
@fixture.in_memory_database
|
@fixture.in_memory_database
|
||||||
@fixture.backup_plan_repository
|
@fixture.backup_plan_service
|
||||||
Scenario Outline: Create an new unique backup plan
|
Scenario Outline: Create an new unique backup plan
|
||||||
Given the label "<label>"
|
Given the label "<label>"
|
||||||
And the path "<source_path>"
|
And the path "<source_path>"
|
||||||
@@ -15,8 +16,9 @@ Feature: Creating the source
|
|||||||
| db | /db | ["/backup/db"] |
|
| db | /db | ["/backup/db"] |
|
||||||
| temp | /tmp | ["/backup/tmp1", "/backup/tmp2"] |
|
| temp | /tmp | ["/backup/tmp1", "/backup/tmp2"] |
|
||||||
|
|
||||||
|
@fixture.injector
|
||||||
@fixture.in_memory_database
|
@fixture.in_memory_database
|
||||||
@fixture.backup_plan_repository
|
@fixture.backup_plan_service
|
||||||
Scenario Outline: Create an new unique backup plan
|
Scenario Outline: Create an new unique backup plan
|
||||||
Given the label "<label>"
|
Given the label "<label>"
|
||||||
And the path "<source_path>"
|
And the path "<source_path>"
|
||||||
|
|||||||
+18
-6
@@ -1,23 +1,35 @@
|
|||||||
from behave import fixture, use_fixture
|
from behave import fixture, use_fixture
|
||||||
|
from injector import Injector
|
||||||
|
|
||||||
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
|
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
|
||||||
|
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||||
|
from tui_rsync.infrastructure.configuration import TestingConfiguration, CurrentConfiguration
|
||||||
from tui_rsync.infrastructure.orm import InMemoryDatabaseManager
|
from tui_rsync.infrastructure.orm import InMemoryDatabaseManager
|
||||||
|
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
def setup_in_memory_database_manager(context):
|
def setup_in_memory_database_manager(context):
|
||||||
context.db = InMemoryDatabaseManager()
|
context.db = context.injector.get(InMemoryDatabaseManager)
|
||||||
yield context.db
|
yield context.db
|
||||||
|
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
def setup_backup_plan_repository(context):
|
def setup_backup_plan_service(context):
|
||||||
context.backup_plan_repository = BackupPlanRepository(context.db)
|
context.backup_plan_service = context.injector.get(BackupPlanService)
|
||||||
yield context.db
|
yield context.backup_plan_service
|
||||||
|
|
||||||
|
|
||||||
|
@fixture
|
||||||
|
def setup_injector_for_testing(context):
|
||||||
|
context.injector = Injector([TestingConfiguration()])
|
||||||
|
CurrentConfiguration.set_injector(context.injector)
|
||||||
|
yield context.injector
|
||||||
|
|
||||||
|
|
||||||
def before_tag(context, tag):
|
def before_tag(context, tag):
|
||||||
|
if tag == "fixture.injector":
|
||||||
|
use_fixture(setup_injector_for_testing, context)
|
||||||
if tag == "fixture.in_memory_database":
|
if tag == "fixture.in_memory_database":
|
||||||
use_fixture(setup_in_memory_database_manager, context)
|
use_fixture(setup_in_memory_database_manager, context)
|
||||||
if tag == "fixture.backup_plan_repository":
|
if tag == "fixture.backup_plan_service":
|
||||||
use_fixture(setup_backup_plan_repository, context)
|
use_fixture(setup_backup_plan_service, context)
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ def add_backup_plan(context):
|
|||||||
destinations=list(map(lambda path: Destination(path), context.destinations)),
|
destinations=list(map(lambda path: Destination(path), context.destinations)),
|
||||||
)
|
)
|
||||||
|
|
||||||
context.backup_plan_repository.add(context.backup_plan)
|
context.backup_plan_service.add(context.backup_plan)
|
||||||
|
|
||||||
context.backup_plan = context.backup_plan_repository.get_by_id(context.backup_plan.id)
|
context.backup_plan = context.backup_plan_service.get_by_id(context.backup_plan.id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
context.exception_raised = True
|
context.exception_raised = True
|
||||||
else:
|
else:
|
||||||
@@ -40,8 +40,8 @@ def add_backup_plan(context):
|
|||||||
@when('I delete the backup plan')
|
@when('I delete the backup plan')
|
||||||
def add_backup_plan(context):
|
def add_backup_plan(context):
|
||||||
try:
|
try:
|
||||||
context.deleted_result = context.backup_plan_repository.delete(context.backup_plan.id)
|
context.deleted_result = context.backup_plan_service.delete(context.backup_plan.id)
|
||||||
context.backup_plan = context.backup_plan_repository.get_by_id(context.backup_plan.id)
|
context.backup_plan = context.backup_plan_service.get_by_id(context.backup_plan.id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
context.exception_raised = True
|
context.exception_raised = True
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from .user_data_paths import UserDataPaths
|
from .user_data_paths import UserDataPaths
|
||||||
from .current_configuration import CurrentConfiguration
|
from .current_configuration import CurrentConfiguration
|
||||||
from .configuration import Configuration
|
from .configuration import Configuration
|
||||||
|
from .testing_configuration import TestingConfiguration
|
||||||
|
|
||||||
__all__ = ['UserDataPaths', 'CurrentConfiguration', 'Configuration']
|
__all__ = ['UserDataPaths', 'CurrentConfiguration', 'Configuration', 'TestingConfiguration']
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from injector import singleton, inject, Injector, 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 GetAllBackupBackupPlansQuery
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
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.queries import GetAllBackupBackupPlansQuery
|
||||||
|
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort
|
||||||
|
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
|
||||||
|
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.orm import DatabaseManagerPort
|
||||||
|
from tui_rsync.core.shared_kernel.components.backup.application.service import BackupSyncService
|
||||||
|
from tui_rsync.core.shared_kernel.components.backup.application.service.backup_restore_service import \
|
||||||
|
BackupRestoreService
|
||||||
|
from tui_rsync.infrastructure.configuration import UserDataPaths
|
||||||
|
from tui_rsync.infrastructure.orm import InMemoryDatabaseManager
|
||||||
|
from tui_rsync.user_interface.cli.shared_kernel.components.prompts.applications.prompts import ChoosePromptFzf
|
||||||
|
|
||||||
|
|
||||||
|
class TestingConfiguration(Module):
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_user_data_paths(self) -> UserDataPathsPort:
|
||||||
|
return UserDataPaths()
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_database_manager(self) -> DatabaseManagerPort:
|
||||||
|
return InMemoryDatabaseManager()
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_backup_plan_repository(self, database_manager: DatabaseManagerPort) -> BackupPlanRepositoryPort:
|
||||||
|
return BackupPlanRepository(database_manager)
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_backup_plan_service(self, backup_plan_repository: BackupPlanRepositoryPort) -> BackupPlanService:
|
||||||
|
return BackupPlanService(backup_plan_repository)
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_remove_all_backup_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand:
|
||||||
|
return RemoveAllBackupBackupPlansCommand(database_manager)
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_get_all_backup_backup_plans_query(self, database_manager: DatabaseManagerPort) -> GetAllBackupBackupPlansQuery:
|
||||||
|
return GetAllBackupBackupPlansQuery(database_manager)
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_backup_sync_service(self, backup_plan_repository: BackupPlanRepositoryPort) -> BackupSyncService:
|
||||||
|
return BackupSyncService(backup_plan_repository)
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_backup_restore_service(self, backup_plan_repository: BackupPlanRepositoryPort) -> BackupRestoreService:
|
||||||
|
return BackupRestoreService(backup_plan_repository)
|
||||||
|
|
||||||
|
@provider
|
||||||
|
@singleton
|
||||||
|
def provide_choose_prompt_fzf(self) -> ChoosePromptFzf:
|
||||||
|
return ChoosePromptFzf()
|
||||||
Reference in New Issue
Block a user