Exemplo n.º 1
0
 def test_get_runfolders_does_not_return_none_runfolder(self):
     # Adding a directory which does not conform to the runfolder pattern
     with_non_runfolder_dir = fake_directories + ["bar"]
     file_system_service = mock_file_system_service(with_non_runfolder_dir,
                                                    fake_projects)
     repo = FileSystemBasedRunfolderRepository(base_path="/foo",
                                               file_system_service=file_system_service)
     actual_runfolders = list(repo.get_runfolders())
     self.assertListEqual(self.expected_runfolders, actual_runfolders)
Exemplo n.º 2
0
class TestRunfolderRepository(unittest.TestCase):

    expected_runfolders = FAKE_RUNFOLDERS

    file_system_service = mock_file_system_service(fake_directories,
                                                   fake_projects)
    repo = FileSystemBasedRunfolderRepository(
        base_path="/foo", file_system_service=file_system_service)

    def test_get_runfolders(self):
        actual_runfolders = list(self.repo.get_runfolders())

        self.assertListEqual(self.expected_runfolders, actual_runfolders)

        for actual_runfolder in actual_runfolders:
            for expected_runfolder in self.expected_runfolders:
                if actual_runfolder == expected_runfolder:
                    self.assertListEqual(actual_runfolder.projects,
                                         expected_runfolder.projects)

    def test_get_runfolders_does_not_return_none_runfolder(self):
        # Adding a directory which does not conform to the runfolder pattern
        with_non_runfolder_dir = fake_directories + ["bar"]
        file_system_service = mock_file_system_service(with_non_runfolder_dir,
                                                       fake_projects)
        repo = FileSystemBasedRunfolderRepository(
            base_path="/foo", file_system_service=file_system_service)
        actual_runfolders = list(repo.get_runfolders())
        self.assertListEqual(self.expected_runfolders, actual_runfolders)

    def test_get_runfolder(self):
        runfolder_name = "160930_ST-E00216_0111_BH37CWALXX"
        actual_runfolder = self.repo.get_runfolder(runfolder_name)
        self.assertIsInstance(actual_runfolder, Runfolder)
        self.assertEqual(actual_runfolder.name, runfolder_name)
Exemplo n.º 3
0
def compose_application(config):
    """
    Instantiates all service, repos, etc which are then used by the application.
    The resulting dictionary can then be passed on to routes which instantiates the
    http handlers.
    :param config: a configuration instance
    :return: a dictionary with references to any relevant resources
    """
    runfolder_repo = FileSystemBasedRunfolderRepository(
        config["monitored_directory"])
    external_program_service = ExternalProgramService()

    db_connection_string = config["db_connection_string"]
    engine = create_engine(db_connection_string, echo=False)

    create_and_migrate_db(engine, db_connection_string)

    session_factory = scoped_session(sessionmaker())
    session_factory.configure(bind=engine)

    staging_repo = DatabaseBasedStagingRepository(
        session_factory=session_factory)

    staging_service = StagingService(
        external_program_service=external_program_service,
        runfolder_repo=runfolder_repo,
        staging_repo=staging_repo,
        staging_dir=config["staging_directory"],
        session_factory=session_factory)

    delivery_repo = DatabaseBasedDeliveriesRepository(
        session_factory=session_factory)

    delivery_service = MoverDeliveryService(
        external_program_service=external_program_service,
        staging_service=staging_service,
        delivery_repo=delivery_repo)

    return dict(config=config,
                runfolder_repo=runfolder_repo,
                external_program_service=external_program_service,
                staging_service=staging_service,
                delivery_service=delivery_service)
