本文整理汇总了Python中orator.orm.builder.Builder.find方法的典型用法代码示例。如果您正苦于以下问题:Python Builder.find方法的具体用法?Python Builder.find怎么用?Python Builder.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orator.orm.builder.Builder
的用法示例。
在下文中一共展示了Builder.find方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_method
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import find [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)
示例2: test_find_or_new_model_found
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import find [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)
示例3: test_find_or_new_model_not_found
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import find [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)
示例4: test_find_with_many
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import find [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']
)