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


Python builder.Builder类代码示例

本文整理汇总了Python中orator.orm.builder.Builder的典型用法代码示例。如果您正苦于以下问题:Python Builder类的具体用法?Python Builder怎么用?Python Builder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Builder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_relation_associate

    def _get_relation_associate(self, parent):
        flexmock(Builder)
        query = flexmock(QueryBuilder(None, QueryGrammar(), None))
        builder = Builder(query)
        builder.should_receive('where').with_args('relation.id', '=', 'foreign.value')
        related = flexmock(Model())
        related.should_receive('get_key').and_return(1)
        related.should_receive('get_table').and_return('relation')
        builder.should_receive('get_model').and_return(related)

        return MorphTo(builder, parent, 'foreign_key', 'id', 'morph_type', 'relation')
开发者ID:joaobarbosa,项目名称:orator,代码行数:11,代码来源:test_morph_to.py

示例2: test_pluck_with_model_found

    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,代码行数:11,代码来源:test_builder.py

示例3: test_relation_count_query_can_be_built

    def test_relation_count_query_can_be_built(self):
        relation = self._get_relation()
        query = flexmock(QueryBuilder(None, QueryGrammar(), None))
        builder = Builder(query)
        builder.get_query().should_receive('select').once()
        relation.get_parent().should_receive('get_table').and_return('table')
        builder.should_receive('where').once().with_args('table.foreign_key', '=', QueryExpression)
        parent_query = flexmock(QueryBuilder(None, None, None))
        relation.get_query().should_receive('get_query').and_return(parent_query)
        grammar = flexmock()
        parent_query.should_receive('get_grammar').once().and_return(grammar)
        grammar.should_receive('wrap').once().with_args('table.id')

        relation.get_relation_count_query(builder, builder)
开发者ID:dougblack,项目名称:orator,代码行数:14,代码来源:test_has_one.py

示例4: test_push_no_relations

    def test_push_no_relations(self):
        model = flexmock(Model())
        query = flexmock(QueryBuilder(MockConnection().prepare_mock(), QueryGrammar(), QueryProcessor()))
        builder = Builder(query)
        builder.get_query().should_receive('insert_get_id').once().with_args({'name': 'john'}, 'id').and_return(1)
        model.should_receive('new_query').once().and_return(builder)
        model.should_receive('_update_timestamps').once()

        model.name = 'john'
        model.set_exists(False)

        self.assertTrue(model.push())
        self.assertEqual(1, model.id)
        self.assertTrue(model.exists)
开发者ID:joaobarbosa,项目名称:orator,代码行数:14,代码来源:test_model.py

示例5: _get_relation

    def _get_relation(self, parent=None):
        flexmock(Builder)
        query = flexmock(QueryBuilder(None, QueryGrammar(), None))
        builder = Builder(query)
        builder.should_receive('where').with_args('relation.id', '=', 'foreign.value')
        related = flexmock(Model())
        related.should_receive('new_query').and_return(builder)
        related.should_receive('get_key_name').and_return('id')
        related.should_receive('get_table').and_return('relation')
        builder.should_receive('get_model').and_return(related)
        if parent is None:
            parent = OrmBelongsToModelStub()
        parent.foreign_key = 'foreign.value'

        return BelongsTo(builder, parent, 'foreign_key', 'id', 'relation')
开发者ID:joaobarbosa,项目名称:orator,代码行数:15,代码来源:test_belongs_to.py

示例6: _get_relation

    def _get_relation(self):
        flexmock(Builder)
        query = flexmock(QueryBuilder(None, QueryGrammar(), None))
        builder = Builder(query)
        builder.should_receive('where').with_args('table.foreign_key', '=', 1)
        related = flexmock(Model())
        related.should_receive('new_query').and_return(builder)
        builder.should_receive('get_model').and_return(related)
        parent = flexmock(Model())
        parent.should_receive('get_attribute').with_args('id').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')
        parent.should_receive('new_query').and_return(builder)

        return HasMany(builder, parent, 'table.foreign_key', 'id')
开发者ID:dougblack,项目名称:orator,代码行数:15,代码来源:test_has_many.py

示例7: test_first_or_fail_raises_model_not_found_exception

    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,代码行数:16,代码来源:test_builder.py

示例8: test_macros_are_called_on_builder

    def test_macros_are_called_on_builder(self):
        builder = Builder(QueryBuilder(
            flexmock(Connection),
            flexmock(QueryGrammar),
            flexmock(QueryProcessor)
        ))

        def foo_bar(builder):
            builder.foobar = True

            return builder

        builder.macro('foo_bar', foo_bar)
        result = builder.foo_bar()

        self.assertEqual(result, builder)
        self.assertTrue(builder.foobar)
