本文整理汇总了Python中invenio_groups.models.Group.create方法的典型用法代码示例。如果您正苦于以下问题:Python Group.create方法的具体用法?Python Group.create怎么用?Python Group.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invenio_groups.models.Group
的用法示例。
在下文中一共展示了Group.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_query_requests
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_query_requests(self):
"""."""
from invenio_groups.models import Group, Membership, \
MembershipState
from invenio_accounts.models import User
from flask.ext.sqlalchemy import BaseQuery
a = User(email="[email protected]", password="admin")
u1 = User(email="[email protected]", password="test")
u2 = User(email="[email protected]", password="test2")
db.session.add_all([a, u1, u2])
db.session.commit()
g = Group.create(name="test", admins=[a])
Membership.create(g, u1, MembershipState.PENDING_ADMIN)
Membership.create(g, u2, MembershipState.PENDING_USER)
self.assertIsInstance(Membership.query_requests(u1), BaseQuery)
self.assertEqual(Membership.query_requests(a).count(), 1)
ad = Group.create(name="admin")
g2 = Group.create(name="test2", admins=[ad])
u3 = User(email="[email protected]", password="test3")
u4 = User(email="[email protected]", password="test4")
u5 = User(email="[email protected]", password="test5")
db.session.add_all([u3, u4, u5])
db.session.commit()
Membership.create(ad, u3, MembershipState.ACTIVE)
Membership.create(g2, u4, MembershipState.PENDING_ADMIN)
Membership.create(g2, u5, MembershipState.PENDING_USER)
self.assertEqual(Membership.query_requests(u3).count(), 1)
示例2: test_query_by_user
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [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)
示例3: test_get_by_name
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_get_by_name(self):
"""Test get by name."""
from invenio_groups.models import Group
Group.create(name="test1")
Group.create(name="test2")
self.assertEqual(Group.get_by_name("test1").name, "test1")
self.assertIsNone(Group.get_by_name("invalid"),)
示例4: test_update_duplicated_names
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_update_duplicated_names(self):
"""."""
from invenio_groups.models import Group
g = Group.create(name="test")
Group.create(name="test-change")
self.assertEqual(Group.query.count(), 2)
self.assertRaises(
IntegrityError,
g.update, name="test-change")
示例5: test_query_by_admin
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_query_by_admin(self):
"""."""
from invenio_groups.models import Group, GroupAdmin
from flask.ext.sqlalchemy import BaseQuery
a = Group.create(name="admin")
g = Group.create(name="test", admins=[a])
self.assertIsInstance(GroupAdmin.query_by_admin(a), BaseQuery)
self.assertEqual(GroupAdmin.query_by_admin(a).count(), 1)
self.assertEqual(GroupAdmin.query_by_admin(g).count(), 0)
示例6: test_create
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_create(self):
"""."""
from invenio_groups.models import Group, GroupAdmin
a = Group.create(name="admin")
g = Group.create(name="test")
ga = GroupAdmin.create(g, a)
self.assertEqual(ga.admin_type, 'Group')
self.assertEqual(ga.admin_id, a.id)
self.assertEqual(ga.group.id, g.id)
self.assertEqual(GroupAdmin.query.count(), 1)
示例7: test_add_admin
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_add_admin(self):
"""."""
from invenio_groups.models import Group, GroupAdmin
a = Group.create(name="admin")
g = Group.create(name="test")
obj = g.add_admin(a)
self.assertIsInstance(obj, GroupAdmin)
self.assertEqual(GroupAdmin.query.count(), 1)
self.assertRaises(
IntegrityError,
g.add_admin, a)
示例8: test_remove_admin
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_remove_admin(self):
"""."""
from invenio_groups.models import Group, GroupAdmin
a = Group.create(name="admin")
g = Group.create(name="test", admins=[a])
self.assertEqual(GroupAdmin.query.count(), 1)
g.remove_admin(a)
self.assertEqual(GroupAdmin.query.count(), 0)
self.assertRaises(
NoResultFound,
g.remove_admin, a)
示例9: test_query_admins_by_group_ids
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_query_admins_by_group_ids(self):
"""."""
from invenio_groups.models import Group, GroupAdmin
from sqlalchemy.orm.query import Query
a = Group.create(name="admin")
g = Group.create(name="test", admins=[a])
self.assertIsInstance(GroupAdmin.query_admins_by_group_ids([g.id]),
Query)
self.assertEqual(
GroupAdmin.query_admins_by_group_ids([g.id]).count(), 1)
self.assertEqual(
GroupAdmin.query_admins_by_group_ids([a.id]).count(), 0)
self.assertRaises(
AssertionError,
GroupAdmin.query_admins_by_group_ids, 'invalid')
示例10: test_creation_existing_name
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_creation_existing_name(self):
"""Test what happens if group with identical name is created."""
from invenio_groups.models import Group
g = Group.create(name="test", )
self.assertRaises(
IntegrityError,
Group.create, name="test", admins=[g])
示例11: test_is_admin
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_is_admin(self):
"""."""
from invenio_groups.models import Group
from invenio_accounts.models import User
g = Group.create(name="test")
u = User(email="test", password="test")
db.session.add(u)
db.session.commit()
g.add_admin(u)
self.assertTrue(g.is_admin(u))
a = Group.create(name="admin")
g = Group.create(name="test2", admins=[a])
self.assertTrue(g.is_admin(a))
示例12: test_query_by_group
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_query_by_group(self):
"""."""
from invenio_groups.models import Group, Membership, \
MembershipState
from invenio_accounts.models import User
from flask.ext.sqlalchemy import BaseQuery
g = Group.create(name="test")
Group.create(name="test2")
u = User(email="[email protected]", password="test")
u2 = User(email="[email protected]", password="test2")
db.session.add(u)
db.session.commit()
Membership.create(g, u, MembershipState.ACTIVE)
self.assertIsInstance(Membership.query_by_group(g), BaseQuery)
self.assertEqual(Membership.query_by_group(g).count(), 1)
self.assertEqual(Membership.query_by_group(u2).count(), 0)
示例13: test_creation_signals
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_creation_signals(self):
"""Test signals sent after creation."""
from invenio_groups.models import Group
from invenio_groups.signals import group_created
Group.called = False
def _receiver(sender=None, group=None):
Group.called = True
assert sender == Group
assert group.name == 'signaltest'
with group_created.connected_to(_receiver):
Group.create(name="signaltest")
assert Group.called
Group.called = False
with group_created.connected_to(_receiver):
self.assertRaises(IntegrityError, Group.create, name="signaltest")
assert not Group.called
示例14: users
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def users():
"""Load default users and groups."""
from invenio_groups.models import Group, Membership, \
PrivacyPolicy, SubscriptionPolicy
admin = accounts.datastore.create_user(
email='[email protected]',
password=encrypt_password('123456'),
active=True,
)
reader = accounts.datastore.create_user(
email='[email protected]',
password=encrypt_password('123456'),
active=True,
)
admins = Group.create(name='admins', admins=[admin])
for i in range(10):
Group.create(name='group-{0}'.format(i), admins=[admin])
Membership.create(admins, reader)
db.session.commit()
示例15: test_is_member
# 需要导入模块: from invenio_groups.models import Group [as 别名]
# 或者: from invenio_groups.models.Group import create [as 别名]
def test_is_member(self):
"""."""
from invenio_groups.models import Group
from invenio_accounts.models import User
g = Group.create(name="test")
u = User(email="test", password="test")
db.session.add(u)
db.session.commit()
g.add_member(u)
self.assertTrue(g.is_member(u))