本文整理汇总了Python中orator.orm.builder.Builder.get方法的典型用法代码示例。如果您正苦于以下问题:Python Builder.get方法的具体用法?Python Builder.get怎么用?Python Builder.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orator.orm.builder.Builder
的用法示例。
在下文中一共展示了Builder.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 get [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_chunk
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import get [as 别名]
def test_chunk(self):
builder = Builder(self.get_mock_query_builder())
results = [['foo1', 'foo2'], ['foo3'], []]
builder.for_page = mock.MagicMock(return_value=builder)
builder.get = mock.MagicMock(side_effect=results)
i = 0
for result in builder.chunk(2):
self.assertEqual(result, results[i])
i += 1
builder.for_page.assert_has_calls([
mock.call(1, 2),
mock.call(2, 2),
mock.call(3, 2)
])
示例3: test_first
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import get [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(
['*']
)
示例4: test_find_with_many
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import get [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']
)
示例5: test_find_or_fail_with_many_raises_model_not_found_exception
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import get [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']
)