Ejemplo n.º 1
0
    def setUp(self):
        # NOTE setting echo to true is very useful to se which sql statements get
        # executed, but since it fills up the logs a lot it's been disabled by
        # default here.
        engine = create_engine('sqlite:///:memory:', echo=False)
        SQLAlchemyBase.metadata.create_all(engine)

        # Throw some data into the in-memory db
        session_factory = sessionmaker()
        session_factory.configure(bind=engine)

        self.session = session_factory()

        self.delivery_order_1 = DeliveryOrder(
            delivery_source='/foo/source',
            delivery_project='bar',
            delivery_status=DeliveryStatus.pending,
            staging_order_id=1)

        self.session.add(self.delivery_order_1)

        self.session.commit()

        # Prep the repo
        self.delivery_repo = DatabaseBasedDeliveriesRepository(session_factory)
Ejemplo n.º 2
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)
Ejemplo 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
    """
    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)
Ejemplo n.º 4
0
class TestDeliveryRepository(unittest.TestCase):
    def setUp(self):
        # NOTE setting echo to true is very useful to se which sql statements get
        # executed, but since it fills up the logs a lot it's been disabled by
        # default here.
        engine = create_engine('sqlite:///:memory:', echo=False)
        SQLAlchemyBase.metadata.create_all(engine)

        # Throw some data into the in-memory db
        session_factory = sessionmaker()
        session_factory.configure(bind=engine)

        self.session = session_factory()

        self.delivery_order_1 = DeliveryOrder(
            delivery_source='/foo/source',
            delivery_project='bar',
            delivery_status=DeliveryStatus.pending,
            staging_order_id=1)

        self.session.add(self.delivery_order_1)

        self.session.commit()

        # Prep the repo
        self.delivery_repo = DatabaseBasedDeliveriesRepository(session_factory)

    def test_get_delivery_orders_for_source(self):
        actual = self.delivery_repo.get_delivery_orders_for_source(
            '/foo/source')
        self.assertEqual(len(actual), 1)
        self.assertEqual(actual[0].id, self.delivery_order_1.id)

    def test_get_delivery_order_by_id(self):
        actual = self.delivery_repo.get_delivery_order_by_id(1)
        self.assertEqual(actual.id, self.delivery_order_1.id)

    def test_get_delivery_orders(self):
        actual = self.delivery_repo.get_delivery_orders()
        self.assertEqual(len(actual), 1)
        self.assertEqual(actual[0].id, self.delivery_order_1.id)

    def test_create_delivery_order(self):

        actual = self.delivery_repo.create_delivery_order(
            delivery_source='/foo/source2',
            delivery_project='bar2',
            delivery_status=DeliveryStatus.pending,
            staging_order_id=2)

        self.assertEqual(actual.id, 2)
        self.assertEqual(actual.delivery_source, '/foo/source2')
        self.assertEqual(actual.delivery_project, 'bar2')
        self.assertEqual(actual.delivery_status, DeliveryStatus.pending)
        self.assertEqual(actual.staging_order_id, 2)

        # Check that the object has been committed, i.e. there are no 'dirty' objects in session
        self.assertEqual(len(self.session.dirty), 0)
        order_from_session = self.session.query(DeliveryOrder).filter(
            DeliveryOrder.id == actual.id).one()
        self.assertEqual(order_from_session.id, actual.id)
Ejemplo 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)