예제 #1
0
    def get_app(self):

        # Get an as similar app as possible, tough note that we don't use the
        #  app service start method to start up the the application
        path_to_this_file = os.path.abspath(
            os.path.dirname(os.path.realpath(__file__)))
        app_svc = AppService.create(
            product_name="test_delivery_service",
            config_root="{}/../../config/".format(path_to_this_file))

        config = app_svc.config_svc
        composed_application = compose_application(config)
        routes = app_routes(**composed_application)

        if self.mock_delivery:

            def mock_delivery(cmd):
                project_id = f"snpseq{random.randint(0, 10**10):010d}"
                dds_output = f"""Current user: bio
    Project created with id: {project_id}
    User forskare was associated with Project {project_id} as Owner=True. An e-mail notification has not been sent.
    Invitation sent to [email protected]. The user should have a valid account to be added to a
    project"""
                log.debug(f"Mock is called with {cmd}")
                shell = False
                if any(cmd[0].endswith(delivery_prgm)
                       for delivery_prgm in ['dds', 'moverinfo', 'to_outbox']):
                    new_cmd = ['sleep', str(self.mock_duration)]

                    if cmd[0].endswith('dds') and 'project' in cmd:
                        new_cmd += ['&&', 'echo', f'"{dds_output}"']
                        new_cmd = " ".join(new_cmd)
                        shell = True
                else:
                    new_cmd = cmd

                log.debug(f"Running mocked {new_cmd}")
                p = Subprocess(new_cmd,
                               stdout=PIPE,
                               stderr=PIPE,
                               stdin=PIPE,
                               shell=shell)
                return Execution(pid=p.pid, process_obj=p)

            self.patcher = mock.patch(
                'delivery.services.external_program_service'
                '.ExternalProgramService.run',
                wraps=mock_delivery)

        return Application(routes)
예제 #2
0
    def get_app(self):

        # Get an as similar app as possible, tough note that we don't use the
        #  app service start method to start up the the application
        path_to_this_file = os.path.abspath(
            os.path.dirname(os.path.realpath(__file__)))
        app_svc = AppService.create(
            product_name="test_delivery_service",
            config_root="{}/../../config/".format(path_to_this_file))

        config = app_svc.config_svc

        composed_application = compose_application(config)
        # TODO Later swap the "real" delivery service here for mock one.

        return Application(app_routes(**composed_application))