Exemplo n.º 1
0
def load_test_app(config=None, **kwargs):
    """
    Used for functional tests where you need to test your
    literal application and its integration with the framework.

    :param config: Can be a dictionary containing configuration, a string which
                    represents a (relative) configuration filename or ``None``
                    which will fallback to get the ``PECAN_CONFIG`` env
                    variable.

    returns a pecan.Pecan WSGI application wrapped in a webtest.TestApp
    instance.

    ::
        app = load_test_app('path/to/some/config.py')

        resp = app.get('/path/to/some/resource').status_int
        assert resp.status_int == 200

        resp = app.post('/path/to/some/resource', params={'param': 'value'})
        assert resp.status_int == 302

    Alternatively you could call ``load_test_app`` with no parameters if the
    environment variable is set ::

        app = load_test_app()

        resp = app.get('/path/to/some/resource').status_int
        assert resp.status_int == 200
    """
    return TestApp(load_app(config, **kwargs))
Exemplo n.º 2
0
 def setUp(self):
     c = dummy_conf()
     self.config = {
         'services': c.services,
         'gerrit': c.gerrit,
         'app': c.app,
         'admin': c.admin,
         'sqlalchemy': c.sqlalchemy,
         'auth': c.auth,
         'htpasswd': c.htpasswd,
         'managesf': c.managesf,
         'storyboard': c.storyboard,
         'policy': c.policy,
         'jenkins': c.jenkins,
         'nodepool': c.nodepool,
     }
     pol_file = tempfile.mkstemp()[1] + '.yaml'
     with open(pol_file, 'w') as p:
         yaml.dump(
             {
                 "managesf.node:get": "rule:any",
                 "managesf.node:create": "rule:any",
                 "is_morty": "username:morty",
                 "morty_api": "rule:is_morty"
             },
             p,
             default_flow_style=False)
     self.config['policy']['policy_file'] = pol_file
     self.app = TestApp(load_app(self.config))
Exemplo n.º 3
0
def load_test_app(config=None, **kwargs):
    """
    Used for functional tests where you need to test your
    literal application and its integration with the framework.

    :param config: Can be a dictionary containing configuration, a string which
                    represents a (relative) configuration filename or ``None``
                    which will fallback to get the ``PECAN_CONFIG`` env
                    variable.

    returns a pecan.Pecan WSGI application wrapped in a webtest.TestApp
    instance.

    ::
        app = load_test_app('path/to/some/config.py')

        resp = app.get('/path/to/some/resource').status_int
        assert resp.status_int == 200

        resp = app.post('/path/to/some/resource', params={'param': 'value'})
        assert resp.status_int == 302

    Alternatively you could call ``load_test_app`` with no parameters if the
    environment variable is set ::

        app = load_test_app()

        resp = app.get('/path/to/some/resource').status_int
        assert resp.status_int == 200
    """
    return TestApp(load_app(config, **kwargs))
    def take_action(self, parsed_args):
        config_data = web_config.get_config_dict(
            database_name=parsed_args.database,
            host=parsed_args.host,
            port=parsed_args.port,
        )
        app = load_app(config_data)

        # Add beaker session middleware so we can track where the user
        # is and navigate back to the same place as they change tabs.
        if not six.PY3:
            app = SessionMiddleware(app, config_data['beaker'])

        host = config_data['server']['host']
        port = int(config_data['server']['port'])
        srv = simple_server.make_server(host, port, app)
        if host == '0.0.0.0':
            self.log.info(
                'serving on 0.0.0.0:%s, view at http://127.0.0.1:%s',
                port,
                port,
            )
        else:
            self.log.info("serving on http://%s:%s", host, port)
        try:
            srv.serve_forever()
        except KeyboardInterrupt:
            # allow CTRL+C to shutdown
            pass
Exemplo n.º 5
0
    def take_action(self, parsed_args):
        config_data = web_config.get_config_dict(
            database_name=parsed_args.database,
            host=parsed_args.host,
            port=parsed_args.port,
        )
        app = load_app(config_data)

        # Add beaker session middleware so we can track where the user
        # is and navigate back to the same place as they change tabs.
        if not six.PY3:
            app = SessionMiddleware(app, config_data['beaker'])

        host = config_data['server']['host']
        port = int(config_data['server']['port'])
        srv = simple_server.make_server(host, port, app)
        if host == '0.0.0.0':
            self.log.info(
                'serving on 0.0.0.0:%s, view at http://127.0.0.1:%s',
                port, port,
            )
        else:
            self.log.info("serving on http://%s:%s", host, port)
        try:
            srv.serve_forever()
        except KeyboardInterrupt:
            # allow CTRL+C to shutdown
            pass
Exemplo n.º 6
0
def make_app():
    config = {
        'app': {
            'modules': ['blazar.api.v2'],
            'root': 'blazar.api.root.RootController',
            'enable_acl': True,
        }
    }
    # NOTE(sbauza): Fill Pecan config and call modules' path app.setup_app()
    app = pecan.load_app(config)
    return app
