当前位置: 首页>>代码示例>>Python>>正文


Python Builder.first方法代码示例

本文整理汇总了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']
        )
开发者ID:southwestjiaotongunivercity,项目名称:orator,代码行数:13,代码来源:test_builder.py

示例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)
开发者ID:southwestjiaotongunivercity,项目名称:orator,代码行数:14,代码来源:test_builder.py

示例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)
开发者ID:southwestjiaotongunivercity,项目名称:orator,代码行数:18,代码来源:test_builder.py

示例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']
        )
开发者ID:southwestjiaotongunivercity,项目名称:orator,代码行数:18,代码来源:test_builder.py

示例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)
开发者ID:southwestjiaotongunivercity,项目名称:orator,代码行数:19,代码来源:test_builder.py

示例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(
            ['*']
        )
开发者ID:southwestjiaotongunivercity,项目名称:orator,代码行数:20,代码来源:test_builder.py

示例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'))
开发者ID:southwestjiaotongunivercity,项目名称:orator,代码行数:8,代码来源:test_builder.py


注:本文中的orator.orm.builder.Builder.first方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。