コード例 #1
0
ファイル: test_conf.py プロジェクト: farahkhan10/Pythonfile5
    def test_config_with_non_package_relative_import(self):
        from pecan import configuration
        with tempfile.NamedTemporaryFile('wb', suffix='.py') as f:
            f.write(b_('\n'.join(['from . import variables'])))
            f.flush()
            configuration.Config({})

            try:
                configuration.conf_from_file(f.name)
            except (ValueError, SystemError, ImportError) as e:
                assert 'relative import' in str(e)
            else:
                raise AssertionError(
                    "A relative import-related error should have been raised")
コード例 #2
0
ファイル: test_conf.py プロジェクト: SvenDowideit/clearlinux
    def test_config_with_non_package_relative_import(self):
        from pecan import configuration
        with tempfile.NamedTemporaryFile('wb', suffix='.py') as f:
            f.write(b_('\n'.join(['from . import variables'])))
            f.flush()
            configuration.Config({})

            try:
                configuration.conf_from_file(f.name)
            except (ValueError, SystemError) as e:
                assert 'relative import' in str(e)
            else:
                raise AssertionError(
                    "A relative import-related error should have been raised"
                )
コード例 #3
0
ファイル: test_conf.py プロジェクト: farahkhan10/Pythonfile5
 def test_config_illegal_ids(self):
     from pecan import configuration
     conf = configuration.Config({})
     conf.update(
         configuration.conf_from_file(
             os.path.join(__here__,
                          'config_fixtures/bad/module_and_underscore.py')))
     self.assertEqual([], list(conf))
コード例 #4
0
ファイル: conftest.py プロジェクト: ktdreyer/prado
def app(request):
    _config = configuration.conf_from_file(config_file()).to_dict()
    config = deepcopy(_config)
    configuration.set_config(config, overwrite=True)

    # Set up a fake app
    app = TestApp(load_test_app(config))
    return app
コード例 #5
0
ファイル: test_conf.py プロジェクト: SvenDowideit/clearlinux
 def test_config_illegal_ids(self):
     from pecan import configuration
     conf = configuration.Config({})
     conf.update(configuration.conf_from_file(os.path.join(
         __here__,
         'config_fixtures/bad/module_and_underscore.py'
     )))
     self.assertEqual([], list(conf))
コード例 #6
0
ファイル: conftest.py プロジェクト: ahills/chacra
def reload_config():
    from pecan import configuration
    conf = configuration.conf_from_file(config_file())
    config = configuration.conf_from_file(config_file()).to_dict()

    # Add the appropriate connection string to the app config.
    config['sqlalchemy'] = {
        'url': '%s/%s' % (BIND, DBNAME),
        'encoding': 'utf-8',
        'poolclass': NullPool
    }

    configuration.set_config(
        config,
        overwrite=True
    )
    _db.init_model()
コード例 #7
0
def app(request):
    _config = configuration.conf_from_file(config_file()).to_dict()
    config = deepcopy(_config)
    configuration.set_config(config, overwrite=True)

    # Set up a fake app
    app = TestApp(load_test_app(config))
    return app
コード例 #8
0
class TestModel(object):

    config = configuration.conf_from_file(config_file()).to_dict()
    engine_url = config['sqlalchemy']['url']

    __db__ = None

    @classmethod
    def setup_class(cls):
        if TestModel.__db__ is None:
            TestModel.__db__ = 'paddles_test'

            # Bind and create the database tables
            pmodels.clear()

            db_engine = create_engine(cls.engine_url,
                                      encoding='utf-8',
                                      poolclass=NullPool)

            # AKA models.start()
            pmodels.Base.metadata.drop_all(db_engine)
            pmodels.Session.bind = db_engine
            pmodels.metadata.bind = pmodels.Session.bind

            pmodels.Base.metadata.create_all(db_engine)
            pmodels.commit()
            pmodels.clear()

    @classmethod
    def teardown_class(cls):
        pmodels.rollback()
        pmodels.clear()

    def setup(self):
        config = deepcopy(self.config)

        # Add the appropriate connection string to the app config.
        config['sqlalchemy'] = {
            'url': self.engine_url,
            'encoding': 'utf-8',
            'poolclass': NullPool
        }

        # Set up a fake app
        self.app = self.load_test_app(config)
        pmodels.start()

    def load_test_app(self, config):
        return load_test_app(config)

    def teardown(self):
        # Tear down and dispose the DB binding
        pmodels.rollback()
        pmodels.clear()