Exemplo n.º 7
0
def make_app():
    config = {
        'app': {
            'modules': ['climate.api.v2'],
            'root': 'climate.api.root.RootController',
            'enable_acl': True,
        }
    }
    # NOTE(sbauza): Fill Pecan config and call modules' path app.setup_app()
    app = pecan.load_app(config)
    return app
Exemplo n.º 8
0
 def setUp(self):
     c = dummy_conf()
     gen_rsa_key()
     config = {'managesf': c.managesf,
               'app': c.app,
               'auth': c.auth,
               'services': c.services,
               'sqlalchemy': c.sqlalchemy}
     # deactivate loggin that polute test output
     # even nologcapture option of nose effetcs
     # 'logging': c.logging}
     self.app = TestApp(load_app(config))
Exemplo n.º 9
0
def make_app():
    config = {
        'app': {
            'root': 'rally.aas.rest.controllers.root.RootController',
            'modules': ['rally.aas.rest'],
            'debug': CONF.debug,
        },
        'wsme': {
            'debug': CONF.debug,
        },
    }
    app = pecan.load_app(config)
    return app
Exemplo n.º 10
0
 def setUp(self):
     c = dummy_conf()
     gen_rsa_key()
     config = {'redmine': c.redmine,
               'gerrit': c.gerrit,
               'app': c.app,
               'auth': c.auth,
               'logout': c.logout,
               'sqlalchemy': c.sqlalchemy}
     # deactivate loggin that polute test output
     # even nologcapture option of nose effetcs
     # 'logging': c.logging}
     self.app = TestApp(load_app(config))
Exemplo n.º 11
0
Arquivo: app.py Projeto: Ch00k/rally
def make_app():
    config = {
        'app': {
            'root': 'rally.api.controllers.root.RootController',
            'modules': ['rally.api'],
            'debug': CONF.debug,
        },
        'wsme': {
            'debug': CONF.debug,
        },
    }
    app = pecan.load_app(config)
    return app
Exemplo n.º 12
0
 def setUp(self):
     c = dummy_conf()
     self.config = {'services': c.services,
                    'gerrit': c.gerrit,
                    'app': c.app,
                    'admin': c.admin,
                    'sqlalchemy': c.sqlalchemy,
                    'auth': c.auth,
                    'htpasswd': c.htpasswd,
                    'managesf': c.managesf,
                    'storyboard': c.storyboard,
                    'mysql': c.mysql,
                    'policy': c.policy, }
     self.app = TestApp(load_app(self.config))
Exemplo n.º 13
0
def make_app():
    config = {
        'app': {
            'modules': ['blazar.api.v2'],
            'root': 'blazar.api.root.RootController',
            'enable_acl': True,
        }
    }
    # NOTE(sbauza): Fill Pecan config and call modules' path app.setup_app()
    app = pecan.load_app(config)
    # WSGI middleware for debugging
    if CONF.log_exchange:
        app = debug.Debug.factory(config)(app)
    return app
Exemplo n.º 14
0
 def setUp(self):
     c = dummy_conf()
     self.config = {
         'services': c.services,
         'gerrit': c.gerrit,
         'app': c.app,
         'admin': c.admin,
         'sqlalchemy': c.sqlalchemy,
         'auth': c.auth,
         'htpasswd': c.htpasswd,
         'managesf': c.managesf,
         'storyboard': c.storyboard,
         'mysql': c.mysql,
         'policy': c.policy,
     }
     self.app = TestApp(load_app(self.config))
Exemplo n.º 15
0
    def setUpClass(cls):
        super(AuthMiddlewareTest, cls).setUpClass()
        tests_config.parse_args()

        opts = cfg.CONF.api_pecan
        cfg_dict = {
            'app': {
                'root': opts.root,
                'template_path': opts.template_path,
                'modules': opts.modules,
                'debug': opts.debug,
                'auth_enable': opts.auth_enable,
                'errors': {'__force_dict__': True}
            }
        }

        # TODO(manas) : register action types here for now. RunnerType registration can be moved
        # to posting to /runnertypes but that implies implementing POST.
        runners_registrar.register_runner_types()

        cls.app = TestApp(auth.AuthMiddleware(load_app(cfg_dict)))
Exemplo n.º 16
0
def load_test_app(config):
    """
    Used for functional tests where you need to test your
    literal application and its integration with the framework.

    :param config: Can be a dictionary containing configuration, or a string
                   which represents a (relative) configuration filename.

    returns a pecan.Pecan WSGI application wrapped in a webtest.TestApp
    instance.

    ::
        app = load_test_app('path/to/some/config.py')

        resp = app.get('/path/to/some/resource').status_int
        assert resp.status_int == 200

        resp = app.post('/path/to/some/resource', params={'param': 'value'})
        assert resp.status_int == 302
    """
    return TestApp(load_app(config))