开发者ID:southwestjiaotongunivercity,项目名称:orator,代码行数:17,代码来源:test_builder.py

示例9: test_chunk

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

示例10: _get_relation

    def _get_relation(self):
        flexmock(Builder)
        query = flexmock(QueryBuilder(None, QueryGrammar(), None))
        builder = Builder(query)
        builder.get_query().should_receive('join').at_least().once().with_args('users', 'users.id', '=', 'posts.user_id')
        builder.should_receive('where').with_args('users.country_id', '=', 1)
        country = flexmock(Model())
        country.should_receive('get_key').and_return(1)
        country.should_receive('get_foreign_key').and_return('country_id')
        user = flexmock(Model())
        user.should_receive('get_table').and_return('users')
        user.should_receive('get_qualified_key_name').and_return('users.id')
        post = flexmock(Model())
        post.should_receive('get_table').and_return('posts')
        builder.should_receive('get_model').and_return(post)

        post.should_receive('new_query').and_return(builder)

        user.should_receive('get_key').and_return(1)
        user.should_receive('get_created_at_column').and_return('created_at')
        user.should_receive('get_updated_at_column').and_return('updated_at')

        parent = flexmock(Model())
        parent.should_receive('get_attribute').with_args('id').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')
        parent.should_receive('new_query').and_return(builder)

        return HasManyThrough(builder, country, user, 'country_id', 'user_id')
开发者ID:joaobarbosa,项目名称:orator,代码行数:29,代码来源:test_has_many_through.py

示例11: _get_relation

    def _get_relation(self):
        flexmock(Builder)
        query = flexmock(QueryBuilder(None, QueryGrammar(), None))
        builder = Builder(query)
        builder.get_query().should_receive("join").at_least().once().with_args(
            "users", "users.id", "=", "posts.user_id"
        )
        builder.should_receive("where").with_args("users.country_id", "=", 1)
        country = flexmock(Model())
        country.should_receive("get_key").and_return(1)
        country.should_receive("get_foreign_key").and_return("country_id")
        user = flexmock(Model())
        user.should_receive("get_table").and_return("users")
        user.should_receive("get_qualified_key_name").and_return("users.id")
        post = flexmock(Model())
        post.should_receive("get_table").and_return("posts")
        builder.should_receive("get_model").and_return(post)

        post.should_receive("new_query").and_return(builder)

        user.should_receive("get_key").and_return(1)
        user.should_receive("get_created_at_column").and_return("created_at")
        user.should_receive("get_updated_at_column").and_return("updated_at")

        parent = flexmock(Model())
        parent.should_receive("get_attribute").with_args("id").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")
        parent.should_receive("new_query").and_return(builder)

        return HasManyThrough(builder, country, user, "country_id", "user_id")
开发者ID:yos-virtus,项目名称:orator,代码行数:31,代码来源:test_has_many_through.py

示例12: test_find_method

    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,代码行数:12,代码来源:test_builder.py

示例13: test_push_one_relation

    def test_push_one_relation(self):
        related1 = flexmock(Model())
        query = flexmock(QueryBuilder(MockConnection().prepare_mock(), QueryGrammar(), QueryProcessor()))
        builder = Builder(query)
        builder.get_query().should_receive('insert_get_id').once().with_args({'name': 'related1'}, 'id').and_return(2)
        related1.should_receive('new_query').once().and_return(builder)
        related1.should_receive('_update_timestamps').once()

        related1.name = 'related1'
        related1.set_exists(False)

        model = flexmock(Model())
        model.should_receive('resolve_connection').and_return(MockConnection().prepare_mock())
        query = flexmock(QueryBuilder(MockConnection().prepare_mock(), QueryGrammar(), QueryProcessor()))
        builder = Builder(query)
        builder.get_query().should_receive('insert_get_id').once().with_args({'name': 'john'}, 'id').and_return(1)
        model.should_receive('new_query').once().and_return(builder)
        model.should_receive('_update_timestamps').once()

        model.name = 'john'
        model.set_exists(False)
        model.set_relation('relation_one', related1)

        self.assertTrue(model.push())
        self.assertEqual(1, model.id)
        self.assertTrue(model.exists)
        self.assertEqual(2, model.relation_one.id)
        self.assertTrue(model.relation_one.exists)
        self.assertEqual(2, related1.id)
        self.assertTrue(related1.exists)
开发者ID:joaobarbosa,项目名称:orator,代码行数:30,代码来源:test_model.py

示例14: test_get_models_hydrates_models

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

示例15: test_find_or_new_model_found

    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,代码行数:16,代码来源:test_builder.py


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