コード例 #9
0
def reload_config():
    from pecan import configuration
    config = configuration.conf_from_file(config_file()).to_dict()

    # Add the appropriate connection string to the app config.
    config['sqlalchemy'] = {
        'url': '%s/%s' % (BIND, DBNAME),
        'encoding': 'utf-8',
        'poolclass': NullPool
    }

    configuration.set_config(config, overwrite=True)
    _db.init_model()
コード例 #10
0
ファイル: conftest.py プロジェクト: ahills/chacra
def app(request):
    config = configuration.conf_from_file(config_file()).to_dict()

    # Add the appropriate connection string to the app config.
    config['sqlalchemy'] = {
        'url': '%s/%s' % (BIND, DBNAME),
        'encoding': 'utf-8',
        'poolclass': NullPool
    }

    # Set up a fake app
    app = TestApp(load_test_app(config))
    return app
コード例 #11
0
ファイル: conftest.py プロジェクト: angeiv/mita
def app(request):
    config = configuration.conf_from_file(config_file()).to_dict()

    # Add the appropriate connection string to the app config.
    config['sqlalchemy'] = {
        'url': '%s/%s' % (BIND, DBNAME),
        'encoding': 'utf-8',
        'poolclass': NullPool
    }

    # Set up a fake app
    app = TestApp(load_test_app(config))
    return app
コード例 #12
0
ファイル: test_conf.py プロジェクト: farahkhan10/Pythonfile5
    def test_update_set_default_config(self):
        """Update an empty configuration with the default values"""
        from pecan import configuration

        conf = configuration.initconf()
        conf.update(
            configuration.conf_from_file(
                os.path.join(__here__, 'config_fixtures/empty.py')))

        self.assertEqual(conf.app.root, None)
        self.assertEqual(conf.app.template_path, '')
        self.assertEqual(conf.app.static_root, 'public')

        self.assertEqual(conf.server.host, '0.0.0.0')
        self.assertEqual(conf.server.port, '8080')
コード例 #13
0
ファイル: conftest.py プロジェクト: STEI-ITB/roseph
def app(request):
    config = configuration.conf_from_file(config_file()).to_dict()

    # Add the appropriate connection string to the app config.
    config['sqlalchemy'] = {
        'url': '%s/%s' % (BIND, DBNAME),
        'echo':          True,
        'echo_pool':     True,
        'pool_recycle':  3600,
        'encoding':      'utf-8'
    }

    # Set up a fake app
    app = TestApp(load_test_app(config))
    return app
コード例 #14
0
ファイル: test_conf.py プロジェクト: SvenDowideit/clearlinux
    def test_update_set_default_config(self):
        """Update an empty configuration with the default values"""
        from pecan import configuration

        conf = configuration.initconf()
        conf.update(configuration.conf_from_file(os.path.join(
            __here__,
            'config_fixtures/empty.py'
        )))

        self.assertEqual(conf.app.root, None)
        self.assertEqual(conf.app.template_path, '')
        self.assertEqual(conf.app.static_root, 'public')

        self.assertEqual(conf.server.host, '0.0.0.0')
        self.assertEqual(conf.server.port, '8080')
