def aiotest(): from aiorm import registry from aiorm.orm.query import statements as stmt driver.DummyCursor.return_many = [ [range(3), range(10, 13)], ] yield from registry.connect('/sample') groups = yield from (stmt.Select(sample.Group).join( sample.User).left_join( sample.UserPreference, sample.User.id == sample.UserPreference.user_id).where( Mock()).run()) yield from registry.disconnect('sample') groups = [group for group in groups] self.assertEqual(len(groups), 2) self.assertEqual(groups[0].to_dict(), { 'id': 1, 'created_at': 0, 'name': 2 }) self.assertEqual(groups[1].to_dict(), { 'id': 11, 'created_at': 10, 'name': 12 })
def aiotest(): from aiorm import registry from aiorm.orm.query import statements as stmt driver.DummyCursor.return_many = [[range(3), range(10, 13)], ] yield from registry.connect('/sample') groups = yield from (stmt.Select(sample.Group) .join(sample.User) .left_join(sample.UserPreference, sample.User.id == sample.UserPreference.user_id) .where(Mock()).run() ) yield from registry.disconnect('sample') groups = [group for group in groups] self.assertEqual(len(groups), 2) self.assertEqual(groups[0].to_dict(), {'id': 1, 'created_at': 0, 'name': 2}) self.assertEqual(groups[1].to_dict(), {'id': 11, 'created_at': 10, 'name': 12})
def aiotest(): from aiorm import registry from aiorm.orm.query.schema import CreateTable dummy_dialect = dialect.DummyCreateTableDialect() yield from registry.connect('/sample') yield from CreateTable(sample.Group).run() dummy_dialect.render_create_table.assert_called_once_with(sample.Group) # last query is a mock, we just ensure that a query has been # executed, not that the query is valid, this is a dialect test self.assertIsNotNone(driver.DummyCursor.last_query) yield from registry.disconnect('sample')
def aiotest(): from aiorm import registry from aiorm.orm import Transaction yield from registry.connect('/sample') transaction = Transaction('sample') self.assertIsInstance(transaction.driver, driver.DummyDriver) self.assertEqual(transaction.driver.database, 'sample') yield from registry.disconnect('sample')
def aiotest(): from aiorm import registry from aiorm.orm.query.schema import CreateTable dummy_dialect = dialect.DummyCreateTableDialect() yield from registry.connect('/sample') yield from CreateTable(sample.Group).run() dummy_dialect.render_sql.assert_called_once() # last query is a mock, we just ensure that a query has been # executed, not that the query is valid, this is a dialect test self.assertIsNotNone(driver.DummyCursor.last_query) yield from registry.disconnect('sample')
def aiotest(): from aiorm import registry from aiorm.orm import Transaction from aiorm.orm import interfaces yield from registry.connect('/sample') driver.DummyCursor.return_many = [[('one',), ('two',)]] transaction = yield from Transaction('sample').begin() result = yield from transaction.fetchall() self.assertEqual(result, [('one',), ('two',)]) yield from registry.disconnect('sample')
def aiotest(): from aiorm import registry from aiorm.orm import Transaction from aiorm.orm import interfaces yield from registry.connect('/sample') driver.DummyCursor.return_one = ['one'] transaction = yield from Transaction('sample').begin() result = yield from transaction.fetchone() self.assertEqual(result, 'one') yield from registry.disconnect('sample')
def aiotest(): from aiorm import registry from aiorm.orm.query.schema import CreateSchema dummy_dialect = dialect.DummyCreateTableDialect() yield from registry.connect('/sample') yield from CreateSchema('sample').run() dummy_dialect.render_sql.assert_called() # last query is a mock, we just ensure that at least, a query # has been executed, not that the query is valid, this is a # dialect test self.assertIsNotNone(driver.DummyCursor.last_query) yield from registry.disconnect('sample')
def aiotest(): from aiorm import registry from aiorm.orm.query import statements as stmt driver.DummyCursor.return_one = [range(3)] yield from registry.connect('/sample') group = yield from stmt.Get(sample.Group, 1).run() yield from registry.disconnect('sample') self.assertEqual(group.to_dict(), {'id': 1, 'created_at': 0, 'name': 2})
def aiotest(): from aiorm import registry from aiorm.orm import Transaction from aiorm.orm import interfaces yield from registry.connect('/sample') driver.DummyCursor.return_many = [[('one', ), ('two', )]] transaction = yield from Transaction('sample').begin() result = yield from transaction.fetchall() self.assertEqual(result, [('one', ), ('two', )]) yield from registry.disconnect('sample')
def aiotest(): from aiorm import registry from aiorm.orm import Transaction from aiorm.orm import interfaces yield from registry.connect('/sample') transaction = yield from Transaction('sample').begin() yield from transaction.execute('dummy_query') self.assertEqual(driver.DummyCursor.last_query, 'dummy_query') yield from registry.disconnect('sample')
def aiotest(): from aiorm import registry from aiorm.orm.query import statements as stmt driver.DummyCursor.return_one = [None] yield from registry.connect('/sample') groups = yield from stmt.Get(sample.Group, 1).where(Mock()).run() yield from registry.disconnect('sample') driver.DummyDriver.mock = driver.DummyCursor() self.assertIsNone(groups)
def aiotest(): from aiorm import registry from aiorm.orm.query import statements as stmt driver.DummyCursor.return_one = [range(3)] yield from registry.connect('/sample') group = yield from stmt.Get(sample.Group, 1).run() yield from registry.disconnect('sample') self.assertEqual(group.to_dict(), { 'id': 1, 'created_at': 0, 'name': 2 })
def aiotest(): from aiorm import registry from aiorm.orm import Transaction from aiorm.orm import interfaces yield from registry.connect('/sample') cursor = registry.get(interfaces.IDialect)() cursor.configure_mock(**{'render_rollback_transaction.return_value': 'rollback_transaction'}) transaction = yield from Transaction('sample').begin() yield from transaction.rollback() cursor.render_rollback_transaction.assert_called_once_with() self.assertEqual(driver.DummyCursor.last_query, 'rollback_transaction') yield from registry.disconnect('sample')
def aiotest(): from aiorm import registry from aiorm.orm import Transaction from aiorm.orm import interfaces yield from registry.connect('/sample') cursor = registry.get(interfaces.IDialect)() cursor.configure_mock( ** {'render_begin_transaction.return_value': 'begin_transaction'}) transaction = Transaction('sample') yield from transaction.begin() cursor.render_begin_transaction.assert_called_once_with() self.assertEqual(driver.DummyCursor.last_query, 'begin_transaction') yield from registry.disconnect('sample')
def aioTearDown(self): from aiorm import registry from aiorm.orm.dialect.postgresql import Dialect, CreateTableDialect registry.unregister(Dialect) registry.unregister(CreateTableDialect) yield from registry.disconnect('sample')