本文整理汇总了Python中orator.orm.builder.Builder.set_model方法的典型用法代码示例。如果您正苦于以下问题:Python Builder.set_model方法的具体用法?Python Builder.set_model怎么用?Python Builder.set_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orator.orm.builder.Builder
的用法示例。
在下文中一共展示了Builder.set_model方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_does_not_eager_relations_when_no_results_are_returned
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def test_get_does_not_eager_relations_when_no_results_are_returned(self):
flexmock(Builder)
builder = Builder(self.get_mock_query_builder())
builder.should_receive('get_models').with_args(['foo']).and_return(['bar'])
builder.should_receive('eager_load_relations').with_args(['bar']).and_return([])
builder.set_model(self.get_mock_model())
builder.get_model().new_collection = mock.MagicMock(return_value=Collection([]))
results = builder.get(['foo'])
self.assertEqual([], results.all())
builder.get_model().new_collection.assert_called_with([])
示例2: test_find_method
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def test_find_method(self):
builder = Builder(self.get_mock_query_builder())
builder.set_model(self.get_mock_model())
builder.get_query().where = mock.MagicMock()
builder.first = mock.MagicMock(return_value='baz')
result = builder.find('bar', ['column'])
builder.get_query().where.assert_called_once_with(
'foo_table.foo', '=', 'bar'
)
self.assertEqual('baz', result)
示例3: test_find_or_new_model_found
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def test_find_or_new_model_found(self):
model = self.get_mock_model()
model.find_or_new = mock.MagicMock(return_value='baz')
builder = Builder(self.get_mock_query_builder())
builder.set_model(model)
builder.get_query().where = mock.MagicMock()
builder.first = mock.MagicMock(return_value='baz')
expected = model.find_or_new('bar', ['column'])
result = builder.find('bar', ['column'])
builder.get_query().where.assert_called_once_with(
'foo_table.foo', '=', 'bar'
)
self.assertEqual(expected, result)
示例4: test_first_or_fail_raises_model_not_found_exception
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def test_first_or_fail_raises_model_not_found_exception(self):
model = self.get_mock_model()
builder = Builder(self.get_mock_query_builder())
builder.set_model(model)
builder.first = mock.MagicMock(return_value=None)
self.assertRaises(
ModelNotFound,
builder.first_or_fail,
['column']
)
builder.first.assert_called_once_with(
['column']
)
示例5: test_find_or_new_model_not_found
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def test_find_or_new_model_not_found(self):
model = self.get_mock_model()
model.find_or_new = mock.MagicMock(return_value=self.get_mock_model())
builder = Builder(self.get_mock_query_builder())
builder.set_model(model)
builder.get_query().where = mock.MagicMock()
builder.first = mock.MagicMock(return_value=None)
result = model.find_or_new('bar', ['column'])
find_result = builder.find('bar', ['column'])
builder.get_query().where.assert_called_once_with(
'foo_table.foo', '=', 'bar'
)
self.assertIsNone(find_result)
self.assertIsInstance(result, Model)
示例6: test_get_relation_properly_sets_nested_relationships
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def test_get_relation_properly_sets_nested_relationships(self):
flexmock(Builder)
builder = Builder(flexmock(QueryBuilder(None, None, None)))
model = flexmock(Model())
relation = flexmock()
model.set_relation('orders', relation)
builder.set_model(model)
relation_query = flexmock()
relation.should_receive('get_query').and_return(relation_query)
relation_query.should_receive('with_').once().with_args({'lines': None, 'lines.details': None})
builder.set_eager_loads({
'orders': None,
'orders.lines': None,
'orders.lines.details': None
})
relation = builder.get_relation('orders')
示例7: test_first
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def test_first(self):
model = self.get_mock_model()
builder = Builder(self.get_mock_query_builder())
builder.set_model(model)
builder.take = mock.MagicMock(return_value=builder)
builder.get = mock.MagicMock(return_value=Collection(['bar']))
result = builder.first()
self.assertEqual('bar', result)
builder.take.assert_called_once_with(
1
)
builder.get.assert_called_once_with(
['*']
)
示例8: test_find_with_many
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def test_find_with_many(self):
model = self.get_mock_model()
builder = Builder(self.get_mock_query_builder())
builder.set_model(model)
builder.get_query().where_in = mock.MagicMock()
builder.get = mock.MagicMock(return_value='baz')
result = builder.find([1, 2], ['column'])
self.assertEqual('baz', result)
builder.get_query().where_in.assert_called_once_with(
'foo_table.foo', [1, 2]
)
builder.get.assert_called_once_with(
['column']
)
示例9: test_find_or_fail_with_many_raises_model_not_found_exception
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def test_find_or_fail_with_many_raises_model_not_found_exception(self):
model = self.get_mock_model()
builder = Builder(self.get_mock_query_builder())
builder.set_model(model)
builder.get_query().where_in = mock.MagicMock()
builder.get = mock.MagicMock(return_value=Collection([1]))
self.assertRaises(
ModelNotFound,
builder.find_or_fail,
[1, 2],
['column']
)
builder.get_query().where_in.assert_called_once_with(
'foo_table.foo', [1, 2]
)
builder.get.assert_called_once_with(
['column']
)
示例10: test_get_models_hydrates_models
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def test_get_models_hydrates_models(self):
builder = Builder(self.get_mock_query_builder())
records = [{
'name': 'john', 'age': 26
}, {
'name': 'jane', 'age': 28
}]
builder.get_query().get = mock.MagicMock(return_value=records)
model = self.get_mock_model()
builder.set_model(model)
model.get_connection_name = mock.MagicMock(return_value='foo_connection')
model.hydrate = mock.MagicMock(return_value=Collection(['hydrated']))
models = builder.get_models(['foo'])
self.assertEqual(models.all(), ['hydrated'])
model.get_table.assert_called_once_with()
model.get_connection_name.assert_called_once_with()
model.hydrate.assert_called_once_with(
records, 'foo_connection'
)
示例11: _get_relation_arguments
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def _get_relation_arguments(self):
flexmock(Model).should_receive('_boot_columns').and_return(['name'])
parent = flexmock(Model())
parent.should_receive('get_key').and_return(1)
parent.should_receive('get_created_at_column').and_return('created_at')
parent.should_receive('get_updated_at_column').and_return('updated_at')
query = flexmock(QueryBuilder(MockConnection().prepare_mock(), QueryGrammar(), QueryProcessor()))
flexmock(Builder)
builder = Builder(query)
builder.should_receive('get_query').and_return(query)
related = flexmock(Model())
builder.set_model(related)
builder.should_receive('get_model').and_return(related)
related.should_receive('new_query').and_return(builder)
related.should_receive('get_key_name').and_return('id')
related.should_receive('get_table').and_return('roles')
related.should_receive('new_pivot').replace_with(lambda *args: Pivot(*args))
builder.get_query().should_receive('join').at_least().once().with_args('user_role', 'roles.id', '=', 'user_role.role_id')
builder.should_receive('where').at_least().once().with_args('user_role.user_id', '=', 1)
return builder, parent, 'user_role', 'user_id', 'role_id', 'relation_id'
示例12: _get_relation_arguments
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import set_model [as 别名]
def _get_relation_arguments(self):
parent = flexmock(Model())
parent.should_receive('get_morph_name').and_return(parent.__class__.__name__)
parent.should_receive('get_key').and_return(1)
parent.should_receive('get_created_at_column').and_return('created_at')
parent.should_receive('get_updated_at_column').and_return('updated_at')
query = flexmock(QueryBuilder(MockConnection().prepare_mock(), QueryGrammar(), QueryProcessor()))
flexmock(Builder)
builder = Builder(query)
builder.should_receive('get_query').and_return(query)
related = flexmock(Model())
builder.set_model(related)
builder.should_receive('get_model').and_return(related)
related.should_receive('get_key_name').and_return('id')
related.should_receive('get_table').and_return('tags')
related.should_receive('get_morph_name').and_return(parent.__class__.__name__)
builder.get_query().should_receive('join').once().with_args('taggables', 'tags.id', '=', 'taggables.tag_id')
builder.should_receive('where').once().with_args('taggables.taggable_id', '=', 1)
builder.should_receive('where').once().with_args('taggables.taggable_type', parent.__class__.__name__)
return builder, parent, 'taggable', 'taggables', 'taggable_id', 'tag_id', 'relation_name', False