本文整理匯總了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)