Exemplo n.º 1
0
    def test_engine_from_config(self):
        dbapi = mock_dbapi

        config = \
            {'sqlalchemy.url': 'postgresql://*****:*****@somehost/test'\
             '?fooz=somevalue', 'sqlalchemy.pool_recycle': '50',
             'sqlalchemy.echo': 'true'}

        e = engine_from_config(config, module=dbapi, _initialize=False)
        assert e.pool._recycle == 50
        assert e.url \
            == url.make_url('postgresql://*****:*****@somehost/test?foo'
                            'z=somevalue')
        assert e.echo is True

        for param, values in [
            ('convert_unicode', ('true', 'false', 'force')),
            ('echo', ('true', 'false', 'debug')),
            ('echo_pool', ('true', 'false', 'debug')),
            ('use_native_unicode', ('true', 'false')),
        ]:
            for value in values:
                config = {
                        'sqlalchemy.url': 'postgresql://*****:*****@somehost/test',
                        'sqlalchemy.%s' % param : value
                }
                cfg = _coerce_config(config, 'sqlalchemy.')
                assert cfg[param] == {'true':True, 'false':False}.get(value, value)
Exemplo n.º 2
0
    def test_coerce_config(self):
        raw = r"""
[prefixed]
sqlalchemy.url=postgresql://scott:tiger@somehost/test?fooz=somevalue
sqlalchemy.convert_unicode=0
sqlalchemy.echo=false
sqlalchemy.echo_pool=1
sqlalchemy.max_overflow=2
sqlalchemy.pool_recycle=50
sqlalchemy.pool_size=2
sqlalchemy.pool_threadlocal=1
sqlalchemy.pool_timeout=10
[plain]
url=postgresql://scott:tiger@somehost/test?fooz=somevalue
convert_unicode=0
echo=0
echo_pool=1
max_overflow=2
pool_recycle=50
pool_size=2
pool_threadlocal=1
pool_timeout=10
"""
        ini = configparser.ConfigParser()
        ini.readfp(StringIO(raw))

        expected = {
            'url': 'postgresql://*****:*****@somehost/test?fooz=somevalue',
            'convert_unicode': 0,
            'echo': False,
            'echo_pool': True,
            'max_overflow': 2,
            'pool_recycle': 50,
            'pool_size': 2,
            'pool_threadlocal': True,
            'pool_timeout': 10,
            }

        prefixed = dict(ini.items('prefixed'))
        self.assert_(_coerce_config(prefixed, 'sqlalchemy.')
                     == expected)

        plain = dict(ini.items('plain'))
        self.assert_(_coerce_config(plain, '') == expected)
Exemplo n.º 3
0
    def test_coerce_config(self):
        raw = r"""
[prefixed]
sqlalchemy.url=postgresql://scott:tiger@somehost/test?fooz=somevalue
sqlalchemy.convert_unicode=0
sqlalchemy.echo=false
sqlalchemy.echo_pool=1
sqlalchemy.max_overflow=2
sqlalchemy.pool_recycle=50
sqlalchemy.pool_size=2
sqlalchemy.pool_threadlocal=1
sqlalchemy.pool_timeout=10
[plain]
url=postgresql://scott:tiger@somehost/test?fooz=somevalue
convert_unicode=0
echo=0
echo_pool=1
max_overflow=2
pool_recycle=50
pool_size=2
pool_threadlocal=1
pool_timeout=10
"""
        ini = configparser.ConfigParser()
        ini.readfp(StringIO(raw))

        expected = {
            "url": "postgresql://*****:*****@somehost/test?fooz=somevalue",
            "convert_unicode": 0,
            "echo": False,
            "echo_pool": True,
            "max_overflow": 2,
            "pool_recycle": 50,
            "pool_size": 2,
            "pool_threadlocal": True,
            "pool_timeout": 10,
        }

        prefixed = dict(ini.items("prefixed"))
        self.assert_(_coerce_config(prefixed, "sqlalchemy.") == expected)

        plain = dict(ini.items("plain"))
        self.assert_(_coerce_config(plain, "") == expected)
Exemplo n.º 4
0
    def test_engine_from_config(self):
        dbapi = mock_dbapi

        config = {
            "sqlalchemy.url": "postgresql://*****:*****@somehost/test" "?fooz=somevalue",
            "sqlalchemy.pool_recycle": "50",
            "sqlalchemy.echo": "true",
        }

        e = engine_from_config(config, module=dbapi, _initialize=False)
        assert e.pool._recycle == 50
        assert e.url == url.make_url("postgresql://*****:*****@somehost/test?foo" "z=somevalue")
        assert e.echo is True

        for param, values in [
            ("convert_unicode", ("true", "false", "force")),
            ("echo", ("true", "false", "debug")),
            ("echo_pool", ("true", "false", "debug")),
            ("use_native_unicode", ("true", "false")),
        ]:
            for value in values:
                config = {"sqlalchemy.url": "postgresql://*****:*****@somehost/test", "sqlalchemy.%s" % param: value}
                cfg = _coerce_config(config, "sqlalchemy.")
                assert cfg[param] == {"true": True, "false": False}.get(value, value)