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)
def test_group_admin_query_by_admin(app):
    """."""
    with app.app_context():
        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])

        assert isinstance(GroupAdmin.query_by_admin(a), BaseQuery)
        assert GroupAdmin.query_by_admin(a).count() == 1
        assert GroupAdmin.query_by_admin(g).count() == 0
def test_group_admin_query_admins_by_group_ids(app):
    """."""
    with app.app_context():
        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])

        assert isinstance(GroupAdmin.query_admins_by_group_ids([g.id]), Query)
        assert 1 == GroupAdmin.query_admins_by_group_ids([g.id]).count()
        assert 0 == GroupAdmin.query_admins_by_group_ids([a.id]).count()
        with pytest.raises(AssertionError):
            GroupAdmin.query_admins_by_group_ids('invalid')
    def test_delete(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)

        GroupAdmin.delete(g, a)
        self.assertEqual(GroupAdmin.query.count(), 0)
def test_group_admin_delete(app):
    """."""
    with app.app_context():
        from invenio_groups.models import Group, GroupAdmin
        a = Group.create(name="admin")
        g = Group.create(name="test")

        ga = GroupAdmin.create(g, a)

        assert ga.admin_type == 'Group'
        assert ga.admin_id == a.id
        assert ga.group.id == g.id
        assert GroupAdmin.query.count() == 1

        GroupAdmin.delete(g, a)
        assert GroupAdmin.query.count() == 0
    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')