Exemplo n.º 17
0
Arquivo: base.py Projeto: Itxaka/st2
    def setUpClass(cls):
        super(AuthMiddlewareTest, cls).setUpClass()
        tests_config.parse_args()

        opts = cfg.CONF.api_pecan
        cfg_dict = {
            'app': {
                'root': opts.root,
                'template_path': opts.template_path,
                'modules': opts.modules,
                'debug': opts.debug,
                'auth_enable': opts.auth_enable,
                'errors': {
                    '__force_dict__': True
                }
            }
        }

        # TODO(manas) : register action types here for now. RunnerType registration can be moved
        # to posting to /runnertypes but that implies implementing POST.
        runners_registrar.register_runner_types()

        cls.app = TestApp(auth.AuthMiddleware(load_app(cfg_dict)))
Exemplo n.º 18
0
    def take_action(self, parsed_args):
        config_data = web_config.get_config_dict(
            database_name=parsed_args.database,
            host=parsed_args.host,
            port=parsed_args.port,
        )
        app = load_app(config_data)

        host = config_data['server']['host']
        port = int(config_data['server']['port'])
        srv = simple_server.make_server(host, port, app)
        if host == '0.0.0.0':
            self.log.info(
                'serving on 0.0.0.0:%s, view at http://127.0.0.1:%s',
                port, port,
            )
        else:
            self.log.info("serving on http://%s:%s", host, port)
        try:
            srv.serve_forever()
        except KeyboardInterrupt:
            # allow CTRL+C to shutdown
            pass
Exemplo n.º 19
0
    def take_action(self, parsed_args):
        config_data = web_config.get_config_dict(
            database_name=parsed_args.database,
            host=parsed_args.host,
            port=parsed_args.port,
        )
        app = load_app(config_data)

        host = config_data['server']['host']
        port = int(config_data['server']['port'])
        srv = simple_server.make_server(host, port, app)
        if host == '0.0.0.0':
            self.log.info(
                'serving on 0.0.0.0:%s, view at http://127.0.0.1:%s',
                port,
                port,
            )
        else:
            self.log.info("serving on http://%s:%s", host, port)
        try:
            srv.serve_forever()
        except KeyboardInterrupt:
            # allow CTRL+C to shutdown
            pass
Exemplo n.º 20
0
 def setUp(self):
     c = dummy_conf()
     self.config = {'services': c.services,
                    'gerrit': c.gerrit,
                    'app': c.app,
                    'admin': c.admin,
                    'sqlalchemy': c.sqlalchemy,
                    'auth': c.auth,
                    'htpasswd': c.htpasswd,
                    'managesf': c.managesf,
                    'storyboard': c.storyboard,
                    'policy': c.policy,
                    'jenkins': c.jenkins,
                    'nodepool': c.nodepool, }
     pol_file = tempfile.mkstemp()[1] + '.yaml'
     with open(pol_file, 'w') as p:
         yaml.dump(
             {"managesf.node:get": "rule:any",
              "managesf.node:create": "rule:any",
              "is_morty": "username:morty",
              "morty_api": "rule:is_morty"},
             p, default_flow_style=False)
     self.config['policy']['policy_file'] = pol_file
     self.app = TestApp(load_app(self.config))
Exemplo n.º 21
0
 def load_app(self):
     from pecan import load_app
     return load_app(self.args.config_file)
Exemplo n.º 22
0
# See the License for the specific language governing permissions and
# limitations under the License.

from pecan import load_app
from oslo.config import cfg

from st2auth import config  # noqa
from st2common import log as logging
from st2common.models import db


cfg.CONF(args=['--config-file', '/etc/st2/st2.conf'])

logging.setup(cfg.CONF.auth.logging)

username = cfg.CONF.database.username if hasattr(cfg.CONF.database, 'username') else None
password = cfg.CONF.database.password if hasattr(cfg.CONF.database, 'password') else None
db.db_setup(cfg.CONF.database.db_name, cfg.CONF.database.host, cfg.CONF.database.port,
            username=username, password=password)

pecan_config = {
    'app': {
        'root': 'st2auth.controllers.root.RootController',
        'modules': ['st2auth'],
        'debug': cfg.CONF.auth.debug,
        'errors': {'__force_dict__': True}
    }
}

application = load_app(pecan_config)
Exemplo n.º 23
0
 def load_app(self):
     from pecan import load_app
     return load_app(self.args.config_file)
Exemplo n.º 24
0
 def load_app(self):
     from pecan import load_app
     if not os.path.isfile(self.args.config_file):
         raise RuntimeError('`%s` is not a file.' % self.args.config_file)
     return load_app(self.args.config_file)
Exemplo n.º 25
0
        new_admin_user = models.AdminUser(
            username=_args.username,
            password=password)
        self.model_commit()
        out("generated password ==> %s" % password)


if __name__ == '__main__':
    def config_file():
        import os
        from os.path import dirname
        _file = os.path.abspath(__file__)
        parent_dir = dirname(dirname(dirname(_file)))
        return os.path.join(parent_dir, 'config.py')

    load_app(config_file())
    models.init_model()
    out("BUILDING SCHEMA")
    try:
        out("STARTING A TRANSACTION...")
        models.start()
        password = os.urandom(30).encode('base64')[:12]
        new_admin_user = models.AdminUser(
            username=_args.username,
            password=password)
        models.commit()
        out("generated password ==> %s" % password)

    except:
        models.rollback()
        out("ROLLING BACK... ")