1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
19 from indico
.modules
.groups
import GroupProxy
20 from indico
.modules
.groups
.models
.groups
import LocalGroup
21 from indico
.modules
.rb
import settings
as rb_settings
22 from indico
.modules
.users
import User
27 """Returns a callable which lets you create dummy users"""
30 def _create_user(id_
, first_name
=u
'Guinea', last_name
=u
'Pig', rb_admin
=False, admin
=False, email
=None, groups
=None,
34 return user
.as_avatar
if legacy
else user
37 user
.first_name
= first_name
38 user
.last_name
= last_name
39 user
.email
= email
or u
'{}@example.com'.format(id_
)
41 user
.local_groups
= {g
.group
for g
in (groups
or ())}
45 rb_settings
.set('admin_principals', rb_settings
.get('admin_principals') + [user
.as_principal
])
48 return user
.as_avatar
if legacy
else user
52 admins
= set(map(tuple, rb_settings
.get('admin_principals')))
54 admins
.discard(user
.as_principal
)
55 db
.session
.delete(user
)
56 rb_settings
.set('admin_principals', list(admins
))
60 def dummy_user(create_user
):
61 """Creates a mocked dummy avatar"""
62 return create_user(1337)
67 """Returns a callable which lets you create dummy groups"""
70 def _create_group(id_
):
73 group
.name
= u
'dummy-{}'.format(id_
)
77 return GroupProxy(group
.id, _group
=group
)
82 db
.session
.delete(group
)
86 def dummy_group(create_group
):
87 """Creates a mocked dummy group"""
88 return create_group(1337)