Exemplo n.º 4
0
def compose_application(config):
    """
    Instantiates all service, repos, etc which are then used by the application.
    The resulting dictionary can then be passed on to routes which instantiates the
    http handlers.
    :param config: a configuration instance
    :return: a dictionary with references to any relevant resources
    """
    def _assert_is_dir(directory):
        if not FileSystemService.isdir(directory):
            raise AssertionError("{} is not a directory".format(
                os.path.abspath(directory)))

    staging_dir = config['staging_directory']
    _assert_is_dir(staging_dir)

    runfolder_dir = config["runfolder_directory"]
    _assert_is_dir(runfolder_dir)

    project_links_directory = config["project_links_directory"]
    _assert_is_dir(project_links_directory)

    runfolder_repo = FileSystemBasedRunfolderRepository(runfolder_dir)
    project_repository = UnorganisedRunfolderProjectRepository(
        sample_repository=RunfolderProjectBasedSampleRepository())
    unorganised_runfolder_repo = FileSystemBasedUnorganisedRunfolderRepository(
        runfolder_dir, project_repository=project_repository)

    general_project_dir = config['general_project_directory']
    _assert_is_dir(general_project_dir)

    general_project_repo = GeneralProjectRepository(
        root_directory=general_project_dir)
    external_program_service = ExternalProgramService()

    db_connection_string = config["db_connection_string"]
    engine = create_engine(db_connection_string, echo=False)

    alembic_path = config["alembic_path"]
    create_and_migrate_db(engine, alembic_path, db_connection_string)

    session_factory = scoped_session(sessionmaker())
    session_factory.configure(bind=engine)

    staging_repo = DatabaseBasedStagingRepository(
        session_factory=session_factory)

    staging_service = StagingService(
        external_program_service=external_program_service,
        runfolder_repo=runfolder_repo,
        project_dir_repo=general_project_repo,
        staging_repo=staging_repo,
        staging_dir=staging_dir,
        project_links_directory=project_links_directory,
        session_factory=session_factory)

    delivery_repo = DatabaseBasedDeliveriesRepository(
        session_factory=session_factory)

    path_to_mover = config['path_to_mover']
    mover_delivery_service = MoverDeliveryService(
        external_program_service=external_program_service,
        staging_service=staging_service,
        delivery_repo=delivery_repo,
        session_factory=session_factory,
        path_to_mover=path_to_mover)

    dds_conf = config['dds_conf']
    dds_project_repo = DDSProjectRepository(session_factory=session_factory)
    dds_service = DDSService(external_program_service=external_program_service,
                             staging_service=staging_service,
                             staging_dir=staging_dir,
                             delivery_repo=delivery_repo,
                             dds_project_repo=dds_project_repo,
                             session_factory=session_factory,
                             dds_conf=dds_conf)

    delivery_sources_repo = DatabaseBasedDeliverySourcesRepository(
        session_factory=session_factory)
    runfolder_service = RunfolderService(runfolder_repo)

    delivery_service = DeliveryService(
        mover_service=mover_delivery_service,
        staging_service=staging_service,
        delivery_sources_repo=delivery_sources_repo,
        general_project_repo=general_project_repo,
        runfolder_service=runfolder_service,
        project_links_directory=project_links_directory)

    best_practice_analysis_service = BestPracticeAnalysisService(
        general_project_repo)

    organise_service = OrganiseService(
        runfolder_service=RunfolderService(unorganised_runfolder_repo))

    return dict(config=config,
                runfolder_repo=runfolder_repo,
                external_program_service=external_program_service,
                staging_service=staging_service,
                mover_delivery_service=mover_delivery_service,
                dds_service=dds_service,
                delivery_service=delivery_service,
                general_project_repo=general_project_repo,
                best_practice_analysis_service=best_practice_analysis_service,
                organise_service=organise_service)
Exemplo n.º 5
0
def compose_application(config):
    """
    Instantiates all service, repos, etc which are then used by the application.
    The resulting dictionary can then be passed on to routes which instantiates the
    http handlers.
    :param config: a configuration instance
    :return: a dictionary with references to any relevant resources
    """
    def _assert_is_dir(directory):
        if not FileSystemService.isdir(directory):
            raise AssertionError("{} is not a directory".format(directory))

    staging_dir = config['staging_directory']
    _assert_is_dir(staging_dir)

    runfolder_dir = config["runfolder_directory"]
    _assert_is_dir(runfolder_dir)

    runfolder_repo = FileSystemBasedRunfolderRepository(runfolder_dir)

    general_project_dir = config['general_project_directory']
    _assert_is_dir(general_project_dir)

    general_project_repo = GeneralProjectRepository(
        root_directory=general_project_dir)
    external_program_service = ExternalProgramService()

    db_connection_string = config["db_connection_string"]
    engine = create_engine(db_connection_string, echo=False)

    alembic_path = config["alembic_path"]
    create_and_migrate_db(engine, alembic_path, db_connection_string)

    session_factory = scoped_session(sessionmaker())
    session_factory.configure(bind=engine)

    staging_repo = DatabaseBasedStagingRepository(
        session_factory=session_factory)

    staging_service = StagingService(
        external_program_service=external_program_service,
        runfolder_repo=runfolder_repo,
        project_dir_repo=general_project_repo,
        staging_repo=staging_repo,
        staging_dir=staging_dir,
        session_factory=session_factory)

    delivery_repo = DatabaseBasedDeliveriesRepository(
        session_factory=session_factory)

    path_to_mover = config['path_to_mover']
    delivery_service = MoverDeliveryService(
        external_program_service=external_program_service,
        staging_service=staging_service,
        delivery_repo=delivery_repo,
        session_factory=session_factory,
        path_to_mover=path_to_mover)

    return dict(config=config,
                runfolder_repo=runfolder_repo,
                external_program_service=external_program_service,
                staging_service=staging_service,
                delivery_service=delivery_service)