mirror of https://gitlab.com/KKlochko/tui-rsync
parent
ecb495a22a
commit
6b247fbe4e
@ -1,23 +1,35 @@
|
||||
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.services.backup_plan_service import BackupPlanService
|
||||
from tui_rsync.infrastructure.configuration import TestingConfiguration, CurrentConfiguration
|
||||
from tui_rsync.infrastructure.orm import InMemoryDatabaseManager
|
||||
|
||||
|
||||
@fixture
|
||||
def setup_in_memory_database_manager(context):
|
||||
context.db = InMemoryDatabaseManager()
|
||||
context.db = context.injector.get(InMemoryDatabaseManager)
|
||||
yield context.db
|
||||
|
||||
|
||||
@fixture
|
||||
def setup_backup_plan_repository(context):
|
||||
context.backup_plan_repository = BackupPlanRepository(context.db)
|
||||
yield context.db
|
||||
def setup_backup_plan_service(context):
|
||||
context.backup_plan_service = context.injector.get(BackupPlanService)
|
||||
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):
|
||||
if tag == "fixture.injector":
|
||||
use_fixture(setup_injector_for_testing, context)
|
||||
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)
|
||||
if tag == "fixture.backup_plan_service":
|
||||
use_fixture(setup_backup_plan_service, context)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from .user_data_paths import UserDataPaths
|
||||
from .current_configuration import CurrentConfiguration
|
||||
from .configuration import Configuration
|
||||
from .testing_configuration import TestingConfiguration
|
||||
|
||||
__all__ = ['UserDataPaths', 'CurrentConfiguration', 'Configuration']
|
||||
__all__ = ['UserDataPaths', 'CurrentConfiguration', 'Configuration', 'TestingConfiguration']
|
||||
|
@ -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()
|
Loading…
Reference in new issue