本文整理汇总了Python中invenio_groups.models.Group.query_by_user方法的典型用法代码示例。如果您正苦于以下问题:Python Group.query_by_user方法的具体用法?Python Group.query_by_user怎么用?Python Group.query_by_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invenio_groups.models.Group
的用法示例。
在下文中一共展示了Group.query_by_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_query_by_user
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import query_by_user [as 别名]
def test_query_by_user(self):
"""."""
from invenio_groups.models import Group, Membership, \
GroupAdmin, MembershipState
from invenio_accounts.models import User
u1 = User(email="[email protected]", password="test1")
u2 = User(email="[email protected]", password="test2")
u3 = User(email="[email protected]", password="test3")
db.session.add(u1)
db.session.add(u2)
db.session.add(u3)
db.session.commit()
g1 = Group.create(name="test1", admins=[u1])
g2 = Group.create(name="test2", admins=[u1])
g1.add_member(u2, state=MembershipState.PENDING_ADMIN)
g1.add_member(u3, state=MembershipState.ACTIVE)
g2.add_member(u2, state=MembershipState.ACTIVE)
self.assertEqual(Group.query.count(), 2)
self.assertEqual(GroupAdmin.query.count(), 2)
self.assertEqual(Membership.query.count(), 3)
self.assertEqual(Group.query_by_user(u1).count(), 2)
self.assertEqual(Group.query_by_user(u1, with_pending=True).count(), 2)
self.assertEqual(Group.query_by_user(u2).count(), 1)
self.assertEqual(Group.query_by_user(u2, with_pending=True).count(), 2)
self.assertEqual(Group.query_by_user(u3).count(), 1)
self.assertEqual(Group.query_by_user(u3, with_pending=True).count(), 1)
self.assertEqual(Group.query_by_user(
u3, with_pending=True, eager=[Group.members]).count(), 1)