コード例 #15
0
def session(connection, request):
    """Creates a new database session for a test."""
    _config = configuration.conf_from_file(config_file()).to_dict()
    config = deepcopy(_config)

    # Add the appropriate connection string to the app config.
    config['sqlalchemy_w'] = {
        'url': '%s/%s' % (BIND, DBNAME),
        'encoding': 'utf-8',
        'poolclass': NullPool
    }

    config['sqlalchemy_ro'] = {
        'url': '%s/%s' % (BIND, DBNAME),
        'encoding': 'utf-8',
        'poolclass': NullPool
    }

    connection.start()

    def teardown():
        from sqlalchemy.engine import reflection

        # Tear down and dispose the DB binding
        connection.clear()

        # start a transaction
        engine = conf.sqlalchemy_w.engine
        conn = engine.connect()
        trans = conn.begin()

        inspector = reflection.Inspector.from_engine(engine)

        # gather all data first before dropping anything.
        # some DBs lock after things have been dropped in
        # a transaction.
        conn.execute("TRUNCATE TABLE %s RESTART IDENTITY CASCADE" % (
            ', '.join(inspector.get_table_names())
        ))

        trans.commit()
        conn.close()

    request.addfinalizer(teardown)
    return connection
コード例 #16
0
def session(connection, request):
    """Creates a new database session for a test."""
    _config = configuration.conf_from_file(config_file()).to_dict()
    config = deepcopy(_config)

    # Add the appropriate connection string to the app config.
    config['sqlalchemy_w'] = {
        'url': '%s/%s' % (BIND, DBNAME),
        'encoding': 'utf-8',
        'poolclass': NullPool
    }

    config['sqlalchemy_ro'] = {
        'url': '%s/%s' % (BIND, DBNAME),
        'encoding': 'utf-8',
        'poolclass': NullPool
    }

    connection.start()

    def teardown():
        from sqlalchemy.engine import reflection

        # Tear down and dispose the DB binding
        connection.clear()

        # start a transaction
        engine = conf.sqlalchemy_w.engine
        conn = engine.connect()
        trans = conn.begin()

        inspector = reflection.Inspector.from_engine(engine)

        # gather all data first before dropping anything.
        # some DBs lock after things have been dropped in
        # a transaction.
        conn.execute("TRUNCATE TABLE %s RESTART IDENTITY CASCADE" %
                     (', '.join(inspector.get_table_names())))

        trans.commit()
        conn.close()

    request.addfinalizer(teardown)
    return connection
コード例 #17
0
ファイル: test_conf.py プロジェクト: farahkhan10/Pythonfile5
    def test_update_force_dict(self):
        """Update an empty configuration with the default values"""
        from pecan import configuration
        conf = configuration.initconf()
        conf.update(
            configuration.conf_from_file(
                os.path.join(__here__, 'config_fixtures/forcedict.py')))

        self.assertEqual(conf.app.root, None)
        self.assertEqual(conf.app.template_path, '')
        self.assertEqual(conf.app.static_root, 'public')

        self.assertEqual(conf.server.host, '0.0.0.0')
        self.assertEqual(conf.server.port, '8080')

        self.assertTrue(isinstance(conf.beaker, dict))
        self.assertEqual(conf.beaker['session.key'], 'key')
        self.assertEqual(conf.beaker['session.type'], 'cookie')
        self.assertEqual(conf.beaker['session.validate_key'],
                         '1a971a7df182df3e1dec0af7c6913ec7')
        self.assertEqual(conf.beaker.get('__force_dict__'), None)
コード例 #18
0
ファイル: test_conf.py プロジェクト: SvenDowideit/clearlinux
    def test_update_force_dict(self):
        """Update an empty configuration with the default values"""
        from pecan import configuration
        conf = configuration.initconf()
        conf.update(configuration.conf_from_file(os.path.join(
            __here__,
            'config_fixtures/forcedict.py'
        )))

        self.assertEqual(conf.app.root, None)
        self.assertEqual(conf.app.template_path, '')
        self.assertEqual(conf.app.static_root, 'public')

        self.assertEqual(conf.server.host, '0.0.0.0')
        self.assertEqual(conf.server.port, '8080')

        self.assertTrue(isinstance(conf.beaker, dict))
        self.assertEqual(conf.beaker['session.key'], 'key')
        self.assertEqual(conf.beaker['session.type'], 'cookie')
        self.assertEqual(
            conf.beaker['session.validate_key'],
            '1a971a7df182df3e1dec0af7c6913ec7'
        )
        self.assertEqual(conf.beaker.get('__force_dict__'), None)
