當前位置: 首頁>>代碼示例>>Python>>正文


Python models.Group類代碼示例

本文整理匯總了Python中invenio_groups.models.Group的典型用法代碼示例。如果您正苦於以下問題:Python Group類的具體用法?Python Group怎麽用?Python Group使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Group類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_query_requests

    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)
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:31,代碼來源:test_models.py

示例2: test_update_duplicated_names

    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")
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:10,代碼來源:test_models.py

示例3: test_query_by_user

    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)
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:31,代碼來源:test_models.py

示例4: test_query_by_admin

    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)
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:11,代碼來源:test_models.py

示例5: test_create

    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)
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:12,代碼來源:test_models.py

示例6: test_add_admin

    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)
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:14,代碼來源:test_models.py

示例7: test_remove_admin

    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)
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:15,代碼來源:test_models.py

示例8: test_query_admins_by_group_ids

    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')
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:17,代碼來源:test_models.py

示例9: test_creation_existing_name

    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])
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:8,代碼來源:test_models.py

示例10: test_is_admin

    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))
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:17,代碼來源:test_models.py

示例11: test_query_by_group

    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)
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:19,代碼來源:test_models.py

示例12: test_creation_signals

    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
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:20,代碼來源:test_models.py

示例13: users

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()
開發者ID:inveniosoftware,項目名稱:invenio-groups,代碼行數:21,代碼來源:app.py

示例14: test_is_member

    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))
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:13,代碼來源:test_models.py

示例15: test_delete

    def test_delete(self):
        """Test deletion of a group."""
        from invenio_groups.models import Group, GroupAdmin, Membership
        from invenio_accounts.models import User

        g1 = Group.create(name="test1")
        g2 = Group.create(name="test2", admins=[g1])
        u = User(email="[email protected]", password="test")
        db.session.add(u)
        db.session.commit()

        g2.add_member(u)

        # Group is admin of another group, which will be left without admins
        g1.delete()
        self.assertEqual(Group.query.count(), 1)
        self.assertEqual(GroupAdmin.query.count(), 0)
        self.assertEqual(Membership.query.count(), 1)

        g2.delete()
        self.assertEqual(Group.query.count(), 0)
        self.assertEqual(GroupAdmin.query.count(), 0)
        self.assertEqual(Membership.query.count(), 0)
開發者ID:egabancho,項目名稱:invenio-groups,代碼行數:23,代碼來源:test_models.py


注:本文中的invenio_groups.models.Group類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。