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