Files
@ 177478f7d054
Branch filter:
Location: rattail-project/rattail/tests/db/test_util.py - annotation
177478f7d054
2.1 KiB
text/x-python
Database config/init overhaul.
This contains some not-very-atomic changes:
* Get rid of `get_session_class()` function and return to global `Session`
class approach.
* Primary database `Session` is now configured as part of command
initialization, by default.
* Make `config` object available to subcommands, and `Daemon` instances
(the beginning of the end for `edbob.config`!).
* Add `--stdout` and `--stderr` arguments to primary `Command`. These are
in turn made available to subcommands.
* Overhauled some subcommand logic per new patterns.
* Get rid of a few other random references to `edbob`.
* Added and improved several tests.
* Added ability to run tests using arbitrary database engine.
This contains some not-very-atomic changes:
* Get rid of `get_session_class()` function and return to global `Session`
class approach.
* Primary database `Session` is now configured as part of command
initialization, by default.
* Make `config` object available to subcommands, and `Daemon` instances
(the beginning of the end for `edbob.config`!).
* Add `--stdout` and `--stderr` arguments to primary `Command`. These are
in turn made available to subcommands.
* Overhauled some subcommand logic per new patterns.
* Get rid of a few other random references to `edbob`.
* Added and improved several tests.
* Added ability to run tests using arbitrary database engine.
0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 0c13de51b8e0 |
from unittest import TestCase
from sqlalchemy.pool import SingletonThreadPool, NullPool
from edbob.configuration import AppConfigParser
from rattail.db import util
class TestEngineConfig(TestCase):
def test_standard(self):
config = {
'sqlalchemy.url': 'sqlite://',
}
engine = util.engine_from_config(config)
self.assertEqual(str(engine.url), 'sqlite://')
self.assertTrue(isinstance(engine.pool, SingletonThreadPool))
def test_custom_poolclass(self):
config = {
'sqlalchemy.url': 'sqlite://',
'sqlalchemy.poolclass': 'sqlalchemy.pool:NullPool',
}
engine = util.engine_from_config(config)
self.assertEqual(str(engine.url), 'sqlite://')
self.assertTrue(isinstance(engine.pool, NullPool))
def test_get_engines_default(self):
config = AppConfigParser('rattail')
config.set('edbob.db', 'sqlalchemy.url', 'sqlite://')
engines = util.get_engines(config)
self.assertEqual(len(engines), 1)
self.assertEqual(str(engines['default'].url), 'sqlite://')
def test_get_engines_custom(self):
config = AppConfigParser('rattail')
config.set('edbob.db', 'keys', 'host, store')
config.set('edbob.db', 'host.url', 'sqlite:///rattail.host.sqlite')
config.set('edbob.db', 'store.url', 'sqlite:///rattail.store.sqlite')
config.set('edbob.db', 'store.poolclass', 'sqlalchemy.pool:SingletonThreadPool')
engines = util.get_engines(config)
self.assertEqual(len(engines), 2)
self.assertEqual(str(engines['host'].url), 'sqlite:///rattail.host.sqlite')
self.assertTrue(isinstance(engines['host'].pool, NullPool))
self.assertEqual(str(engines['store'].url), 'sqlite:///rattail.store.sqlite')
self.assertTrue(isinstance(engines['store'].pool, SingletonThreadPool))
def test_get_engines_none(self):
config = AppConfigParser('rattail')
config.set('edbob.db', 'unknown.url', 'sqlite://')
engines = util.get_engines(config)
self.assertEqual(len(engines), 0)
|