def includeme(config): from aiorm.driver.postgresql.aiopg import Driver from aiorm.orm.dialect.postgresql import Dialect config.add_tween('pyramid_aiorm.transaction.tween_factory', under=EXCVIEW) settings = {key:val for key, val in config.get_settings().items() if key.startswith('aiorm.')} driver_cls = settings.pop('aiorm.driver', 'aiorm.driver.postgresql.aiopg') driver_cls = getattr(importlib.import_module(driver_cls), 'Driver') registry.register(driver_cls) dialect = settings.pop('aiorm.driver', 'aiorm.orm.dialect.postgresql') dialect = importlib.import_module(dialect) dialect_cls = getattr(dialect, 'Dialect') registry.register(dialect_cls) dialect_cls = getattr(dialect, 'CreateTableDialect') registry.register(dialect_cls) ignored = len('aiorm.db.') for key, url in settings.items(): if not key.startswith('aiorm.db.'): continue name = key[ignored:] yield from registry.connect(url, name=name) scanmods = aslist(settings['aiorm.scan'], flatten=True) for scanmod in scanmods: orm.scan(scanmod)
def test_scan_many(self): from aiorm import orm import_module = mock.patch('importlib.import_module', new=self._mock_import_module) import_module.start() self.imported_module = [] orm.scan('mod1', 'mod2') self.assertEqual(self.imported_module, ['mod1', 'mod2']) import_module.stop() delattr(self, 'imported_module')
def test_scan(self): from aiorm import orm from aiorm.orm.declaration.meta import db orm.scan('aiorm.tests.fixtures.sample') from aiorm.tests.fixtures import sample self.assertEqual(db, {'sample': {'user': sample.User, 'group': sample.Group, 'user_group': sample.UserGroup, 'preference': sample.Preference, 'user_preference': sample.UserPreference, }}) db.pop('sample')
def test_scan(self): from aiorm import orm from aiorm.orm.declaration.meta import db orm.scan('aiorm.tests.fixtures.sample') from aiorm.tests.fixtures import sample self.assertEqual( db, { 'sample': { 'user': sample.User, 'group': sample.Group, 'user_group': sample.UserGroup, 'preference': sample.Preference, 'user_preference': sample.UserPreference, } }) db.pop('sample')
def setUpClass(cls): orm.scan('aiorm.tests.fixtures.sample')