コード例 #19
0
ファイル: storyboard.py プロジェクト: redhat-cip/managesf
        to_remove = set(included_ids) - set(wanted_included)
        for id in to_add:
            self.client.project_groups.update(id=pg.id).projects.put(id=id)
        for id in to_remove:
            self.client.project_groups.update(id=pg.id).projects.delete(id=id)

    def delete_project_groups(self, **kwargs):
        name = kwargs['name']
        self._set_client()
        pg = [
            p for p in self.client.project_groups.get_all(name=name)
            if p.name == name
        ]
        pg = pg[0]
        included_ids = [
            p.id for p in self.client.project_groups.get(
                id=pg.id).projects.get_all()
        ]
        for id in included_ids:
            self.client.project_groups.update(id=pg.id).projects.delete(id=id)
        self.client.project_groups.delete(id=pg.id)


if __name__ == '__main__':
    from pecan import configuration
    conf = configuration.conf_from_file('/etc/managesf/config.py')
    c = StoryboardOps(conf)
    c._set_client()
    # Warn there is a minimal name length for project name
    c.update_project('project1', 'the project p1')
コード例 #20
0
ファイル: test_conf.py プロジェクト: SvenDowideit/clearlinux
 def test_config_from_file(self):
     from pecan import configuration
     path = os.path.join(
         os.path.dirname(__file__), 'config_fixtures', 'config.py'
     )
     configuration.conf_from_file(path)
コード例 #21
0
ファイル: app.py プロジェクト: zongzw/octavia
def get_pecan_config():
    """Returns the pecan config."""
    filename = app_config.__file__.replace('.pyc', '.py')
    return pecan_configuration.conf_from_file(filename)
コード例 #22
0
ファイル: storyboard.py プロジェクト: redhat-cip/managesf
            if project:
                wanted_included.append(project[0].id)
        to_add = set(wanted_included) - set(included_ids)
        to_remove = set(included_ids) - set(wanted_included)
        for id in to_add:
            self.client.project_groups.update(id=pg.id).projects.put(id=id)
        for id in to_remove:
            self.client.project_groups.update(id=pg.id).projects.delete(id=id)

    def delete_project_groups(self, **kwargs):
        name = kwargs['name']
        self._set_client()
        pg = [p for p in self.client.project_groups.get_all(name=name)
              if p.name == name]
        pg = pg[0]
        included_ids = [
            p.id for p in
            self.client.project_groups.get(id=pg.id).projects.get_all()]
        for id in included_ids:
            self.client.project_groups.update(id=pg.id).projects.delete(id=id)
        self.client.project_groups.delete(id=pg.id)


if __name__ == '__main__':
    from pecan import configuration
    conf = configuration.conf_from_file('/etc/managesf/config.py')
    c = StoryboardOps(conf)
    c._set_client()
    # Warn there is a minimal name length for project name
    c.update_project('project1', 'the project p1')
コード例 #23
0
ファイル: test_conf.py プロジェクト: farahkhan10/Pythonfile5
 def test_config_from_file(self):
     from pecan import configuration
     path = os.path.join(os.path.dirname(__file__), 'config_fixtures',
                         'config.py')
     configuration.conf_from_file(path)
コード例 #24
0
ファイル: test_conf.py プロジェクト: pombredanne/pecan
 def test_config_from_file(self):
     path = os.path.join(os.path.dirname(__file__), "test_config", "config.py")
     conf = configuration.conf_from_file(path)
     self.assertTrue(conf.app.debug)
コード例 #25
0
ファイル: app.py プロジェクト: 100PercentIT/ceilometer
def get_pecan_config():
    # Set up the pecan configuration
    filename = api_config.__file__.replace('.pyc', '.py')
    return configuration.conf_from_file(filename)