本文整理汇总了Python中orator.orm.builder.Builder.should_receive方法的典型用法代码示例。如果您正苦于以下问题:Python Builder.should_receive方法的具体用法?Python Builder.should_receive怎么用?Python Builder.should_receive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orator.orm.builder.Builder
的用法示例。
在下文中一共展示了Builder.should_receive方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_relation
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
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')
示例2: _get_relation
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
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")
示例3: test_eager_load_relations_load_top_level_relationships
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
def test_eager_load_relations_load_top_level_relationships(self):
flexmock(Builder)
builder = Builder(flexmock(QueryBuilder(None, None, None)))
nop1 = lambda: None
nop2 = lambda: None
builder.set_eager_loads({'foo': nop1, 'foo.bar': nop2})
builder.should_receive('_load_relation').with_args(['models'], 'foo', nop1).and_return(['foo'])
results = builder.eager_load_relations(['models'])
self.assertEqual(['foo'], results)
示例4: _get_relation_associate
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
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')
示例5: test_get_does_not_eager_relations_when_no_results_are_returned
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [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([])
示例6: test_relation_count_query_can_be_built
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
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)
示例7: _get_relation
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
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')
示例8: _get_relation
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
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')
示例9: test_eager_load_accept_queries
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
def test_eager_load_accept_queries(self):
model = OrmBuilderTestModelCloseRelated()
flexmock(Builder)
builder = Builder(flexmock(QueryBuilder(None, None, None)))
nop1 = OrmBuilderTestModelFarRelatedStub.where('id', 5)
builder.set_eager_loads({'foo': nop1})
relation = flexmock()
relation.should_receive('add_eager_constraints').once().with_args(['models'])
relation.should_receive('init_relation').once().with_args(['models'], 'foo').and_return(['models'])
relation.should_receive('get_eager').once().and_return(['results'])
relation.should_receive('match').once()\
.with_args(['models'], ['results'], 'foo').and_return(['foo'])
builder.should_receive('get_relation').once().with_args('foo').and_return(relation)
relation.should_receive('merge_query').with_args(nop1).and_return(relation)
results = builder.eager_load_relations(['models'])
self.assertEqual(['foo'], results)
示例10: test_relationship_eager_load_process
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
def test_relationship_eager_load_process(self):
proof = flexmock()
flexmock(Builder)
builder = Builder(flexmock(QueryBuilder(None, None, None)))
def callback(q):
proof.foo = q
builder.set_eager_loads({'orders': callback})
relation = flexmock()
relation.should_receive('add_eager_constraints').once().with_args(['models'])
relation.should_receive('init_relation').once().with_args(['models'], 'orders').and_return(['models'])
relation.should_receive('get_eager').once().and_return(['results'])
relation.should_receive('get_query').once().and_return(relation)
relation.should_receive('match').once()\
.with_args(['models'], ['results'], 'orders').and_return(['models.matched'])
builder.should_receive('get_relation').once().with_args('orders').and_return(relation)
results = builder.eager_load_relations(['models'])
self.assertEqual(['models.matched'], results)
self.assertEqual(relation, proof.foo)
示例11: _get_one_relation
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
def _get_one_relation(self):
flexmock(Builder)
query = flexmock(QueryBuilder(None, QueryGrammar(), None))
builder = Builder(query)
builder.should_receive('where').with_args('table.morph_id', '=', 1)
related = flexmock(Model())
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_morph_name').and_return(parent.__class__.__name__)
builder.should_receive('where').once().with_args('table.morph_type', parent.__class__.__name__)
return MorphOne(builder, parent, 'table.morph_type', 'table.morph_id', 'id')
示例12: _get_relation_arguments
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
def _get_relation_arguments(self):
parent = flexmock(Model())
parent.should_receive('get_morph_name').and_return(parent.__class__.__name__)
parent.should_receive('get_key').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')
query = flexmock(QueryBuilder(MockConnection().prepare_mock(), QueryGrammar(), QueryProcessor()))
flexmock(Builder)
builder = Builder(query)
builder.should_receive('get_query').and_return(query)
related = flexmock(Model())
builder.set_model(related)
builder.should_receive('get_model').and_return(related)
related.should_receive('get_key_name').and_return('id')
related.should_receive('get_table').and_return('tags')
related.should_receive('get_morph_name').and_return(parent.__class__.__name__)
builder.get_query().should_receive('join').once().with_args('taggables', 'tags.id', '=', 'taggables.tag_id')
builder.should_receive('where').once().with_args('taggables.taggable_id', '=', 1)
builder.should_receive('where').once().with_args('taggables.taggable_type', parent.__class__.__name__)
return builder, parent, 'taggable', 'taggables', 'taggable_id', 'tag_id', 'relation_name', False
示例13: _get_relation_arguments
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import should_receive [as 别名]
def _get_relation_arguments(self):
flexmock(Model).should_receive('_boot_columns').and_return(['name'])
parent = flexmock(Model())
parent.should_receive('get_key').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')
query = flexmock(QueryBuilder(MockConnection().prepare_mock(), QueryGrammar(), QueryProcessor()))
flexmock(Builder)
builder = Builder(query)
builder.should_receive('get_query').and_return(query)
related = flexmock(Model())
builder.set_model(related)
builder.should_receive('get_model').and_return(related)
related.should_receive('new_query').and_return(builder)
related.should_receive('get_key_name').and_return('id')
related.should_receive('get_table').and_return('roles')
related.should_receive('new_pivot').replace_with(lambda *args: Pivot(*args))
builder.get_query().should_receive('join').at_least().once().with_args('user_role', 'roles.id', '=', 'user_role.role_id')
builder.should_receive('where').at_least().once().with_args('user_role.user_id', '=', 1)
return builder, parent, 'user_role', 'user_id', 'role_id', 'relation_id'