Files
@ 177478f7d054
Branch filter:
Location: rattail-project/rattail/tests/__init__.py - annotation
177478f7d054
1.3 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.
177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 177478f7d054 |
import os
import warnings
from unittest import TestCase
from sqlalchemy import create_engine
from sqlalchemy.exc import SAWarning
from rattail.db import model
from rattail.db import Session
warnings.filterwarnings(
'ignore',
r"^Dialect sqlite\+pysqlite does \*not\* support Decimal objects natively\, "
"and SQLAlchemy must convert from floating point - rounding errors and other "
"issues may occur\. Please consider storing Decimal numbers as strings or "
"integers on this platform for lossless storage\.$",
SAWarning, r'^sqlalchemy\..*$')
class DataTestCase(TestCase):
engine_url = os.environ.get('RATTAIL_TEST_ENGINE_URL', 'sqlite://')
def setUp(self):
self.engine = create_engine(self.engine_url)
model.Base.metadata.create_all(bind=self.engine)
Session.configure(bind=self.engine)
self.session = Session()
def tearDown(self):
self.session.close()
Session.configure(bind=None)
model.Base.metadata.drop_all(bind=self.engine)
# # TODO: This doesn't seem to be necessary, hopefully that's good?
# for table in list(model.Base.metadata.sorted_tables):
# if table.name.startswith('batch.'):
# model.Base.metadata.remove(table)
# TODO: Unfortunately this *does* seem to be necessary...
model.Batch._rowclasses.clear()
|